2
<!DOCTYPE html>
<html>
<head>
</head>
<body>

<button type="button" style="width: 40%; float: left; height: 40px">Top!</button>
<button type="button" style="width: 40%; float: right; height: 40px">Top!</button>
<button type="button" style="float: left">Botton!</button>

</body>
</html>

enter image description here

enter image description here

In the above code, the 3th button will only be placed in a new line if the window is so narrow that the space between the 2 top buttons is not enough to fit the 3rd button.

How do I change the code so that the 3nd button will always be placed in a new line regardless of the window width?

2 Answers2

1

Just add

clear:both:
float:left;

to bottom Button

<button type="button" style="clear: both;float: left;">Botton!</button>
0

You should not use float for the 3rd button, instead use a margin like this:

body {
   text-align: center;
}

button:nth-child(3) {
   margin-top: 40px; /*you can use more margin if you want to*/
}
<body>
<button type="button" style="width: 40%; float: left; height: 40px">Top!</button>
<button type="button" style="width: 40%; float: right; height: 40px">Top!</button>
<button type="button">Botton!</button>
</body>
galobponce
  • 38
  • 5