简体   繁体   English

Bootstrap响应图像问题

[英]Problems with Bootstrap Responsive Images

I have to create a responsive web site app based on the Bootstrap 3 framework. 我必须基于Bootstrap 3框架创建一个响应式网站应用程序。

The Bootstrap 3 way of making things responsive is to have a grid-layout of 12 columns that scale down. Bootstrap 3使事物响应的方法是采用12列的网格布局以按比例缩小。

I understand that Bootstrap 3 designs for mobile first and scales up(!!). 我了解Bootstrap 3是为移动设备而设计的,并且可以扩大规模(!!)。

The issue is that no matter how I recode the permutations of the 12-column grid system, and no matter if I define min-width, min-height, max-width, max-height, width, height, etc. of the image to define fixed dimensions, the image either scales down really small, or it scales really big - and my client does not like this!! 问题是,无论我如何重新编码12列网格系统的排列,也不管是否定义图像的最小宽度,最小高度,最大宽度,最大高度,宽度,高度等。要定义固定尺寸,图像要么缩小得很小,要么放大得很大-我的客户不喜欢这样!

Here below is code I am working on. 下面是我正在处理的代码。 First is the HTML code, and then the accompanying CSS code below that is in a separate style sheet (that works fine). 首先是HTML代码,然后是下面的随附CSS代码,它们在单独的样式表中(正常工作)。

Thank you very much for any help in solving the matter. 非常感谢您为解决此问题提供的帮助。

<!-- 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;
}

I'm going to guess that you're including the full and unedited version of the Bootstrap CSS - https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css 我猜想您包括了Bootstrap CSS的完整和未经编辑的版本-https: //maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css

The issue that you're having is that within the CSS there is a declaration to ensure that all images are set to be 100%, and with an !important to override any other settings. 您遇到的问题是CSS内有一个声明,以确保将所有图像都设置为100%,并带有!important来覆盖任何其他设置。

img {
    max-width: 100%!important
}

The CSS you have included in only targeting the .logotop class, and in order of css specificity the Bootstrap style for teh img will win out. 仅包含针对.logotop类的CSS,并且按照CSS的特定顺序, img的Bootstrap样式将胜出。

Include this as your CSS instead: 包括以下内容作为您的CSS:

.logotop img {
    //your styles here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM