html - html5 样板中的响应式 Logo (图像替换)

标签 html responsive-design html5boilerplate image-replacement

我正在通过initializr.com 使用响应式版本的html5 样板。我的网站使用自定义 Logo ,因此我将 .ir 类添加到 h1

.ir {
    background-color: transparent;
    border: 0;
    overflow: hidden;
    *text-indent: -9999px;
}

像这样

<h1 class="title ir">h1.title</h1>

documentation

Add the .ir class to any element you are applying image-replacement to. When replacing an element's content with an image, make sure to also set a specific background-image: url(pathtoimage.png);, width, and height so that your replacement image appears.

所以我在代码中添加了这些行

.ir {
background-image: url(http://i.imgur.com/yYnyJ.jpg);
background-size: 100% auto;
width:450px;
height:450px
}

问题是具体的宽度和高度。我无法摆脱它们,但 Logo 无法以这种方式响应。有想法吗?这是 fiddle 。 http://jsfiddle.net/qeW3e/

最佳答案

我认为这是指在您的目标元素上设置宽度和高度,而不是在 .ir css 类本身中设置宽度和高度。

实际的解决方案可能在网站上看起来更像这样。

HTML

<div class="header">
<div class="logo"><h1 class="title ir">h1.title</h1></div>
<div class="navigation"><p>navigation goes here</p></div>
</div>

​CSS

    .ir {
    background-color: transparent;
    border: 0;
    overflow: hidden;
    text-indent: -9999px;

    background-image: url(http://i.imgur.com/yYnyJ.jpg);
    background-size: 100% auto;
    background-repeat: no-repeat;
    width: 100%;
    height: 100%;
}
.header {height:300px;}
.logo {width: 30%; float:left; height: 100%;}
.logo h1 {display:block;}
.navigation {float:left; width: 65%;}

​这是 fiddle 示例

http://jsfiddle.net/qeW3e/1/

关于html - html5 样板中的响应式 Logo (图像替换),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12748939/

相关文章:

html - 没有社交媒体元素的导航栏崩溃

javascript - css 属性 "display"无法正常工作

html - 样式化媒体查询,忽略/覆盖父样式

html - html5 样板演示顶部的奇怪间距

html - 使包含 img 的 div 占据全高

javascript - jquery 动态内部 html

javascript - 超时在ajax post请求中不起作用

html - 如何在 <div> 中垂直顶部对齐 <nav>?

css - 根据页面调整大小和可用空间动态调整 Div 标签中的文本大小

twitter-bootstrap - HTML5 样板和 Twitter Bootstrap