{"id":3407,"date":"2022-05-02T10:00:00","date_gmt":"2022-05-02T10:00:00","guid":{"rendered":"https:\/\/cssdeck.com\/blog\/?p=3407"},"modified":"2022-06-21T15:37:56","modified_gmt":"2022-06-21T15:37:56","slug":"how-to-check-whether-the-device-supports-hover-with-a-css","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/how-to-check-whether-the-device-supports-hover-with-a-css\/","title":{"rendered":"How to check whether the device supports hover with a CSS"},"content":{"rendered":"\n<p><a href=\"https:\/\/cssdeck.com\/blog\/what-is-this-css-thing-anyway\/\" title=\"https:\/\/cssdeck.com\/blog\/what-is-this-css-thing-anyway\/\"><strong>CSS, or &#8220;Cascading Style Sheets,&#8221; is a programming language<\/strong><\/a> used to layout and structure web pages (HTML or XML). This language comprises &#8220;cascading style sheets,&#8221; which contain coding elements.&nbsp;<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"700\" height=\"291\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2022\/04\/Device-over-in-CSS.jpeg\" alt=\"\" class=\"wp-image-3413\"\/><figcaption>device hover in css<\/figcaption><\/figure><\/div>\n\n\n<p>The ability to offer the same markup page in various styles for distinct rendering techniques, including on, in print, by voice (through speech-based browsing or screen translator), and on Braille-based interactive applications, is also made possible by the separation of formatting and content. <a href=\"https:\/\/cssdeck.com\/blog\/how-to-write-a-css-rule\/\"><strong>CSS contains rules<\/strong><\/a> for different configurations if the information is accessible on a mobile device.<\/p>\n\n\n\n<p>CSS is a basic syntax that specifies the names of many style properties using a handful of English keywords.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How does the device hover in CSS?&nbsp;<\/h2>\n\n\n\n<p>Although checking whether a device supports hover with CSS appears to be a simple problem, it proves to be rather difficult to solve. By exploring content from some websites, we found it will only appear if a user hovers over or focuses on a link. The link, on the other hand, has its target.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"700\" height=\"361\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2022\/04\/How-does-the-device-hover-in-CSS-.jpeg\" alt=\"\" class=\"wp-image-3412\"\/><figcaption> device hover in CSS&nbsp;<\/figcaption><\/figure><\/div>\n\n\n<p>When a touch screen user clicks one of such links displayed on such sites, the browser gets to the &#8220;href&#8221; location right away. This means that the contents of the hover are never seen, and that&#8217;s it!<\/p>\n\n\n\n<p>Users without a mouse (or another device that can hover like a magic remote control) should see alternative content. But how can I tell whether this is the case?<\/p>\n\n\n\n<p>The disparity between typical mouse-like pointers and devices with touch input, such as smartphones, makes hover effects difficult. On a touch device, we don&#8217;t have the same continuous pointer input as we do with a mouse, but the design of a site should nevertheless indicate which items are interactive, ignoring such facts.<\/p>\n\n\n\n<p>See also: <a href=\"https:\/\/cssdeck.com\/blog\/5-awesome-css-hover-effects-and-their-codes\/\">5 Awesome CSS hover effects and their codes<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Solution<\/h2>\n\n\n\n<p>Let&#8217;s try and solve this challenge of&nbsp;<strong>device hover in CSS<\/strong>&nbsp;by using color to communicate interaction. Hovering over an element with a mouse-like pointer will allow users to test its interaction with it. Interactive items will be highlighted with a strong backdrop color when they hover. And because touch device users won&#8217;t be able to hover, we&#8217;ll utilize the highlighted background color for interactive parts at all times. We hope it makes sense to you.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example:-<\/strong><\/h3>\n\n\n\n<p>Now to check and prove this right, let&#8217;s go for a basic example:-<\/p>\n\n\n\n<ul><li>Go and select a blank HTML page and insert,<\/li><\/ul>\n\n\n\n<p>&lt;button&gt;Button&lt;\/button&gt;<\/p>\n\n\n\n<p>(We&#8217;ll add CSS styles soon, but first, we&#8217;ll create an interactive element to experiment with: a button.)<\/p>\n\n\n\n<p>Buttons have a very common function, as we all know, but they come in various shapes and sizes, so it&#8217;s critical to express visually that they&#8217;re interactive. To signify the interactivity of buttons, we&#8217;ll use a yellow backdrop.<\/p>\n\n\n\n<p>We&#8217;ll write our <a href=\"https:\/\/docs.microsoft.com\/en-us\/microsoft-edge\/devtools-guide-chromium\/css\/css-overview-tool\">CSS <\/a>to default to mobile device styles, and we&#8217;ll use media queries to adjust the techniques for other devices, as usual.&nbsp;<\/p>\n\n\n\n<p>So let&#8217;s begin by decorating the button with a yellow background to represent interaction, as stated above.<\/p>\n\n\n\n<div class=\"wp-block-group is-layout-flow\"><div class=\"wp-block-group__inner-container\">\n<p>Insert,<\/p>\n\n\n\n<p>button {<\/p>\n\n\n\n<p>     background: yellow ;<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>To see if the client&nbsp;<strong>device supports hover in CSS?<\/strong>&nbsp;For this, we&#8217;ll use the hover media feature in a query. We&#8217;ll add this media query to our stylesheet to apply styles to hover-capable devices.<\/p>\n\n\n\n<p>@media ( hover : hover ) {<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp;Button {<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;background: white :<\/p>\n\n\n\n<p>&nbsp; &nbsp;}<\/p>\n\n\n\n<p>&nbsp;&nbsp;Button : hover {<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;background : yellow :<\/p>\n\n\n\n<p>&nbsp; &nbsp;}<\/p>\n\n\n\n<p>}<\/p>\n<\/div><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"700\" height=\"390\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2022\/04\/device-hover-in-css.jpeg\" alt=\"\" class=\"wp-image-3411\"\/><figcaption>device hover in css<\/figcaption><\/figure><\/div>\n\n\n<p>Now, time for results.<\/p>\n\n\n\n<p>After the above procedure, hover media can either report &#8220;hover&#8221; or &#8220;none.&#8221; Hovering gadgets will report with the option &#8220;hover,&#8221; while non-hovering devices will report &#8220;none.&#8221;<\/p>\n\n\n\n<p>Hovering over buttons will now override the default button styles, allowing users to test interactivity while hovering. It&#8217;s that simple! Regrettably, I wasted years without employing this useful media query, and I was stymied by my hover styles quandary the entire time. <\/p>\n\n\n\n<p>So, for different times, whenever you want to go to check whether the\u00a0<strong>device hover in CSS<\/strong>\u00a0or not, go for it!<\/p>\n\n\n\n<p>Thanks for checking out my guide.\u00a0If you are looking for more tech resources and want to read in-depth guides, I would recommend checking out\u00a0<a href=\"https:\/\/www.realpythonproject.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">realpythonprojects<\/a>.<\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>CSS, or &#8220;Cascading Style Sheets,&#8221; is a programming language used to layout and structure web pages (HTML or XML). This language comprises &#8220;cascading style sheets,&#8221; which contain coding elements.&nbsp;<\/p>\n<p>device hover in css<\/p>\n<p>The ability to offer the same markup page in [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/how-to-check-whether-the-device-supports-hover-with-a-css\/\" title=\"Click to read 'How to check whether the device supports hover with a CSS'\">Read Article<\/a><\/p>\n","protected":false},"author":21,"featured_media":3409,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[165,168,170,172,6,192],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3407"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=3407"}],"version-history":[{"count":3,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3407\/revisions"}],"predecessor-version":[{"id":3450,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3407\/revisions\/3450"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media\/3409"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=3407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=3407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=3407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}