【问题标题】:Problems with Bootstrap Responsive ImagesBootstrap 响应式图像的问题
【发布时间】:2014-12-29 19:51:26
【问题描述】:

我必须创建一个基于 Bootstrap 3 框架的响应式网站应用程序。

使事物具有响应性的 Bootstrap 3 方法是具有 12 列的网格布局,可按比例缩小。

我知道,Bootstrap 3 首先是针对移动设备设计的,并且可以扩大规模(!!)。

问题在于,无论我如何重新编码 12 列网格系统的排列,也无论我是否定义了 min-width、min-height、max-width、max-height、width、height 等。定义固定尺寸的图像,图像要么缩小得非常小,要么放大得非常大——我的客户不喜欢这样!!

下面是我正在处理的代码。首先是 HTML 代码,然后是下面附带的 CSS 代码,它位于单独的样式表中(可以正常工作)。

非常感谢您为解决问题提供的任何帮助。

<!-- BEGIN HEADER -->
<!-- <header> -->
  <!-- BEGIN container for HEADER DIV -->
    <!-- BEGIN DIV for top header DIVs -->
    <div id="headerdivs" class="pad-section">
      <div class="container">
        <div class="row-fluid" style="height: 200px;">


          <div class="col-xs-4 text-center" style="background: blue;">
             <p class="lead"></p>
           </div>     

          <div class="col-xs-4 text-center" style="background: red;">
            <div style="position: relative;">
                <span class="logotop"><a href="index.html"><img src="images/logo.png" height="200" width="168" alt="" class="img-responsive" /></a></span>
            </div>
          </div>

          <div class="col-xs-4 text-center" style="background: blue;">
            <p class="lead"></p>
          </div>


        </div>
      </div>
    </div>
    <!-- END DIV for top header DIVs -->
  <!-- END container for HEADER DIV -->
<!-- </header> -->
<!-- END HEADER -->

.logotop {

    position:relative;
    left: 0px;
    bottom: 0px;
    color: white;
    width: 200px;
    max-width: 200px;
    min-width: 200px;
    height: 168px;
    max-height: 168px;
    min-height: 168px;
    z-index:1001;
}

【问题讨论】:

  • 你预计会发生什么?
  • 你是说这样的效果吗:bootply.com/JKwJuaHDes
  • @Danko,我希望图像仅缩放到较小的尺寸,但在分辨率较大时保持定义的尺寸。
  • @Banzay,是的,这是响应式效果 - 但是蓝色的一种颜色并不是展示图像缩放效果的最佳选择。

标签: jquery html css twitter-bootstrap responsive-design


【解决方案1】:

我猜你包含了完整且未经编辑的 Bootstrap CSS - https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css

您遇到的问题是,在 CSS 中有一个声明,以确保所有图像都设置为 100%,并使用 !important 覆盖任何其他设置。

img {
    max-width: 100%!important
}

您在仅针对 .logotop 类中包含的 CSS,并且按照 css 特异性的顺序,img 的 Bootstrap 样式将胜出。

改为将其作为您的 CSS:

.logotop img {
    //your styles here
}

【讨论】:

  • 实际上,我可以通过将此图像放置在顶部标题导航栏中的 Bootstrap "navbar-brand" 类中来解决这个问题,然后找到将这个品牌移动到页面中心的代码(这带来了更多问题),但开发/编程就是这样:解决一个问题会引发更多需要逐步解决的问题。
  • 是的,当你能解决自己的问题时总是很棒。请将您的问题标记为现在已解决。
猜你喜欢
  • 2021-02-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-08
  • 2013-07-08
  • 2017-01-12
相关资源
最近更新 更多