在一个`.container-fluid`和`row`中,在一个bootstap中居中一个`.img-responsive`?

时间:2017-02-05 21:34:40

标签: css twitter-bootstrap-3 centering twitter-bootstrap-4 col

我不希望这里的答案为21世纪对计算机科学的理解增添了很多,但我很感谢社区的帮助。

我有一张图片,我试图以bootstap为中心。它位于.container-fluid.row.col-xs-6 .offset-xs-3之内。 <img...>本身就是.img-responsive。您可以在此codepen上看到该项目:http://codepen.io/NotAnAmbiTurner/pen/GrGmaq?editors=1000

图像不居中 - 我应该能够获得一个与视口宽度(一个SVG)一起缩放的图像,并且位于页面的中间。我无法理解这一点。

我想知道这是否与我采取&#34; raw&#34;这一事实有关。来自Dropbox的图片作为我的src,图片是.jpg,还是某种组合?再说一遍,我是一个菜鸟,所以同样可能的是,我似乎无法找到一个错字。我已经过了自助文档,各种SO问题无济于事。我找到的唯一解决方案是从容器和行中删除<img...>,然后分配... class="centered-block" ...。但是,除非我从根本上误解了某些东西,否则,(1)我不应该这样做,而且(2)而不是抨击我想要了解我的概念错误在任何情况下都是如此,为了我自己的学习。

PS - 完全不相关,但我的<a ...></a>标签似乎无法点击。如果有人有任何想法,那也会很棒。

事实证明,基本问题是CodePen依赖于Bootstrap 4,而不是(正如我所假设的)Bootstrap 3

1 个答案:

答案 0 :(得分:1)

您正在使用Bootstrap 3中的类,但是从Bootstrap 4加载样式表;它们并不是全面兼容的。 img-responsive不再存在以及col-xs- *类。请参阅ImagesGrid Options

注意:您的链接无法正常运行,因为它们不是有效的HTML,您还可以使用h3,validate标记关闭h2。

工作示例:

&#13;
&#13;
@media (max-width: 480px) {
  h1 {
    font-size: 5vmax;
  }
  h2 {
    font-size: 3.5vmax;
  }
  h3 {
    font-size: 2.5vmax;
  }
  li {
    font-size: 2.5vmax;
  }
}
&#13;
<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>
&#13;
&#13;
&#13;