CSS: Getting indent to work

时间:2016-02-03 04:16:39

标签: css

I'm trying to put space before the numbering. However, I'm not able to put spaces on the second line.

For example, I would like in this format below:

    1. This is a question. The second line will have to be indent as well. 
       Testing on second line now. 
       THIS IS AN ANSWER SECTION.

However, I'm only able to get this below:

1. This is a question. The second line will have to be indent as well. 
Testing on second line now. 
   THIS IS AN ANSWER SECTION.

I've made a fiddle here: https://jsfiddle.net/96a7hmq5/15/ Please click on the question to show more.

2 个答案:

答案 0 :(得分:5)

I know this may go without saying, but if you just use an ordered list, the indent would be handled automatically.

<ol>
  <li>This is a question. The second line will have to be indent as well.<br/>
Testing on second line now. <br/>
THIS IS AN ANSWER SECTION.
  </li>
  <li>This is the 2nd numbered item.<br>
This is the second line of the 2nd item<br>
ANSWER LINE HERE
  </li>
</ol>

答案 1 :(得分:1)

您可以使用数字的数据属性

<h4 class="accordion-toggle" data-number="1.">

并将h4位置设置为相对,并在伪类后添加,并将内容设置为您的数字。

Final result

    .accordion-toggle{
      position:relative;
      display: block;
      margin-left: 10px;;
    }


    .accordion-toggle:before{
      position: absolute;
      left: -15px;
      top:0px;
      content: attr(data-number);
    }