[英]center horizontally a clickable image inside a div
How do we center horizontally inside a div an image that we want to be clickable? 我们如何在div内水平居中放置想要单击的图像?
HTML: HTML:
<div class="logo-wrap">
<img class="logo" src="img/logo.png" width="262" height="53" />
</div>
CSS: CSS:
.logo-wrap{
text-align: center;
}
img.logo {
margin-left: auto;
margin-right: auto;
}
I need to put the "a" tag somewhere and give it a proper CSS. 我需要将“ a”标签放在某个地方,并为其提供适当的CSS。 Any idea?
任何想法?
<div class="logo-wrap">
<a href="http://www.facebook.com"><img src="img/logo.png" width="262" height="53" /></a>
</div>
My personal preference is to manage it all with css providing more control. 我个人的喜好是使用CSS提供更多控制权来管理所有内容。
HTML HTML
<div class="logo-wrap">
<a class="logo"/>
</div>
CSS CSS
.logo-wrap{
text-align: center;
}
.logo {
background:#68c url('img/logo.png') no-repeat center center;
margin:0 auto;
height:53px;
width:262px;
display:block;
cursor:pointer;
}
html HTML
<div class="logo-wrap">
<a href="#">
<img class="logo" src="img/logo.png" />
</a>
</div>
css CSS
.logo-wrap{
width:100%;
}
.logo{
width:50%;
display:block;
margin:0 auto;
}
Try this: 尝试这个:
img.logo {
vertical-align: middle
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.