Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get whatever default style <h2> has, without having my text on a single line?

Tags:

html

css

I realize that in the modern day, most people use CSS to perform styling, and will have CSS define what H2 looks like.

However, please imagine that I'm trying to make my text looks like it is the default appearance of <h2>, but have it on a line with other text.

Is it possible to do this in HTML4?

Alternatively, is it possible to emulate it using CSS? Assume I am NOT setting a style on <h2> directly.

like image 318
merlin2011 Avatar asked Jan 17 '23 12:01

merlin2011


2 Answers

By default, all HTML headings (<h1> to <h5>) are displayed as block. This means a heading will be in a separate line if there is other elements surrounding it.

You can change that with CSS by applying display: inline to your heading. If you need it to keep some block behavior (like having a certain width, for example), you can use display: inline-block instead.

like image 150
bfavaretto Avatar answered Jan 30 '23 19:01

bfavaretto


Give a try to that:

<!DOCTYPE html>
<html>
<body>

<style>
.h2{
   font-size: x-large;
   font-weight: bold;
   display: inline;
}
</style>

<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<p class="h2">This is heading 2</p>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>

</body>
</html>

And you should disable your current styles applying to the current h2. For example: color: black !important; (if it's defined)

like image 31
Jordi P.S. Avatar answered Jan 30 '23 20:01

Jordi P.S.