We have an adaptive layout where some list elements are displayed horizontally:
| Li1 | Li2 | Li 3 | Li4 |
Obviously I can just set
ul {width:100%}
ul li {width:25%}
To have the li's change size as the browser changes size. However, we want the left edge of the left-most li to align to the left edge with the right-most li right edge aligning to the right edge even as the browser expands.
Li1 Li2 Li3 Li4
| |
Li1 Li2 Li3 Li4
| |
Li1 Li2 Li3 Li4
| |
Is there a way to do this with pure css?
Use this solution (or this one). Translating that answer to a list results in:
Markup:
<ul>
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ul>
Style sheet:
ul {text-align: justify}
ul::after {width: 100%; display: inline-block; content: "."; visibility: hidden}
li {display: inline-block}
This is an IE7+ solution. For IE7 you need an extra element adjacent to the list items.
IMHO, the best way is use CSS3 Flexboxes:
.menu {
display: flex;
justify-content: space-around;
}
space-between more exactly answers the question - Mike O'Connor 2017-11-14 12:18
this is what I get this far.. could be a start for you
HTML
<div id="container">
<ul>
<li class="fisrt">1</li>
</ul>
<ul class="center">
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<ul>
<li class="last">5</li>
</ul>
</div>
CSS
#container
{
}
li
{float:left;
border:1px solid red;
width:120px;}
.fisrt
{
float:left;
}
.last
{
float:right;
}
.center
{
width:400px;
margin:auto;
}
Hi you define text align justify in you li as like this
css
ul {width:100%}
ul li {width:25%;
list-style:none;
display:inline-block;
text-align:justify;
margin:2px;
background:yellow;
word-wrap: break-word;
}
HTML
<ul>
<li>Demo text hrere Demo text hrere Demo text hrere Demo text hrere Demo text hrere Demo text hrere Demo text hrere </li>
<li>Demo text hrere Demo text hrere Demo text hrere Demo text hrere Demo text hrere Demo text hrere Demo text hrere </li> <li>DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD</li>
</ul>
Live demo here http://jsfiddle.net/rohitazad/8UakC/8/