Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML and CSS button alignment

How can I right align a button inside a div without wiping it from the Markup Flow with valid CSS and HTML? Is applying margin-leftthe only way to do this?

I have a structure like this

<div class="navContainer">
    <div class="title">
        <span>Nav Titulo</span>
    </div>
    <div class="navContent">
        Nav Conteudo
    </div>
    <button type="button">Enviar</button>
</div>

<div class="navContainer">
    <div class="title">
        <span>Nav Titulo</span>
    </div>
    <div class="navContent">
        Nav Conteudo
    </div>
</div>

If I apply button { float: right } or button { position: absolute } the next div will get over the button. It happens that I just want to make the button position at the right side

like image 313
Rodrigo Souza Avatar asked May 01 '26 17:05

Rodrigo Souza


1 Answers

what you want to read up on is clearing

if you have floated elements, they go out of page flow, but any element with clear:both will stay in page flow, but not allow anything on either side of it, floated or not.

in practice, adding a clear:both element after you floats makes things work the way you want them to.

like image 154
Matt Briggs Avatar answered May 03 '26 06:05

Matt Briggs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!