Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change select width to fit div container

I have defined a dropdwon as fellow:

    <div class="form-group">
        <select class="form-control">
            <option>small option</option>
            <option>mediummmmmmmmmmmmmmmmmmmm option</option>                
            <option>large eeeeeeeeeeeeeeeeeeeeee eeeeeeeeeeeeeee eeeeeeeeeeeee eeee option</option>
        </select>
    </div>

I want to change select width to be minimum of container width and option text width. If option text is bigger than div container, truncate option's text and put ellipsis at the end. So the option stays inside the container. Also select must be responsive, When resizing window, select width should be updated to fit new window width.

How can I achieve that using bootstrap CSS?

like image 933
Mhd Avatar asked Nov 14 '17 15:11

Mhd


People also ask

How do I fit a div into a container?

Method 2: We can make the display attribute of the child container to table-row and display attribute of parent container to table, that will take all the height available from the parent div element. To cover all the width, we can make the width of parent div to 100%.

How do I make div width auto adjust to content?

One way you can achieve this is setting display: inline-block; on the div . It is by default a block element, which will always fill the width it can fill (unless specifying width of course).


1 Answers

try width:100%;

It works for me each element in ListView

like image 77
Emi Avatar answered Oct 22 '22 18:10

Emi