.selectlist {
width: auto;
display: inline-block
}
.selectlist li {
width: 60px;
cursor: pointer;
position: relative;
left: 0;
background-color: #EEE;
margin: .5em;
padding: .3em 0;
height: 1.6em;
border-radius: 4px;
}
<ul class="selectlist">
<li>this is line test 1</li>
<li>this is line 2</li>
<li>this is line 3</li>
</ul>
I am trying to modify the following make <li>
or <ul>
element to fit the length of given text with CSS only. The width: auto
makes the elements occupy the whole screen width.
.ul {
margin: 0 0 2em 0;
list-style-type: none;
padding: 0;
width: auto;
}
.ul li {
width: auto;
cursor: pointer;
position: relative;
left: 0;
background-color: #EEE;
margin: .5em;
padding: .3em 0;
height: 1.6em;
border-radius: 4px;
}
If it is not possible to make the list to fit the length of text then can I make the text fit into the given width of the element by modifying the above CSS?
Update: Thanks for all the replies. The above code formats list items to look like rectangle shape.
I tried all your suggestions and the text wraps into a second line which appear outside the rectangle shape. I just realized my question is limited to the above code scenario, not a general one.
Please see the snippet. I would like fixed length rectangle and make the text fit into it.