将我的徽标链接到主页 html
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14775507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Link my Logo to homepage html
提问by Maarten Verstraten
I want to make my Logo in my header clickable and link to the homepage but i don't know exactly how to do this right.
我想让我的标题中的徽标可点击并链接到主页,但我不知道如何正确地做到这一点。
My code:
我的代码:
Navigation menu:
导航菜单:
HTML
HTML
<div id="myMenu">
<div class="myWrapper">
<nav>
<div class="logo"></div>
</nav>
</div>
</div>
CSS
CSS
#myMenu
{
width: 100%;
height: 30px;
z-index: 999;
background-color: #252e30;
}
.myWrapper
{
max-width: 660px;
margin: 0 auto;
}
.logo
{
display: inline-block;
width: 156px;
height: 30px;
margin-top: 5px;
background-size: auto 43px;
background-image: url(../images/mylogo.png);
background-repeat: no-repeat;
}
I want my logo make clickable and link to the page: Homepage.cshtml
我希望我的徽标可点击并链接到页面:Homepage.cshtml
回答by Jonah Bishop
Instead of using CSS to set your logo as a background image, what would be wrong with using the img
tag, surrounding by a link? Like so:
不是使用 CSS 将您的徽标设置为背景图像,而是使用img
由链接包围的标签有什么问题?像这样:
<div id="myMenu">
<div class="myWrapper">
<nav>
<a href="/"><img src="../images/mylogo.png" height="30" width="156" /></a>
</nav>
</div>
</div>
This has the added benefit of being more accessible (especially if you use an alt
attribute on your logo), which makes search engine bots happier. Image content that conveys meaning to the user should never bet set using CSS.
这具有更易于访问的额外好处(特别是如果您alt
在徽标上使用属性时),这使搜索引擎机器人更快乐。向用户传达意义的图像内容不应该使用 CSS 设置。
回答by Tim Baas
You better use an image wrapped in an anchor-tag.
您最好使用包含在锚标记中的图像。
But else this should work:
但否则这应该有效:
<div class="logo" onclick="window.location.href='homepage.html'"></div>
回答by digitalfrenchfry
You can't make a background image a link. Move the image into the HTML code, and then make that a link.
您不能将背景图像设为链接。将图像移动到 HTML 代码中,然后将其设为链接。
回答by Hyman Allen
<div id="myMenu">
<div class="myWrapper">
<nav>
<a href="Homepage.cshtml"><div class="logo"></div></a>
</nav>
</div>
</div>
回答by Roger C
Use an <a>
instead of the <div>
for the logo..
使用<a>
代替<div>
徽标..