I have created a HTML document which contains multiple buttons. I have added these buttons inside a DIV id named ‘buttons’. I now want to add a sort by button to the HTML page. This sort button should be on the same line as the other buttons, To do this, I have created a new DIV id inside ‘buttons’. This code displays the sort button above the other buttons. Not inline.
I want to display the sort button inline with the rest of the elements. However, the other buttons should not move. How could I do this.
An example of the code:
<div id="buttons">
<div id="sort-by-buttons">
<select name="sort-by" id="sort-by">
<option value="all">All</option>
<option value="name">Name</option>
<option value="price">Price</option>
</select>
</div>
<button class="button-value" onclick="filterProduct('all')">All</button>
<button class="button-value" onclick="filterProduct('jacket')">Jacket</button>
</div>
2
Answers
Style the div and buttons:
There are multiple solutions for this problem:
Solution 1
Remove the container div
#sort-by-buttons
.If Solution 1 is not possible, because you need
#sort-by-buttons
for some reason, you can have a look on the following two solutions:Solution 2
Add
display: flex
to the container div#buttons
.Solution 3
Make
#sort-by-buttons
inline-block
.