My following code for a simple webpage on the browser:
The buttons on the webpage show up as inline elements instead of of one on top of the other consecutively. Happens as well with using flexbox. Items within the container become inline without stating display: flex-inline.
<h1 id="id1">My Heading 1</h1>
<p id="demo"></p>
<button type="button" onclick="document.getElementById('id1').style.color = 'red'">
Click Me!</button>
<button onclick="displayDate()">Try it</button>
I tried adding a <br>
tag
3
Answers
<button>
is not a block element. To stack them on top of each other,1- one way is to wrap them in
<div>
s2- Another is to use
display: block
style on them.3- Or to wrap both of them in a
<div>
with display set toflex
andflex-direction
tocolumn
By default, buttons have a display of
inline-block
. If you want to change that, explicitly set thedisplay
.Buttons are inline elements (well, inline-block) by default.
When you make an element
display: flex
ordisplay: flex-inline
its children are arranged in a row (by default) or column (if you specifyflex-direction: column
).The difference between
flex
andflex-inline
is how the parent element is rendered, not the children.If you want the buttons displayed on consecutive lines then you can:
<br>
between them (without involving flexbox) or<div>
(also without involving flexbox) orI can’t infer the semantics of your data (largely because it seems to be a mishmash of demo elements and not a straight-forward text) so I can’t comment on which option(s) would be appropriate.