I thought using float: right;
would fix this, but it makes the button appear outside of the div. How do I solve this?
HTML
<div id="main"> <h1>Title</h1> <button>Button</button> </div>
CSS
#main { width: 200px; border: 1px dotted black; } h1 { margin: 0; } button { float: right; }
JSFiddle
As such, nesting a heading element inside of a button element will cause failures for WCAG requirement 1.3. 1, Info and Relationships, because the heading has lost semantic meaning. This rule checks <button> elements to see if they contain heading ( <h1> - <h6> ) elements, and gives an error message if they are found.
Give your h1 display: inline-block to allow your elements to occupy the same row... In my case I wanted the heading text centered, so I was able to get that by replacing "display: inline-block" with "text-align: center".
You need to absolutely position the buttons inside the header. To do so, add position:relative to the button's parent element and add position: absolute and something like top: 10px; right: 30px; to the buttons.
Give your h1
display: inline-block
to allow your elements to occupy the same row...
#main { width: 200px; border: 1px dotted black; } h1 { margin: 0; display: inline-block; } button { float: right; }
<div id="main"> <h1>Title</h1> <button>Button</button> </div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With