宽度:100%;使桌面上的图像大于原始大小

时间:2016-02-28 17:00:19

标签: html css twitter-bootstrap twitter-bootstrap-3

我连续三张图片,宽度都是323像素。

为了让我的网站快速响应我已经从width: 323px;切换到width: 100%;这适用于移动设备,但在较大的浏览器上,图片会变得比原始尺寸大,因此会拉伸和扭曲。

注意:我正在使用Bootstrap

直播链接:http://185.123.96.102/~kidsdrum/moneynest.co.uk/

CSS

.tripleimage {
    border-radius: 3px;
    border: 1px solid #021a40;
    padding: 1px;
        margin-bottom: 15px;
 width: 100%;
        -webkit-box-shadow: 5px 5px 10px #A3A3A3;
    -moz-box-shadow: 5px 5px 20px #A3A3A3;
    box-shadow: 3px 3px 10px #A3A3A3;
    }

HTML

<div class="container-fluid bg-3 text-center">    
  <h3 class="h3big">What do you need help with?</h3><br>
  <div class="row">
    <div class="col-sm-4">
         <img src="http://185.123.96.102/~kidsdrum/moneynest.co.uk/img/button-1.png" alt="button-1" class="middleimages">
         <div class="box-content">
                       <p class="alltextbig text-uppercase"><b>Living</b> paycheque to paycheque?</p>
                       <figure><img src="http://185.123.96.102/~kidsdrum/moneynest.co.uk/img/pound-coins.jpg" alt="saving money image" title="Saving money" class="tripleimage">
                       <figcaption><b>Feel like you're walking on a tightrope every day?</b> <br>Stuck in a pay cheque to pay cheque cycle, can't keep your budget in check, dont have a budget, use credit cards or have no savings? <br><br>

                       <b>Lesson 1</b> - Learn how I escaped the pay cheque to pay cheque cycle.</figcaption>

                       </figure>


<input type="submit" value="Start Class Now" name="subscribe" id="mc-embedded-subscribe" class="text-uppercase btn btn-primary btn-lg btn-middle" style="margin-top: 11%">

              </div>
              </div>
    <div class="col-sm-4 columnBorder"> 

       <img src="http://185.123.96.102/~kidsdrum/moneynest.co.uk/img/button-2.png" alt="button-1" class="middleimages">
       <div class="box-content column-border">
           <p class="alltextbig text-uppercase"><b>Saving</b> to buy a home?</p>
           <figure>
             <img src="http://185.123.96.102/~kidsdrum/moneynest.co.uk/img/saving-to-buy-a-home.jpg" alt="Buying a house" title="Saving to buy a house" class="tripleimage"><figcaption><b>Is saving for a house causing you anxiety?</b> Stressed out over a correction or rise in interest rates?<br><br>
Worried if you don't buy now house prices will continue to rise and out price you?<br><br>
             <b>Lesson 2</b> - Tips to rapidly save for your future home.
             </figcaption>
             </figure>

           <input type="submit" value="Start Class Now" name="subscribe" id="mc-embedded-subscribe" class="text-uppercase btn btn-primary btn-lg btn-middle" style="margin-top: 6%">
      </div>
      </div>
    <div class="col-sm-4"> 
       <img src="http://185.123.96.102/~kidsdrum/moneynest.co.uk/img/button-3.png" alt="button-1" class="middleimages">
       <div class="box-content">
      <p class="alltextbig text-uppercase"><b>Want</b> to make more money?</p>
      <figure>
        <img src="http://185.123.96.102/~kidsdrum/moneynest.co.uk/img/going-travelling.jpg" alt="How to make more money" title="How to make more money"  class="tripleimage">
        <figcaption><b>Want to increase your income?</b>
       <br>Want to drive a better car, go travelling or live in a better neighbourhood? Increase your income to scale up your savings and substantially improve your current lifestyle. 

        <br><br><b>Lesson 3</b> - It's not just about being frugal. How to easily increase your income without taking large risks.
        </figcaption>
        </figure>

    <input type="submit" value="Start Class Now" name="subscribe" id="mc-embedded-subscribe" class="text-uppercase btn btn-primary btn-lg btn-middle">

    </div>
    </div>
  </div>
</div>

2 个答案:

答案 0 :(得分:2)

如果您希望图像具有响应性(I.E 100%宽度)并且仍然不会超过323px宽,那么您可以使用CSS max-width属性。

.tripleimage {
    ...
    width: 100%;
    max-width: 323px;
}

答案 1 :(得分:1)

您需要使用CSS媒体查询来实现移动兼容性。首先将此元标记添加到您的html以使用媒体查询

<meta name="viewport" content="width=device-width, initial-scale=1">

现在,如果设备屏幕宽度小于400px,则可以使用以下css代码应用自定义css规则。

@media screen and (max-width: 400px) {
   .tripleimage {
       width: 100%;
   }
}