Logo image and H1 heading on the same line

2019-01-22 01:25发布

I wanna create my first web page but encountered a problem.

I have the following code:

<img src="img/logo.png" alt="logo" />
<h1>My website name</h1>

I want to know how to make the logo and the H1 to be in the same line. Thanks!

11条回答
2楼-- · 2019-01-22 01:40

Try this:

<img style="display: inline;" src="img/logo.png" alt="logo" />
<h1 style="display: inline;">My website name</h1>
查看更多
走好不送
3楼-- · 2019-01-22 01:41

in your css file do img { float: left; } and h1 {float: left; }

查看更多
\"骚年 ilove
4楼-- · 2019-01-22 01:42

Just stick the img tag inside the h1 tag as part of the content.

查看更多
淡お忘
5楼-- · 2019-01-22 01:42

Check this.

 .header{width:100%;
    }

    .header img{ width: 20%; //or whatever width you like to have

    }

    .header h1{

    display:inline; //It will take rest of space which left by logo.
}
查看更多
聊天终结者
6楼-- · 2019-01-22 01:44
<head>
<style>
header{
    color: #f4f4f4;
    background-image: url("header-background.jpeg");    
}

header img{
    float: left;
    display: inline-block;
}

header h1{
    font-size: 40px; 
    color: #f4f4f4;
    display: inline-block;
    position: relative;
    padding: 20px 20px 0 0;
    display: inline-block;
}
</style></head>


<header>
<a href="index.html">
    <img src="./branding.png" alt="technocrat logo" height="100px" width="100px"></a>
    <a href="index.html">
    <h1><span> Technocrat</span> Blog</h1></a>
</div></header>
查看更多
Evening l夕情丶
7楼-- · 2019-01-22 01:47

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>
查看更多
登录 后发表回答