Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indentation of <ul><li>

Tags:

html

css

I have a list of items and it will take up two lines or more.

enter image description here

When it gets longer than the width of the div, it wraps to the next line like the example below.

enter image description here

How can I make the second line to start in alignment with Item1 and can be done responsively?

enter image description here

ul li {
  display: inline-block;
}
<ul>
  <li><strong>List of items:</strong></li>
  <li><a href="#">Item1</a></li>
  <li><a href="#">Item2</a></li>
  <li><a href="#">Item3</a></li>
  <li><a href="#">Item4</a></li>
  <li><a href="#">Item5</a></li>
  <li><a href="#">Item6</a></li>
  <li><a href="#">Item7</a></li>
</ul>
like image 297
Organic Heart Avatar asked Mar 02 '20 02:03

Organic Heart


People also ask

What is the difference between Ul and indent in CSS?

The first css definition for ul sets the base indent that you want for the list as a whole. The second definition sets the indent value for each nested list item within it. In my case they are the same, but you can obviously pick whatever you want.

How to remove indentation from an unordered list using CSS?

To remove that indentation from an unordered list (a list having bullets) there needs styling to be done using CSS. The style will be implemented only on the list. So the selector would be ul. Example: This example creates a page with a list with zero (0) indent . In the above example, padding-left property is used to set the indentation from left.

Which selector is used to set the indentation from left?

So the selector would be ul. Example: This example creates a page with a list with zero (0) indent . In the above example, padding-left property is used to set the indentation from left.

How do you indent a lis in HTML?

You can indent the lis and (if applicable) the as (or whatever content elements you have) as well , each with differing effects. You could also use padding-left instead of margin-left, again depending on the effect you want. By default, many browsers use padding-left to set the initial indentation.


Video Answer


1 Answers

It seems that the title of your unordered list is List of items. Semantically speaking, it should be moved into a heading element outside of the unordered list itself.

Then you can use flexbox on a wrapper element to vertically align its child elements (the heading and the unordered list).

.wrapper {
  display: flex;
  align-items: flex-start;
}

ul li {
  display: inline-block;
  margin-right: 0.5em;
}

h2, li {font-size: 16px}

h2 {flex-shrink: 0;}

h2, ul {margin: 0;}

ul {padding-left: 0.5em;}
<div class="wrapper">
  <h2>List of items:</h2>
  <ul>
    <li><a href="#">Item1</a></li><li><a href="#">Item2</a></li><li><a href="#">Item3</a></li><li><a href="#">Item4</a></li><li><a href="#">Item5</a></li><li><a href="#">Item6</a></li><li><a href="#">Item7</a></li><li><a href="#">Item8</a></li><li><a href="#">Item9</a></li><li><a href="#">Item10</a></li><li><a href="#">Item11</a></li><li><a href="#">Item12</a></li><li><a href="#">Item13</a></li>
  </ul>
</div>
like image 138
ksav Avatar answered Oct 02 '22 10:10

ksav