Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling the line-height of a <br> tag within a heading tag?

I have a heading (<h1>) that has a sort of tagline below it. (I used a <small> tag and set font-size to a certain percent so it lines up perfectly when I change font-size of the heading for smaller screens. I'm using em units, if that matters.)

At first, the <small> tag sat nicely underneath the main heading, but I realized I forgot the HTML5 DOCTYPE declaration. So, after I discovered this omission and corrected it, the spacing was all wrong.

Here's my code:

HTML:

<h1 class="banner">Justin Wilson<br /><small>WEB + GRAPHIC DESIGNER</small></h1>

CSS:

h1.banner {
text-align: center;
display: block;
font-family: 'arvil';
font-size: 6.5em;
color: #94babd; }

h1.banner > small {
font-family: Helvetica, Arial, sans-serif;
font-size: 27%;
color: #888;
letter-spacing: 1px;
font-weight: 100; }

And here's the before and after:

Before and after doctype declaration

I have searched through StackOverflow, but I'm not sure how to proceed. I've read that a <br /> tag simply line breaks, but it inherits the line-spacing, and line-spacing: (value) does not work, nor do margins or padding.

What I need is a simple, cross-browser solution. I used Chrome for the screenshot. Support for IE6-7 is not needed, though support for IE8 would be nice.

like image 524
Justin W Avatar asked May 06 '13 18:05

Justin W


People also ask

How do you adjust the BR tag height?

You can't change the height of <br> tag as its not an HTML element, it is just an instruction which enforces a line break. br does not take up any space in the page. There is a way by which you can increase line break between lines, is by putting multiple br tags.

What is the height of Br?

<br> is a line break. It doesn't have a height, it just breaks the line. Doesn't replacing mean, removing the element?

Can you style a BR tag?

Takeaway : br tag should not be used for styling.

What can I use instead of Br in CSS?

Instead of using the <br> tag, you should use a semantic HTML element and the CSS margin or padding properties if necessary.


1 Answers

The problem is caused by the default line height for the heading element. The default depends on the browser and on the font, but it tends to be about 1.1 to 1.3 times the font size. In any case, with a very large font size set, this creates a problem, because the line height value also sets the height of the second line. By CSS specifications, for a block element, line-height sets the minimum height of line boxes.

There are various ways around this. Setting display: block on the small element is one way, since then its default line height will be determined according to its own font size. Another way is to set a line height that is considerably smaller than the font size, e.g.

h1.banner { line-height: 0.5; }
like image 69
Jukka K. Korpela Avatar answered Sep 30 '22 10:09

Jukka K. Korpela