I want to achieve following layout:
[my button][hello1][hello2]
This is html:
<div id='container'>
<button id='my-button'>my button</button>
<ul id='my-ul'>
<li>hello1</li>
<li>hello2</li>
</ul>
</div>
How to define css?
I want to achieve following layout:
[my button][hello1][hello2]
This is html:
<div id='container'>
<button id='my-button'>my button</button>
<ul id='my-ul'>
<li>hello1</li>
<li>hello2</li>
</ul>
</div>
How to define css?
Flexbox is the right way to this. In this case, you want to align every element in the container element, and the elements in the list, so the css should be
.container {
display: flex;
}
ul {
display: flex;
}
You need to use display: inline-block;
along with removing the padding on the ul
element. Also, I have added a container
class to the div to avoid using IDs in CSS.
.container > button, .container > ul, .container > ul > li {
display: inline-block;
margin: 0;
padding: 0;
}
<div id='container' class="container">
<button id='my-button'>my button</button>
<ul id='my-ul'>
<li>hello1</li>
<li>hello2</li>
</ul>
</div>