将 .img-responsive 居中,在 .container-fluid 和 row 中,在 bootstrap 中?
Center a `.img-responsive`, in a `.container-fluid` and `row`, in bootstrap?
我不希望这里的答案对 21 世纪计算机科学的理解有多大帮助,但我很感谢社区的帮助。
我有一张图片,我正试图将其置于 bootstrap 的中心。它在 .container-fluid
、.row
和 .col-xs-6
和 .offset-xs-3
中。 <img...>
本身就是 .img-responsive
。你可以在这个代码笔上看到这个项目:http://codepen.io/NotAnAmbiTurner/pen/GrGmaq?editors=1000.
图像未居中 - 我应该能够获得随视口宽度(如 SVG)缩放且位于页面中间的图像。我似乎无法做到这一点。
我想知道这是否与我从保管箱中获取 "raw" 图像作为我的 src
的事实有关,该图像是 .jpg
,或一些组合?话又说回来,我对此一窍不通,所以也有可能只是某个地方有一个我似乎找不到的拼写错误。我浏览了 bootstrap 文档,各种 SO 问题都无济于事。我找到的唯一解决方案是从容器和行中删除 <img...>
,然后分配 ... class="centered-block" ...
。但是,除非我从根本上误解了某些东西,否则 (1) 我不应该那样做,并且 (2) 我不想一头雾水,而是想了解在任何情况下我的概念错误是什么,以供我自己学习。
PS - 完全不相关,但我的 <a ...></a>
标签似乎不可点击。如果有人对此有任何想法,那也很好。
事实证明,基本问题是 CodePen 依赖于 Bootstrap 4,而不是(正如我假设的那样)Bootstrap 3.
您正在使用 Bootstrap 3 中的 类,但加载 Bootstrap 4 中的样式表;它们不全面兼容。 img-responsive 以及 col-xs-* 类 不再存在。参见 Images and Grid Options。
注意:您的链接无效,因为它们无效 HTML 并且您还用 h3 关闭了 h2,validate 您的标记。
工作示例:
@media (max-width: 480px) {
h1 {
font-size: 5vmax;
}
h2 {
font-size: 3.5vmax;
}
h3 {
font-size: 2.5vmax;
}
li {
font-size: 2.5vmax;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="jumbotron">
<h1 class="text-primary">Dr. Clair Cameron Patterson</h1>
<h2 class="text-secondary">The man who first learned the age of the Earth, and helped save a civilization from the dangers of its use of lead.</h2>
<div class="container-fluid">
<div class="row">
<div class="col">
<img src="https://www.dropbox.com/s/91fw6aazyxzb178/image-for-codecamp-tribute-page.jpg?raw=1" alt="Cartoon Image of Clair Cameron Patterson at Congressional Hearing" class="img-fluid mx-auto d-block" style="padding:1.5vmin">
</div>
</div>
</div>
<h3>Academics</h3>
<ul>
<li>Undergraduate, Grinnell College</li>
<li>PhD, University of Chicago</li>
<li>Researcher, California Institute of Technology</li>
</ul>
<h3>Brief Timeline</h3>
<ul>
<li><strong>1956</strong>: found the earth to be 4.55 Billion years old using <a href="https://en.wikipedia.org/wiki/Lead%E2%80%93lead_dating">lead-lead dating</a> and
<a href="https://en.wikipedia.org/wiki/Canyon_Diablo_(meteorite)">a fragment of a metorite that fell in Arizona</a>. This calculation has been largely undisturbed since.</li>
<li><strong>1965</strong>: began campaign against lead in various products, especially gasoline, which at that time was emitting lead into the atmosphere.</li>
<li><strong>1978</strong>: wrote a 78-page minority opinion as part of a National Research Council (NRC) panel stating that controls on lead in various products had to start immediately, including gasoline, food containers, paint, glazes, and water distribution
systems.
</li>
<li>by the late <strong>1990s</strong>: levels of lead in Americans' blood has dropped by up to 80%. Though connections with Dr. Patterson's work are not clear, as the leading researcher in the area, and constant campaigner against the use of lead, it
is likely he was a major antecedant of this change.</li>
</ul>
</div>
我不希望这里的答案对 21 世纪计算机科学的理解有多大帮助,但我很感谢社区的帮助。
我有一张图片,我正试图将其置于 bootstrap 的中心。它在 .container-fluid
、.row
和 .col-xs-6
和 .offset-xs-3
中。 <img...>
本身就是 .img-responsive
。你可以在这个代码笔上看到这个项目:http://codepen.io/NotAnAmbiTurner/pen/GrGmaq?editors=1000.
图像未居中 - 我应该能够获得随视口宽度(如 SVG)缩放且位于页面中间的图像。我似乎无法做到这一点。
我想知道这是否与我从保管箱中获取 "raw" 图像作为我的 src
的事实有关,该图像是 .jpg
,或一些组合?话又说回来,我对此一窍不通,所以也有可能只是某个地方有一个我似乎找不到的拼写错误。我浏览了 bootstrap 文档,各种 SO 问题都无济于事。我找到的唯一解决方案是从容器和行中删除 <img...>
,然后分配 ... class="centered-block" ...
。但是,除非我从根本上误解了某些东西,否则 (1) 我不应该那样做,并且 (2) 我不想一头雾水,而是想了解在任何情况下我的概念错误是什么,以供我自己学习。
PS - 完全不相关,但我的 <a ...></a>
标签似乎不可点击。如果有人对此有任何想法,那也很好。
事实证明,基本问题是 CodePen 依赖于 Bootstrap 4,而不是(正如我假设的那样)Bootstrap 3.
您正在使用 Bootstrap 3 中的 类,但加载 Bootstrap 4 中的样式表;它们不全面兼容。 img-responsive 以及 col-xs-* 类 不再存在。参见 Images and Grid Options。
注意:您的链接无效,因为它们无效 HTML 并且您还用 h3 关闭了 h2,validate 您的标记。
工作示例:
@media (max-width: 480px) {
h1 {
font-size: 5vmax;
}
h2 {
font-size: 3.5vmax;
}
h3 {
font-size: 2.5vmax;
}
li {
font-size: 2.5vmax;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="jumbotron">
<h1 class="text-primary">Dr. Clair Cameron Patterson</h1>
<h2 class="text-secondary">The man who first learned the age of the Earth, and helped save a civilization from the dangers of its use of lead.</h2>
<div class="container-fluid">
<div class="row">
<div class="col">
<img src="https://www.dropbox.com/s/91fw6aazyxzb178/image-for-codecamp-tribute-page.jpg?raw=1" alt="Cartoon Image of Clair Cameron Patterson at Congressional Hearing" class="img-fluid mx-auto d-block" style="padding:1.5vmin">
</div>
</div>
</div>
<h3>Academics</h3>
<ul>
<li>Undergraduate, Grinnell College</li>
<li>PhD, University of Chicago</li>
<li>Researcher, California Institute of Technology</li>
</ul>
<h3>Brief Timeline</h3>
<ul>
<li><strong>1956</strong>: found the earth to be 4.55 Billion years old using <a href="https://en.wikipedia.org/wiki/Lead%E2%80%93lead_dating">lead-lead dating</a> and
<a href="https://en.wikipedia.org/wiki/Canyon_Diablo_(meteorite)">a fragment of a metorite that fell in Arizona</a>. This calculation has been largely undisturbed since.</li>
<li><strong>1965</strong>: began campaign against lead in various products, especially gasoline, which at that time was emitting lead into the atmosphere.</li>
<li><strong>1978</strong>: wrote a 78-page minority opinion as part of a National Research Council (NRC) panel stating that controls on lead in various products had to start immediately, including gasoline, food containers, paint, glazes, and water distribution
systems.
</li>
<li>by the late <strong>1990s</strong>: levels of lead in Americans' blood has dropped by up to 80%. Though connections with Dr. Patterson's work are not clear, as the leading researcher in the area, and constant campaigner against the use of lead, it
is likely he was a major antecedant of this change.</li>
</ul>
</div>