我会这样做。您需要为周围的 div 提供背景图像的尺寸:
HTML
<div class="background">
<img class="logo" src="http://placehold.it/150x75/FF0000/FFF&text=Logo" alt="Company Name" />
</div>
CSS
.background
{
position:relative; /*Any child elements can now be positioned relative to this element*/
background-image:url(http://placehold.it/750x150&text=background);
background-repeat:no-repeat;
width:700px; /*Width of background image*/
height:150px; /*Height of background image*/
}
示例:http://jsfiddle.net/8RC7U/
您可以通过多种不同的方式定位徽标:
边距
.logo
{
margin-top: 10px;
margin-left: 10px;
}
http://jsfiddle.net/8RC7U/1/
绝对定位
.logo
{
position:absolute;
top: 15px;
right:30px;
}
http://jsfiddle.net/8RC7U/2/
这只是初学者。
最后一点,以下内容可能更适合屏幕阅读器,更适合 SEO:
HTML - 以文本形式包含公司名称
<div class="background">
<h2 class="logo">Company Name</h2>
</div>
CSS - 将文本移出屏幕并再次使用背景图片
.background
{
position:relative;
background-image:url(http://placehold.it/750x150&text=background);
background-repeat:no-repeat;
width:700px;
height:150px;
}
.logo
{
text-indent:-9999px; /*Shift the text off screen*/
width:150px; /*Width Of logo*/
height:75px; /*Height of logo*/
background-image:url(http://placehold.it/150x75/FF0000/FFF&text=Logo);
margin: 10px 0 0 10px; /*Positioning top right bottom left*/
display:inline-block; /*Set to inline block so margins apply inside parent*/
}
示例:http://jsfiddle.net/8RC7U/3/