{"id":38,"date":"2008-02-25T07:00:04","date_gmt":"2008-02-25T13:00:04","guid":{"rendered":"http:\/\/cssnewbie.com\/css-rules\/style-unordered-lists\/"},"modified":"2008-02-25T07:00:04","modified_gmt":"2008-02-25T13:00:04","slug":"style-unordered-lists","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/style-unordered-lists\/","title":{"rendered":"5 Ways to Set Your Unordered Lists Apart"},"content":{"rendered":"<p><img src='https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/02\/style-unordered-lists.gif' alt='Example of a styled unordered list' \/><\/p>\n<p>Unordered lists are one of the most pervasive elements on the web, probably just behind paragraphs and hyperlinks in terms of their bunny-like abundance. And for good reason: bulleted (i.e., unordered) lists are a great way to convey a bunch of related information in a rather small space, which is often the preferred way to read on (and thus, write for) the internet.<\/p>\n<p>Last week, I showed you how to turn an ordinary, unassuming <a href=\"\/navigation\/tab-based-navigation\/\">unordered list into a navigation bar.<\/a> And then we <a href=\"\/navigation\/intelligent-navigation\/\">made that nav bar even cooler<\/a> with a bit of JavaScript. But sometimes, you just need a list to be a list. But that isn\u2019t to say it has to be a <em>boring looking<\/em> list. Here are five different ways to style your unordered lists with CSS.<\/p>\n<h3>1: Change your Bullets<\/h3>\n<p>Sometimes, all your list needs is a new set of bullets to set it apart from all the other lists out there. For that, you\u2019d turn to the list-style-type attribute, like so:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">ul {\n\tlist-style-type: circle; \n}<\/pre>\n<p>This sets your bullet type to a hollow circle, <a href=\"\/example\/style-unordered-lists\/#one\">as shown in this example.<\/a> And there are other list-style-types out there, as well. \u201cDisc\u201d is the default style, but \u201csquare\u201d has a nice look, as well.<\/p>\n<h3>2: Add Margins and Padding<\/h3>\n<p>If you really want your list to stand out, you could do worse than to literally set it apart with a bit of margin and padding:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">ul {\n\tmargin: 2em; \n}\nul li {\n\tpadding-left: 1em; \n\tmargin-bottom: .5em; \n}<\/pre>\n<p><a href=\"\/example\/style-unordered-lists\/#two\">As you can see in this example,<\/a> our first rule applies a 2 em margin to all four sides of our unordered list \u2013 moving it away from the surrounding paragraphs both vertically and horizontally. The left padding on the list item puts a little space between the bullet and the text, adding to the airy feel. The margin on the bottom of the list item opens a bit of space between the individual items in our list.<\/p>\n<h3>3: Use an Image<\/h3>\n<p>One of the easiest ways to make your lists truly unique (and to ensure they mesh well with your site\u2019s design) is to use images instead of bullets. Here\u2019s how to do it:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">ul {\n\tlist-style-image: url(check.gif); \n}<\/pre>\n<p>Easy, no? <a href=\"\/example\/style-unordered-lists\/#three\">Yet the effect is dramatic:<\/a> all of our list items now have a checked box next to them instead of a bullet. And it doesn\u2019t have to be a checkbox, either \u2013 it could be anything your creative little heart desires. One caveat to this technique is to remember that, unlike the default bullet types, these images won\u2019t grow and shrink with your items if your readers change the text size.<\/p>\n<h3>4: Borders, Backgrounds and the Hover Class<\/h3>\n<p>For a unique list style that doesn\u2019t make use of images, you could always use borders, background colors, and the :hover pseudo-class to set your list apart:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">ul {\n\tlist-style: none;\n\tmargin: 1em 0;\n\tpadding: 0; \n}\nul li {\n\tfont-weight: bold;\n\tmargin: 0;\n\tpadding: 3px 10px 5px 20px;\n\tborder-bottom: 1px solid #ccc;\n\tcolor: #666; \n}\nul li:hover {\n\tcolor: #000;\n\tbackground-color: #ddd; \n}<\/pre>\n<p><a href=\"\/example\/style-unordered-lists\/#four\"><br \/>\nIn this example,<\/a> we\u2019re turning off the bullets altogether with a list-style: none rule, then styling the list items by changing their color, giving them a bit of padding, making them boldface, and setting a border along the bottom. Then, when the user hovers their mouse over the list item, it darkens slightly and we apply a pale gray background color, which would help the reader keep their place in a long list more easily.<\/p>\n<p>Of course, IE6 doesn\u2019t recognize the :hover class on anything other than anchors, so if you needed this to show up in IE6, you\u2019d need to apply an anchor to your text\u2026 which is why this technique is usually reserved for sidebar links or lists of similar ilk.<\/p>\n<h3>The Whole Shebang<\/h3>\n<p>Of course, why stop at just using <em>one<\/em> of these techniques, when you could apply several at once? Here\u2019s our mega-styled list:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">ul {\n\tmargin: 1.5em; \n}\nul li {\n\tlist-style-image: url(uncheck.gif);\n\tborder-bottom: 1px solid #ccc;\n\tpadding: .2em 0 .2em .5em;\n\tfont-weight: bold;\n\tcolor: #666; \n}\nul li:hover {\n\tcursor: pointer;\n\tlist-style-image: url(check.gif);\n\tbackground-color: #f2f2f2;\n\tcolor: #000; \n}\n<\/pre>\n<p><a href=\"\/example\/style-unordered-lists\/#five\">In this attractive example,<\/a> we are:<\/p>\n<ul>\n<li>Setting a margin on the list to set it apart,<\/li>\n<li>Setting padding and a border on the list item,<\/li>\n<li>Using an image instead of a bullet,<\/li>\n<li>Changing the font-weight and color of the text, and<\/li>\n<li>Using the :hover pseudo-class to change the cursor type, set a new list image, apply a subtle background, and darken the text.<\/li>\n<\/ul>\n<p>Now that\u2019s a nice looking list. Of course, as before, our hover elements won\u2019t show up in IE6 (though IE7 will handle them fine). But our list is still pretty darn distinctive even without the hover class.<\/p>\n<p>These are just five of a nearly infinite variety of options. What techniques do you use to set your lists apart? Oh, and be sure to <a href=\"http:\/\/feeds.feedburner.com\/cssnewbie\">subscribe to our feed,<\/a> because later this week I\u2019ll show you a trick for styling nested <strong>ordered<\/strong> lists that really makes them more attractive and user-friendly.<\/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>\n<p>Unordered lists are one of the most pervasive elements on the web, probably just behind paragraphs and hyperlinks in terms of their bunny-like abundance. And for good reason: bulleted (i.e., unordered) lists are a great way to convey a bunch [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/style-unordered-lists\/\" title=\"Click to read '5 Ways to Set Your Unordered Lists Apart'\">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":[173,186],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/38"}],"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=38"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/38\/revisions"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=38"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=38"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=38"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}