my in my HTML page my look like this :
And I would like it to look like this :
How I can do that with HTML and CSS ?
<ul>
<li>Java ★★★★</li>
<li>Python ★★★★</li>
<li>HTML/CSS ★★★</li>
<li>SQL ★★★</li>
<li>JavaScript ★★★</li>
<li>PHP ★★</li>
<li>C ★★</li>
<li>Scala★</li>
</ul>
Thanks for your help :) !
CodePudding user response:
Wrap the stars inside a span and consider a table layout
ul {
display: table;
}
li {
display: table-row;
}
li span {
display: table-cell;
}
<ul>
<li>Java <span>★★★★</span></li>
<li>Python <span>★★★★</span></li>
<li>HTML/CSS <span>★★★</span></li>
<li>SQL <span>★★★</span></li>
<li>JavaScript <span>★★★</span></li>
<li>PHP <span>★★</span></li>
<li>C <span>★★</span></li>
<li>Scala <span>★</span></li>
</ul>
CodePudding user response:
One solution would be to isolate the text and the HTML entities in their own span elements. Then you can nest these new elements in div
's and use flex
to align them. Then just define a width for your for the second span and you are good to go. I chose 80px
based on the longest rendered width of the text, which happened to be (HTML/CSS).
div {
display: flex;
align-items: center;
}
li {
list-style-type: none;
}
div>span:nth-child(1) {
width: 80px;
}
<ul>
<li>
<div>
<span>Java</span>
<span>★★★★</span>
</div>
</li>
<li>
<div>
<span>Pyhton</span>
<span>★★★★</span>
</div>
</li>
<li>
<div>
<span>HTML/CSS</span>
<span>★★★</span>
</div>
</li>
<li>
<div>
<span>SQL</span>
<span>★★★</span>
</div>
</li>
<li>
<div>
<span>JavaScript</span>
<span>★★★</span>
</div>
</li>
<li>
<div>
<span>PHP</span>
<span>★★</span>
</div>
</li>
<li>
<div>
<span>C</span>
<span>★★</span>
</div>
</li>
<li>
<div>
<span>Scala</span>
<span>★</span>
</div>
</li>
</ul>