2

I'm creating a website that has a FAQ page, and i was wondering if i could make an "ordered" list but instead of displaying

  1. question ....
    a) answer .....
  2. question
    a) answer
    etc. which would be done using:

<ol>
  <li>question</li>
      <ol type="A">
        <li>answer</li>
      </ol>
  <li>question 2</li>
      <ol type="A">
        <li>answer 2</li>
        <ol>
</ol>
But is there a way to turn the numbers (and letters) into Question and Answer? or do i have to manually have to type Question and Answer for each line? I have used JavaScript (and css) before but never Jquery. I would prefer to do it with JavaScript.

EDIT: I was unaware of dd and dt (description list) when I asked this question. Originally i was trying to make one line say Question and then Answer on the next line, but the answer @Timothy Jones said made more sense then making an ordered list.

Michael
  • 39
  • 7

3 Answers3

5

I would do this using a description list, and the CSS ::before selector:

<style type="text/css">
   dt::before {
       content: "Question: ";
   } 
   dd::before {
       content: "Answer: ";
   }
</style>
<dl>
  <dt>How would this look?</dt>
      <dd>it would look alright</dd>
  <dt>Alright, well how would this look?</dt>
      <dd>it would also look alright</dd>
</dl>

(add styles as appropriate). I prefer this over a javascript solution, as it doesn't require any processing after the page has loaded.

Timothy Jones
  • 21,495
  • 6
  • 60
  • 90
1

HTML

<ol class="faq">
    <li>
        <ol><li></li></ol>
    </li>
    <li>
        <ol><li></li></ol>
    </li>
    <li>
        <ol><li></li></ol>
    </li>
    <li>
        <ol><li></li></ol>
    </li>
</ol>

CSS

ol { list-style-type: none; }

ol.faq  { padding-left: 0; }

ol.faq > li::before {
    content: "Question";
    color: red;
}

ol.faq > li > ol > li::before {
    content: "Answer";
    color: green;
}

DEMO: http://jsfiddle.net/wxocofu6/5/

Note that in your code your lists are improperly nested.

Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
  • About your note, this is how i was taught and it allows me to understand it easier. I'm trying to get into better habits, but how should it have been done? – Michael Sep 08 '15 at 02:30
  • If you're nesting a list within a list item, you don't close the list item until after the code for the nested items. In other words, consider `
  • ` and `
  • ` a container. All lists you want nested in this list item going between those tags. For a clear illustration see this answer: http://stackoverflow.com/questions/5899337/proper-way-to-make-html-nested-list – Michael Benjamin Sep 08 '15 at 02:34