Journal CSS: Lists +

12 min read

Deviation Actions

nichtgraveyet's avatar
Published:
4.4K Views
This update shares a method for writing link lists - where your list's purpose is just to list links, with an optional description. click here to skip to it.


Lists on deviantart can be rather ugly beasts, which is why, perhaps, they don't get the love they deserve. A shame really, because with a few simple lines of CSS they can become quite beautiful things.

I've already covered the use of lists in special techniques like hover menus and image list but in this journal/tutorial we go back to basics.


The HTML to create a list is quite simple. Well, HTML is simple in itself anyhow... but lets keep moving. There are three types of list:
  1. the ordered list - with sequential numbers marking each item (like this list here! :))
  2. the unordered list - usually seen as bullet points
  3. and the definition list - a special type of list I'll explain below.


The most commonly used is the unordered list, and with it you can separate a bunch of items into bullet points:

  • The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog. Junk MTV quiz graced by fox whelps. Bawds jog, flick quartz, vex nymphs.
  • Waltz, bad nymph, for quick jigs vex! Fox nymphs grab quick-jived waltz. Brick quiz whangs jumpy veldt fox. Bright vixens jump; dozy fowl quack.
  • Flummoxed by job, kvetching W. zaps Iraq. Cozy sphinx waves quart jug of bad milk. A very bad quack might jinx zippy fowls. Few quips galvanized the mock jury box.
  • Quick brown dogs jump over the lazy fox. The jay, pig, fox, zebra, and my wolves quack! Blowzy red vixens fight for a quick jump. Joaquin Phoenix was gazed by MTV for luck. A wizard's job is to vex chumps quickly in fog. Watch "Jeopardy! ", Alex Trebek's fun TV quiz game. Woven silk pyjamas exchanged for blue quartz.


Compare that to the more common 'fudged' lists, which could use dashes or other symbols to indicate each list item:

- The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog. Junk MTV quiz graced by fox whelps. Bawds jog, flick quartz, vex nymphs.

- Quick brown dogs jump over the lazy fox. The jay, pig, fox, zebra, and my wolves quack! Blowzy red vixens fight for a quick jump. Joaquin Phoenix was gazed by MTV for luck. A wizard's job is to vex chumps quickly in fog. Watch "Jeopardy! ", Alex Trebek's fun TV quiz game. Woven silk pyjamas exchanged for blue quartz.

- The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog. Junk MTV quiz graced by fox whelps. Bawds jog, flick quartz, vex nymphs.


Putting your lists in actual HTML lists is a great because you can use CSS to make them look any way you like. Borders, backgrounds, more spacing, less spacing... whatever. With plain text lists you get none of that.

HTML
The HTML is very similar for ordered and unordered lists, see if you can figure out which is which:

<ul>
  <li>List item</li>
  <li>List item</li>
  <li>List item</li>
</ul>

<ol>
  <li>List item</li>
  <li>List item</li>
  <li>List item</li>
</ol>


List items can contain all sorts of things, not just text. You can put thumb/avatar/username shortcuts (which dA converts into image/link tags) - you can even put a whole other list inside a list item. CRAZY.



Definition lists are special though, instead of placing your list items in li tags, we have definition terms dt and definition descriptions dd:

<dl>
  <dt>term</dt>
  <dd>description</dd>
</dl>


In HTML we are meant to use specific tags for specific purposes, and definition lists have the specific purpose of defining lists of terms, for example:

note: the bold text, and spacing between each item is not part of the pure default styling of definition lists

deviant
Members of deviantART are called 'deviants' - not meant to degrade them or imply shady activity, the term deviant portrays our nature for going off the beaten path and doing things differently.
deviation
On deviantart, a deviation is our pet term for anything a member submits to their gallery - being an instance of 'deviance'.
Gallery Director - 'GD'
deviantART has many galleries, and it's the task of the volunteer Gallery Directors to look after and promote their assigned post.
ass kissers
brown nosers
fan boy/girl
Members of deviantART who hold rank above others, whether it be social or by virtue of being a staff member, tend to attract this kind of person. While many let the attention get to their heads, the rest of us keep it real. This is also an example that shows you can have many dt tags preceding a dd tag.


fixing the annoying space
One last thing to note before we get to the fun stuff - if you write a list in your journal formatted nicely like those examples, you'll find that there will be unwanted extra space between the list items. The extra space is caused by the break tags deviantart inserts whenever it encounters a 'newline' (a hit of the enter key) - to avoid it you could write your lists all bunched on one line, but a nicer solution is to use CSS to hide the tags:

ul br{display: none}
ol br{display: none}
dl br{display: none}

li br{display: inline}
dt br{display: inline}
dl br{display: inline}


The first three lines hide the break tags that cause the problems, and the last three lines retain them when they appear inside the list item itself - somewhere break tags have legitimate use.

ordered list fancypants
By default you will find your ordered lists items marked by numbers, but it is quite simple to make it alphabetical, Roman numerals, or even the Greek alphabet!


lower-latin
  1. aye?
  2. bee
  3. see
  4. dee


upper-roman
  1. one
  2. two
  3. three
  4. four


lower-greek
  1. alpha
  2. beta
  3. gamma
  4. delta

The CSS is simple:

ol{list-style-type: lower-latin }

Check htmldog.com's property list for a full list of values you can give list-style-type.

Note that with the CSS in the example above, all ordered lists in your journal will have that style applied. If you only want to change a specific list, you'll have to wrap it div tags and give the div a class name, then adjust your selector ie: .alpha ol{list-style-type: lower-latin}

custom bullet images
The crowd pleaser :D

  • Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor.
  • Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
  • Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.


There is a property for specifying a bullet image - list-style-image - but you don't get any control over the exact position of the bullet image. Give it a try if you like, but I prefer a different approach.

Instead of using the property, we can apply the bullet image as the background image of the list item, setting a few special properties along the way to make sure it all looks exactly as we want it.

dA only lets us give div and img tags class names, otherwise we'd put the class name in the list tag.
The HTML is the same as any other list, only this time there's an extra div tag surrounding it, with the class name 'custom_bullet' - though you can call it anything you like.

.custom_bullet ul{padding: 0}
.custom_bullet ul li{
  background: url(...) no-repeat;
  padding-left: 20px;
  list-style: none
}


The amount of padding you give depends on the size of your bullet image. Setting it to exactly the width of your bullet will make it touch the text, so be sure to give it a little extra to space things out.

You can also adjust the position of the bullet using the background-position properties - which you can specify separately, or keep within the background shortcut property I have shown above. For instance, if you wanted your list bullets vertically centered:

background: url(...) no-repeat left center;

...would give:

  • Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  • Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor.Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor.
  • Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.


Most useful however, is to use background-position to fine tune the position of a bullet image to make sure it looks right. This will most often happen when the size of the list item doesn't position the bullet image naturally - either because the font size is huge, or because the list item has a lot of padding. Below, I've give the list items a silly amount of padding to illustrate my point:

  • ACK! It looks wrong!
  • Niiiiice!


The second item was fixed with:

background: url(...) no-repeat 0 13px;
...the 0 indicates how many pixels to push the image from the left (in this case, none), and the 13px indicates how many pixels we want to push the image from the top.

For some extra fancypants, you could also change the bullet image on :hover -

  • Collection 1
  • Collection 2
  • Collection 3


Link lists

I'm currently working on this section!

If you want to make a simple list of links, you could write up a list and put your links in the list items... but that's not interesting enough for me, so I'm going to share some fancy pants.

Instead of using list tags (strange, I know, considering this is a tutorial on lists) we're going to make a div, and stick the links right in it. Then we'll use CSS to make it interesting.



...that's about it for now I think. If I've missed something, or if you have any questions, leave a comment :thumbsup:

famfamfam's icons were used in this journal.


© 2008 - 2024 nichtgraveyet
Comments67
Join the community to add your comment. Already a deviant? Log In
Eil's avatar
Thanks for sharing this, it was really helpful :heart:

But... you wouldn't happen to know why my horizontal lists are looking like this: [link] ? :(

It's just a standard unordered list inside a div class.

I tried following a tutorial, but get this problem even though I can view the tut result just fine and copied the code exactly (just did some adjustments to margins/paddings to see if that might be the problem).

CSS:

.menu ul li { display: inline; }

.menu ul li a {
float:left;
width: 40px;
padding:20px;
background:#000;
}