Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the letters "Q" and "A" inside a list in HTML

Tags:

html

css

Is it possible to set up a list in HTML or CSS to use specific letters instead of bullets?

Example:

Q. a question will be posted here.
A. the answer will go here.

I know I can go in and format each entry, but I would prefer to modify individual <li> tags with a class.

like image 414
user2700707 Avatar asked Aug 20 '13 16:08

user2700707


3 Answers

Semantically, a <dl> is a better fit for Q/A. You can use the :before pseudo-element like so:

dt:before {
  content: 'Q. ';
}
dd:before {
  content: 'A. ';
}
<dl>
  <dt>Is this a question?</dt>
  <dd>Yes, it is.</dd>
</dl>

Note: According to the documentation for <dl> (emphasis mine):

Name-value groups may be terms and definitions, metadata topics and values, questions and answers, or any other groups of name-value data.

like image 104
canon Avatar answered Nov 17 '22 17:11

canon


Yes, you can use :before pseudo-selector like this:

li.question:before {
    content: "Q. ";
}
li.answer:before {
    content: "A. ";
}

Now you just apply classes question and answer to those <li> elements.

like image 35
Mike Brant Avatar answered Nov 17 '22 17:11

Mike Brant


You could use a combination of :nth-child and :before.

li {
    list-style:none;
}   
li:nth-child(odd):before {
    content:"Q. "; 
}
li:nth-child(even):before {
    content:"A. "; 
}

Example: http://jsfiddle.net/Xt72Y/

It works with both ol and ul and does not require changing the html.

like image 1
Appleshell Avatar answered Nov 17 '22 18:11

Appleshell