【发布时间】:2013-07-05 23:35:26
【问题描述】:
不确定这是否可行,但我希望使用 Twitter Bootstrap 让图像填充跨度的整个宽度和高度。
我有一个宽度为 span4 的侧边栏,其余的 span 8 带有图像。
我尝试过使用 background:cover 类,但是它只会填充跨度的宽度,并且只有在我指定高度时才会填充高度。
HTML
<div class="container-fluid">
<div class="row-fluid col-wrap">
<div class="span4 sidebar-red col">
<h1>About</h1>
<p class="lead">The first of its kind in Toronto…</p>
<p>Workplace One offers small businesses, entrepreneurs, professionals and anyone in between, a customized and unique work environment in a shared office community.</p>
<p>Workplace One offers flexibility. With customizable offices and services, Workplace One caters to the constant evolution of a small or growing business.</p>
<p>The unique space design encourages collaboration and provides an energy that can't be found in a home office, or other professional work environment.</p>
</div><!--/span-->
<div class="span8">
<img src="img/h_ph.jpg"/>
</div><!--/span-->
</div><!--/span-->
</div><!--/row-->
提前致谢
JB
【问题讨论】:
-
你关心保持纵横比吗?好像高度是由原始图片的高度决定的,而宽度是由跨度的宽度决定的。
-
我并不关心纵横比——更多的是填充跨度的空间。
-
您说您使用了
background:cover,但您的 HTML 显示的是 IMG...您想要背景图片还是 span8 内的图片? -
我想要跨度内的图像。我已经尝试了许多背景图片的变体,而不是 img 标签,但这些都没有提供我想要的结果。
-
您最好使用背景图片,例如:
.span8 { background-image: url('img/h_ph.jpg'); background-size: cover; }
标签: css image twitter-bootstrap responsive-design