I want to have two headings h2 and h3 on the same horizontal rule one on the left and the other on the right. They have a HR underneath them and I want them to be at the same distance from this HR.
I tried making them both inline and have one float right and the other left. The problem with doing so was with h3 as it is smaller than h2 vertically it was centered at half the h2's length.
h2 was kinda like sitting on the hr and h3 kinda looked like floating in mid air.
I kinda wanted them to be like both sitting on the hr.
h2{ display:inline; float:left; } h3{ display:inline; float:right; }
I was talking about visually describing the situation.
The following code will allow you to have two headings on the same line, the first left-aligned and the second right-aligned, and has the added advantage of keeping both headings on the same baseline. Show activity on this post. Add a span with the style="float: right" element inside the h1 element.
So, the solution to place multiple blocks elements in on line, is to embed them in another container, where the <header> tag could advantageously be used to semantically organize your page: <header id="my_header"> <div> <h2>ELEMENT 1</h2> </div> <div> <h2>ELEMENT 2</h2> </div> <div> <h2>ELEMENT 1</h2> </div> </header> ...
Add sub-heading using HTML: The most often way we add sub-headings in HTML is either by using only HTML Headings or using HTML Headings and HTML div. Let's explore both ways of adding sub-heading. Adding Sub Heading using HTML Headings: The HTML heading tag (<h1> , <h2> . . . . <h6>) defines the heading of a page .
You'd need to wrap the two headings in a div
tag, and have that div tag use a style that does clear: both
. e.g:
<div style="clear: both"> <h2 style="float: left">Heading 1</h2> <h3 style="float: right">Heading 2</h3> </div> <hr />
Having the hr
after the div
tag will ensure that it is pushed beneath both headers.
Or something very similar to that. Hope this helps.
You should only need to do one of:
inline
(or inline-block
)float
left or rightYou should be able to adjust the height
, padding
, or margin
properties of the smaller heading to compensate for its positioning. I recommend setting both headings to have the same height
.
See this live jsFiddle for an example.
(code of the jsFiddle):
CSS
h2 { font-size: 50px; } h3 { font-size: 30px; } h2, h3 { width: 50%; height: 60px; margin: 0; padding: 0; display: inline; }
HTML
<h2>Big Heading</h2> <h3>Small(er) Heading</h3> <hr />
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