Logo image and H1 heading on the same line
529,990
Solution 1
As example (DEMO):
HTML:
<div class="header">
<img src="img/logo.png" alt="logo" />
<h1>My website name</h1>
</div>
CSS:
.header img {
float: left;
width: 100px;
height: 100px;
background: #555;
}
.header h1 {
position: relative;
top: 18px;
left: 10px;
}
Solution 2
Try this:
- Put both elements in a container DIV.
- Give that container the property overflow:auto
- Float both elements to the left using float:left
- Give the H1 a width so that it doesn't take up the full width of it's parent container.
Solution 3
If your image is part of the logo why not do this:
<h1><img src="img/logo.png" alt="logo" /> My website name</h1>
Use CSS to style it better.
And it is also best practice to make your logo a hyperlink that take the user back to the home page.
So you could do:
<h1 id="logo"><a href="/"><img src="img/logo.png" alt="logo" /> My website name</a></h1>
Solution 4
Try this:
<img style="display: inline;" src="img/logo.png" alt="logo" />
<h1 style="display: inline;">My website name</h1>
Solution 5
Just stick the img tag inside the h1 tag as part of the content.
Author by
Six Quads
Updated on June 25, 2020Comments
-
Six Quads about 4 years
I want to create my first web page but I encountered a problem.
I have the following code:
<img src="img/logo.png" alt="logo" /> <h1>My website name</h1>
I'd like to know how to make the logo and the H1 to be in the same line. Thanks!
-
Mr. Alien almost 12 years@Speransky Got almost same.. ;)
-
Mr. Alien almost 12 years@SperanskyDanil You deserve it too am upvoting you, you missed out the
line-height
andclear
I guess -
Alex Alksne over 8 years@Kermit It's pretty self explanatory and worked for me!
-
vaku about 5 yearsWelcome to Stack Overflow @Richa It is always better to
include
thesource
orreferences
in support of your answer and If possible providewhy
your answer works... -
Pawel Cioch over 4 yearsIs is "legal" per HTML specification?