{"id":219,"date":"2008-08-19T17:01:04","date_gmt":"2008-08-19T22:01:04","guid":{"rendered":"http:\/\/cssnewbie.com\/?p=219"},"modified":"2008-08-19T17:01:04","modified_gmt":"2008-08-19T22:01:04","slug":"5-great-uses-for-the-css-display-property","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/5-great-uses-for-the-css-display-property\/","title":{"rendered":"5 Great Uses for the CSS Display Property"},"content":{"rendered":"<p><a href=\"http:\/\/cssnewbie.com\/horizontal-dropdown-menus\/\"><img decoding=\"async\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/05\/horizontalmenu-400.gif\" alt=\"\" border=\"0\" \/><\/a><\/p>\n<p>The display property is a bit of an unheralded workhorse in the CSS world. Even though <a href=\"http:\/\/www.w3schools.com\/css\/pr_class_display.asp\">the list of theoretical display property values<\/a> is quite long, only three of them ever see any use (primarily due to poor browser support on the others): inline, block, and none. <\/p>\n<p>The inline value allows you to define an element to behave as though it were an inline element (like a span or an anchor tag). Conversely, the block value lets you force block-level behavior (like a div or a paragraph). And &ldquo;display: none&rdquo; simply causes an element to not display at all.<\/p>\n<p>But despite the display property&#8217;s seemingly limited use, you&#8217;d be surprised how many CSS techniques rely on this little workhorse to get the job done. Here are five CSS techniques I&#8217;ve written about in the past that wouldn&#8217;t exist without the help of the display property.<\/p>\n<h3>Showing\/Hiding Content<\/h3>\n<p><a href=\"http:\/\/cssnewbie.com\/showhide-content-css-javascript\/\"><img decoding=\"async\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/05\/showhide-400.gif\" alt=\"\" \/><\/a><\/p>\n<p>One popular technique that relies on the display property is the <a href=\"http:\/\/cssnewbie.com\/showhide-content-css-javascript\/\">Show\/Hide Content technique (explained in much greater detail here)<\/a>, which uses CSS and JavaScript to show or hide additional content when the users clicks on a button.  The ability to &ldquo;hide&rdquo; content on a page is a cornerstone of the modern web: too many options at once leaves a user feeling overwhelmed, but too few options can leave your audience feeling constrained. This technique allows you to get the best of both worlds.<\/p>\n<h3>Making Closeable DIVs<\/h3>\n<p><a href=\"http:\/\/cssnewbie.com\/message-box-javascript-css\/\"><img decoding=\"async\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/04\/messagebox-400.gif\"\/ alt=\"\"><\/a><\/p>\n<p>In-document message boxes can be quite useful when used for the powers of good &mdash; and not, say, to create annoying pop-in ads right in the middle of a page you&#8217;re trying to read. Luckily, whether used for good or evil, most all in-document popups come with a &ldquo;close&rdquo; option: and that close option is almost always the work of the &ldquo;display: none&rdquo; rule. <a href=\"http:\/\/cssnewbie.com\/message-box-javascript-css\/\">Learn more about creating in-document message boxes here.<\/a><\/p>\n<h3>Creating RSS-Only Content<\/h3>\n<p><a href=\"http:\/\/cssnewbie.com\/hiding-content-in-your-rss-feed\/\"><img decoding=\"async\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/07\/rssfeed.gif\" alt=\"\" \/><\/a><\/p>\n<p>As I wrote about in a recent article, <a href=\"http:\/\/cssnewbie.com\/hiding-content-in-your-rss-feed\/\">hiding content in your RSS feed<\/a> doesn&#8217;t have to require a fancy plug-in &mdash; which is good for people who aren&#8217;t relying on a fancy content management system to generate their pages. Instead, producing RSS-only content can be as simple as hiding your content in your page with the display property &mdash; which is then ignored when picked up by RSS feed readers.<\/p>\n<h3>Building Dropdown Menus<\/h3>\n<p><a href=\"http:\/\/cssnewbie.com\/easy-css-dropdown-menus\/\"><img decoding=\"async\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/05\/dropdown-400.gif\" alt=\"\" \/><\/a><\/p>\n<p>Without the CSS display property, fancy dropdown menus would be limited to the realm of JavaScript. However, by combining CSS&#8217;s display property and the :hover pseudo-class, you can create beautiful dropdown menus without a single line of JavaScript. Want to learn how? <a href=\"http:\/\/cssnewbie.com\/easy-css-dropdown-menus\/\">Here&#8217;s a tutorial on creating easy CSS dropdown menus,<\/a> and <a href=\"http:\/\/cssnewbie.com\/horizontal-dropdown-menus\/\">here&#8217;s a second tutorial on creating special horizontal dropdowns.<\/a><\/p>\n<h3>Fixing Bugs<\/h3>\n<p><a href=\"http:\/\/cssnewbie.com\/double-margin-float-bug\/\"><img decoding=\"async\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/06\/doublemargin-400.gif\" alt=\"\" \/><\/a><\/p>\n<p>If you work on web development long enough, sooner or later some browser is going to throw a bug your way (Internet Explorer 6, I&#8217;m looking at you). But just because there&#8217;s a bug in the browser doesn&#8217;t mean that the fix has to be complicated. In fact, two of the most common Internet Explorer bugs out there &mdash; <a href=\"http:\/\/cssnewbie.com\/fixing-ie6-whitespace-bug\/\">the IE6 Whitespace Bug<\/a> and <a href=\"http:\/\/cssnewbie.com\/double-margin-float-bug\/\">the IE Double Margin Float Bug<\/a> &mdash; both use the &ldquo;display: inline&rdquo; property to make IE behave properly. Click the bug names for more in-depth information. <\/p>\n<p>So when you get right down to it, the display property is a pretty useful little guy, even if only three of its values are supported. Just imagine how prolific it&#8217;d be if all its values were available!<\/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>Despite the display property&#8217;s seemingly limited use, you&#8217;d be surprised how many CSS techniques rely on this little workhorse to get the job done. Here are five CSS techniques I&#8217;ve written about in the past that wouldn&#8217;t exist without the help of the display property. [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/5-great-uses-for-the-css-display-property\/\" title=\"Click to read '5 Great Uses for the CSS Display Property'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[168,192],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/219"}],"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\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=219"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/219\/revisions"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}