{"id":197,"date":"2013-12-23T14:00:06","date_gmt":"2013-12-23T14:00:06","guid":{"rendered":"http:\/\/aurelio.audero.it\/blog\/?p=197"},"modified":"2016-06-04T00:27:27","modified_gmt":"2016-06-04T00:27:27","slug":"enhancing-the-abbr-element-on-mobile","status":"publish","type":"post","link":"https:\/\/www.audero.it\/blog\/2013\/12\/23\/enhancing-the-abbr-element-on-mobile\/","title":{"rendered":"Enhancing the abbr Element on Mobile"},"content":{"rendered":"<p>Today&#8217;s world runs fast, really fast. When writing, a lot of people use abbreviations and acronyms to save time that we can find spread all over the web. They are so used that an HTML tag, <code>&lt;abbr&gt;<\/code>, was created to identify them and help the semantic of web pages.<\/p>\n<p>In this article, I&#8217;ll show you a small <abbr title=\"Cascading Style Sheets\">CSS<\/abbr> snippet that can enhance how the <code>&lt;abbr&gt;<\/code> tag is shown on mobile devices.<br \/>\n<!--more--><br \/>\nThe <code>&lt;abbr&gt;<\/code> tag is usually used in conjunction with the <code>title<\/code> attribute, which has as its value the meaning of the abbreviation or the acronym (i.e. the extended form). For example, if we wanted to talk about the <em>LAMP<\/em> stack, we could write the following code to explain what &#8220;LAMP&#8221; means:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;abbr title=&quot;Linux Apache MySQL PHP&quot;&gt;LAMP&lt;\/abbr&gt;\r\n<\/pre>\n<p>Apart from the intrinsic semantic of the tag, one of the advantage is that the readers can easily discover the extended form hovering the tag with the mouse. By default, browsers don&#8217;t give any visual hint of the presence of this &#8220;hidden&#8221; information, so it&#8217;s not easy to know it. The following image shows how Chrome on Windows 7 renders <code>&lt;abbr&gt;<\/code> without any style applied:<\/p>\n<figure>\n<a href=\"http:\/\/aurelio.audero.it\/blog\/wp-content\/uploads\/2013\/12\/abbr-unstyled.jpg\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"260\" data-permalink=\"https:\/\/www.audero.it\/blog\/2013\/12\/23\/enhancing-the-abbr-element-on-mobile\/abbr-unstyled\/\" data-orig-file=\"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2013\/12\/abbr-unstyled.jpg\" data-orig-size=\"131,52\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"abbr tag unstyled\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2013\/12\/abbr-unstyled.jpg\" src=\"\/\/aurelio.audero.it\/blog\/wp-content\/uploads\/2013\/12\/abbr-unstyled.jpg\" alt=\"The abbr tag unstyled\" width=\"131\" height=\"52\" class=\"aligncenter size-full wp-image-260\" \/><\/a><figcaption>The <code>&lt;abbr&gt;<\/code> tag containing the acronym LAMP as shown by default by Chrome on Windows 7<\/figcaption><\/figure>\n<p><small>A different browser may applies some style, but usually it&#8217;ll be rendered as shown above.<\/small><\/p>\n<p>To give the readers a visual hint that they can discover the meaning of the abbreviation or the acronym without searching it on the web, web designers usually adopt the following <abbr title=\"Cascading Style Sheets\">CSS<\/abbr> code:<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\nabbr&#x5B;title]\r\n{\r\n   border-bottom: 1px dashed #ADADAD;\r\n   cursor: help;\r\n}\r\n<\/pre>\n<p>This style is applied to any <code>&lt;abbr&gt;<\/code> having a <code>title<\/code> attribute set. It applies a gray dashed border below the <code>&lt;abbr&gt;<\/code> tag, and change the cursor icon, when the reader hover the tag, so that a small question mark near the cursor will be shown. The image below shows how Chrome on Windows 7 renders the tag with this style applied:<\/p>\n<figure>\n<a href=\"http:\/\/aurelio.audero.it\/blog\/wp-content\/uploads\/2013\/12\/abbr-styled.jpg\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"261\" data-permalink=\"https:\/\/www.audero.it\/blog\/2013\/12\/23\/enhancing-the-abbr-element-on-mobile\/abbr-styled\/\" data-orig-file=\"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2013\/12\/abbr-styled.jpg\" data-orig-size=\"131,52\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"abbr tag styled\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2013\/12\/abbr-styled.jpg\" src=\"\/\/aurelio.audero.it\/blog\/wp-content\/uploads\/2013\/12\/abbr-styled.jpg\" alt=\"The abbr tag styled\" width=\"131\" height=\"52\" class=\"aligncenter size-full wp-image-261\" \/><\/a><figcaption>The <code>&lt;abbr&gt;<\/code> tag containing the acronym LAMP with a style applied, rendered by Chrome on Windows 7<\/figcaption><\/figure>\n<p>Until now, we discussed about how the readers can hover the tag to show the extended form of the acronym or the abbreviation. But what if a reader is using a mobile device (as probably you&#8217;re doing now)? As you might know, on mobile we don&#8217;t have a thing such as hover. Therefore, we need to integrate the style with something else. We can take a cue from non-web media like books or newspapers. When using an abbreviation or an acronym, writers for this kind of media usually include the extended form between parentheses. So, recalling our <em>LAMP<\/em> example, you&#8217;ll find something like:<\/p>\n<p>LAMP (Linux Apache MySQL PHP)<\/p>\n<p>Why not adopting this well-known technique on the web too?<\/p>\n<p>What we want is to apply the first <abbr title=\"Cascading Style Sheets\">CSS<\/abbr> snippet on the text shown on desktops and laptops, and a code implementing the books-like technique for mobile devices. To achieve this goal we need:<\/p>\n<ul>\n<li>Media queries<\/li>\n<li>The <code>content<\/code> property<\/li>\n<li>The <code>attr<\/code> expression<\/li>\n<\/ul>\n<p>For those of you that don&#8217;t have familiarity with <code>content<\/code> and <code>attr<\/code>, the former allows to set the content of a pseudo-element, while the latter allows to retrieve the value of a given attribute. Because we want to automatically update the content <em>after<\/em> an <code>abbr<\/code> element using <abbr title=\"Cascading Style Sheets\">CSS<\/abbr>, we can employ the <code>:after<\/code> pseudo-selector.<\/p>\n<p>Putting it all together, using a mobile-first approach, results in the following <abbr title=\"Cascading Style Sheets\">CSS<\/abbr> code:<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\nabbr&#x5B;title]:after\r\n{\r\n   content: &quot; (&quot; attr(title) &quot;)&quot;;\r\n}\r\n\r\n@media screen and (min-width: 1025px)\r\n{\r\n   abbr&#x5B;title]\r\n   {\r\n      border-bottom: 1px dashed #ADADAD;\r\n      cursor:help;\r\n   }\r\n\r\n   abbr&#x5B;title]:after\r\n   {\r\n      content: &quot;&quot;;\r\n   }\r\n}\r\n<\/pre>\n<p>As you can see, in the code I&#8217;ve chosen <code>1025px<\/code> as a breakpoint for desktops, but you can change it based on your needs. In addition, inside the media query we reset the content of the <code>after<\/code> pseudo-element assigning an empty string to the <code>content<\/code> property. You can see the code above in action looking at the <a href=\"http:\/\/aurelio.audero.it\/demo\/enhancing-abbr-element-on-mobile-demo.html\" target=\"_blank\">demo page<\/a> resizing it. In order to allow users viewing the demo on devices having different screen size to see the effect, I&#8217;ve put several elements with different breakpoints.<\/p>\n<p>The discussed technique is supported by all major browsers, including Internet Explorer starting from version 9. Internet Explorer 8 supports the <code>content<\/code> property and the <code>attr<\/code> expression but not media queries. If we want to extend the compatibility, we can use a shim like <a href=\"https:\/\/github.com\/scottjehl\/Respond\" target=\"_blank\">Respond.js<\/a> or <a href=\"https:\/\/code.google.com\/p\/css3-mediaqueries-js\/\" target=\"_blank\">css3-mediaqueries.js<\/a>.<\/p>\n<h3>Conclusions<\/h3>\n<p>The sample technique described in this article allows us to enhance how mobile users read the texts of our web pages. Its compatibility is pretty good because it can be employed in all major browsers, including Internet Explorer starting from version 9. In addition, we can use it in Internet Explorer 8 too using a shim to support media queries.<\/p>\n<p>As we&#8217;ve seen, we can solve issues taking cue from various sources, even non-digital once. A good lesson to remember.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today&#8217;s world runs fast, really fast. When writing, a lot of people use abbreviations and acronyms to save time that we can find spread all over the web. They are so used that an HTML tag, <code>&lt;abbr&gt;<\/code>, was created to identify them and help the semantic of web pages.<\/p>\n<p>In this article, I&#8217;ll show you a small <abbr title=\"Cascading Style Sheets\">CSS<\/abbr> snippet that can enhance how the <code>&lt;abbr&gt;<\/code> tag is shown on mobile devices.<\/p>\n","protected":false},"author":1,"featured_media":266,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4,5],"tags":[48,49,50,11],"class_list":["post-197","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-css","category-html","tag-css","tag-html","tag-mobile","tag-web"],"jetpack_featured_media_url":"https:\/\/www.audero.it\/blog\/wp-content\/uploads\/2013\/12\/abbr-icon.jpg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9Or4e-3b","jetpack-related-posts":[{"id":329,"url":"https:\/\/www.audero.it\/blog\/2014\/09\/19\/resources-beginner-front-end-developers\/","url_meta":{"origin":197,"position":0},"title":"Resources for Beginner Front-end Developers","author":"Aurelio De Rosa","date":"September 19, 2014","format":false,"excerpt":"Few weeks ago I received an email from a developer asking me for suggestions on how to delve into the front-end world. After having replied to this email, I thought that it'd have been nice to share the same suggestions on my blog. That's exactly what you'll find in this\u2026","rel":"","context":"In &quot;Discussions &amp; Opinions&quot;","block_context":{"text":"Discussions &amp; Opinions","link":"https:\/\/www.audero.it\/blog\/category\/discussions-opinions\/"},"img":{"alt_text":"html5 css3 javascript logos","src":"https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2014\/09\/front-end-stack.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2014\/09\/front-end-stack.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2014\/09\/front-end-stack.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2014\/09\/front-end-stack.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2014\/09\/front-end-stack.png?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":397,"url":"https:\/\/www.audero.it\/blog\/2015\/06\/16\/trick-of-the-day-the-time-element\/","url_meta":{"origin":197,"position":1},"title":"Trick of the day: The time element","author":"Aurelio De Rosa","date":"June 16, 2015","format":false,"excerpt":"HTML5 introduced several new elements to address many common use cases that developers have faced over the years. As an example you can think to the new audio and video elements that allow you to avoid the use of third-party software like Flash and Silverlight to play audios and videos.\u2026","rel":"","context":"In &quot;Trick of the day&quot;","block_context":{"text":"Trick of the day","link":"https:\/\/www.audero.it\/blog\/category\/trick-of-the-day\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":56,"url":"https:\/\/www.audero.it\/blog\/2013\/07\/02\/how-to-solve-the-problem-of-font-face-inside-media-queries\/","url_meta":{"origin":197,"position":2},"title":"How to Solve the Problem of @font-face Inside Media Queries","author":"Aurelio De Rosa","date":"July 2, 2013","format":false,"excerpt":"Mobile connections aren't as good as the usual desktop ones, therefore the download time of custom fonts can take up to several seconds. A good approach is to use the @font-face rule only for certain range of media and screens using @media queries. Unfortunately this approach doesn't work for some\u2026","rel":"","context":"In &quot;CSS&quot;","block_context":{"text":"CSS","link":"https:\/\/www.audero.it\/blog\/category\/css\/"},"img":{"alt_text":"A page with custom font not completely downloaded","src":"https:\/\/i0.wp.com\/aurelio.audero.it\/blog\/wp-content\/uploads\/2013\/06\/aeon-megazine-mobile-168x300.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":404,"url":"https:\/\/www.audero.it\/blog\/2015\/07\/14\/trick-of-the-day-css-scroll-snap-points\/","url_meta":{"origin":197,"position":3},"title":"Trick of the day: CSS Scroll Snap Points","author":"Aurelio De Rosa","date":"July 14, 2015","format":false,"excerpt":"When you create a gallery, you usually want to implement a feature where every time the user clicks (or press the ENTER key) on an arrow, you move straight to the next (or previous) image. This effect can also be used to create a website that has several sections, each\u2026","rel":"","context":"In &quot;Trick of the day&quot;","block_context":{"text":"Trick of the day","link":"https:\/\/www.audero.it\/blog\/category\/trick-of-the-day\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2015\/07\/css-scroll-snap-points.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2015\/07\/css-scroll-snap-points.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2015\/07\/css-scroll-snap-points.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2015\/07\/css-scroll-snap-points.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2015\/07\/css-scroll-snap-points.png?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":148,"url":"https:\/\/www.audero.it\/blog\/2013\/09\/05\/how-to-create-custom-filters-in-jquery\/","url_meta":{"origin":197,"position":4},"title":"How to Create Custom Filters in jQuery","author":"Aurelio De Rosa","date":"September 5, 2013","format":false,"excerpt":"In some cases you may need a shortcut to collect elements for which jQuery doesn't provide a specific filter. This is exactly where custom filters come into play. In this article, extracted from my book Instant jQuery Selectors, you'll learn how to build a custom filter in jQuery. Please note\u2026","rel":"","context":"In &quot;JavaScript&quot;","block_context":{"text":"JavaScript","link":"https:\/\/www.audero.it\/blog\/category\/javascript\/"},"img":{"alt_text":"jquery logo","src":"https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2013\/09\/jquery-logo.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2013\/09\/jquery-logo.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2013\/09\/jquery-logo.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2013\/09\/jquery-logo.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2013\/09\/jquery-logo.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2013\/09\/jquery-logo.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":170,"url":"https:\/\/www.audero.it\/blog\/2013\/09\/16\/15-tips-to-improve-your-jquery-selectors\/","url_meta":{"origin":197,"position":5},"title":"15 Tips to Improve Your jQuery Selectors","author":"Aurelio De Rosa","date":"September 16, 2013","format":false,"excerpt":"Who don't know what jQuery is and how it can help in developing a web project. Based on the latest statistics, jQuery is used on ~60% of the Quantcast Top 100k websites. We use it constantly and sometimes we tend to think it's almost magic, that jQuery is capable to\u2026","rel":"","context":"In &quot;JavaScript&quot;","block_context":{"text":"JavaScript","link":"https:\/\/www.audero.it\/blog\/category\/javascript\/"},"img":{"alt_text":"jquery logo","src":"https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2013\/09\/jquery-logo.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2013\/09\/jquery-logo.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2013\/09\/jquery-logo.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2013\/09\/jquery-logo.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2013\/09\/jquery-logo.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/www.audero.it\/blog\/wp-content\/uploads\/2013\/09\/jquery-logo.png?resize=1400%2C800&ssl=1 4x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/posts\/197","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/comments?post=197"}],"version-history":[{"count":18,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/posts\/197\/revisions"}],"predecessor-version":[{"id":486,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/posts\/197\/revisions\/486"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/media\/266"}],"wp:attachment":[{"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/media?parent=197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/categories?post=197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.audero.it\/blog\/wp-json\/wp\/v2\/tags?post=197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}