我已经建立了一个有趣的小网站,熟悉bootstrap。
我的问题是,无论我怎么尝试,徽标图像都没有响应。
代码看起来非常简单,我相信我只是遗漏了一个小细节:
<div id="masthead">
<div class="container">
<div class="row">
<div class="col-md-7 header-logo">
<div class="header-logo" style="color: white;">
<img src="/img/gros_buck_175.png" class="img-responsive" align="left" style="padding-right: 1.5em;padding-top: 0px; max-width: 184px;">
<br>
TEL: 450 955-3422 <br>
182 CHEMIN D'ADAMSVILLE <br>
J2L 2Y6, BROMONT<br>
laboucheriedugrosbuck@gmail.com
<br clear="all">
</div>
</div>
<div class="col-md-5">
<div class="well well-lg">
<div class="row">
<div class="col-sm-12">
<img src="/img/sceau_140.png" class="img-responsive" align="left" style="padding-right: 1.2em;">
<h3 style="margin-top:0px; margin-bottom: 1em;">PROMO</h3>
FAITES VOTRE PLAN DE VIANDE:<br>
ACHETEZ POUR PLUS DE 100$ DE PRODUITS
À L'UNITÉ ET RECEVEZ 10% EN SAUCISSES.
</div>
</div>
</div>
</div>
</div>
</div><!--/container-->
</div><!--/masthead-->(这里是重现这个问题的小提琴)- https://jsfiddle.net/JoshC/2XgDW/2/
发布于 2015-04-30 09:22:46
首先从图像标记中删除max-width: 184px属性
<img src="/img/gros_buck_175.png"
class="img-responsive"
align="left"
style="padding-right: 1.5em;padding-top: 0px;">尽管最好避免使用内联样式:
<img src="/img/gros_buck_175.png" class="img-responsive" id="myLogo" align="left">#myLogo {
padding-right: 1.5em;
padding-top: 0px;
}如果有一个祖先元素的样式可能受到干扰,您可以像这样重置它:
#myLogo {
all: initial!important;
width: 100%!important;
height: auto!important;
}如果您仍然面临这个问题,那么下一步就是使用JavaScript
Object.assign(document.getElementById('myLogo').style, {
all: 'initial',
width: '100%',
height: 'auto'
});这段代码应该包含在文档中的元素之后,否则它将无法找到指定的元素,因为它还不存在。
现在您已经将示例添加到您的问题中,您可以通过替换以下CSS使图像采用其自然大小:
img {
display:table-cell;
width:100%;
height:auto;
}使用此CSS:
img {
display:inline-block;
}(Demo)
我认为您对display: table的使用正在干扰您的设计。下面是实现相同布局的两种方法。
CSS3方法
所有相关的现代浏览器都支持这种方法,所以如果你不关心与旧浏览器的向后兼容性,你可以使用这种方法。
(Demo)
<div class="inline-wrap">
<img src="http://placehold.it/150x150" />
<div class="text-wrap">Lorem Ipsum is simply dummy text Lorem Ipsum is simply dummy text Lorem Ipsum is simply dummy text</div>
</div>*,*:before,*:after {
box-sizing: border-box;
}
.inline-wrap {
white-space: nowrap;
font-size: 0;
height: 150px;
}
.inline-wrap img {
width: 150px;
}
.inline-wrap .text-wrap {
white-space: initial;
font-size: initial;
display: inline-block;
height: 100%;
width: 65%; /* Fallback */
width: calc(100% - 150px);
}表方法
为了向后兼容,您可以使用此方法。
(Demo)
<table>
<tr>
<td class="img-wrap">
<img src="http://placehold.it/150x150" />
</td>
<td class="text-wrap">Lorem Ipsum is simply dummy text Lorem Ipsum is simply dummy text Lorem Ipsum is simply dummy text</td>
</tr>
</table>*, *:before, *:after {
box-sizing: border-box;
}
table, tr, td {
border: 0;
padding: 0;
margin: 0;
border-collapse: collapse;
}
table {
width:100%;
}
table .img-wrap {
font-size: 0;
}
table .text-wrap {
width: 100%;
height: 100%;
}发布于 2015-04-30 12:24:54
尝试将max-width更改为width: 100%,这应该会告诉它占据容器宽度的100%,但随着容器宽度的更改,图像的大小也会改变,同时始终保持100%的宽度覆盖。
这应该可以工作,如果它不让我知道,我会破解它一点。我只是在用我的手机,所以我真的不想用触摸屏键盘把它放在沙盒里。如果这不起作用,我明天下午会在我的电脑上解决这个问题:D!
Ps。有没有理由在一个div中声明类.header-logo,然后在下一个div中给它同样的类。我知道如果它是一个不同的div块,但这本质上是一个标题徽标内的标题徽标。
https://stackoverflow.com/questions/29957365
复制相似问题