Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align list item numbers with surrounding paragraphs

Tags:

html

css

The list items may contain a couple of paragraphs, images, etc. They should all stay to the right of the item number.

#page {
  width: 200px;
}

li {
  margin: 1em 0;
}
ol {
  padding: 0;
}
<div id="page">
  <p>Some text</p>
  <ol>
    <li>A list item</li>
    <li>A multiline list item another line</li>
    <li>
      <p>A list item containing blocks such as example images:</p>
      <div style="width:128px;height:48px;background:#CCC">Example<br/>Image</div>
    </li>
  </ol>
  <p>Some more text</p>
</div>

Desired result

Ideally I would prefer to keep the list tags rather than use a table or other set of positioned generic blocks.

like image 698
Fire Lancer Avatar asked Jan 13 '17 15:01

Fire Lancer


People also ask

How do you align numbers in a list in HTML?

You can use list-style: inside; to align the numbers.

How do you align list elements in an HTML file?

To center align an unordered list, you need to use the CSS text align property. In addition to this, you also need to put the unordered list inside the div element. Now, add the style to the div class and use the text-align property with center as its value. See the below example.


1 Answers

check out list-style-position property

#page {
  width: 200px;
}
li {
  margin: 1em 0;
  /* this is what you want ↓ */
  list-style-position: inside;
}
ol {
  padding: 0;
}
<div id="page">
  <p>Some text</p>
  <ol>
    <li>A list item</li>
    <li>A multiline list item another line</li>
  </ol>
  <p>Some more text</p>
</div>
like image 109
ashish singh Avatar answered Sep 20 '22 01:09

ashish singh