简体   繁体   English

使用bootstrap 3时如何强制图像最大宽度?

[英]How to enforce image max-width when using bootstrap 3?

Using bootstrap 3, I want an article page to show images of all sizes both responsive and not exceed the article boundaries. 使用bootstrap 3,我想要一个文章页面来显示所有大小的图像,这些图像既响应又不超过文章边界。 Here is the html: 这是html:

<div class="col-sm-8">
    <div class="article">

    <h3 class="title">{{ post.title }}</h3> <ul class="list-inline list-unstyled">
        {% if post.author %}
            <li class="author">wrote<b>
                    {{ post.author }} </b>
            </li>
        {% endif %}

        <li class="pubdate">{{ post.pub_date |date:'Y m d' }}
    </li>


    </ul>


     <div class="img-responsive headimage"> <img src="/media/{{post.headimage}}" />
     </div>

        <div class="open-sans">{{ post.body }}</div>

    </div>
</div>

and the css: 和css:

.headimage img {

    max-width: 700px;
    padding: 1em;
}

This limit the max-width however is hackish the image is not responsive. 然而,这限制了最大宽度是图像无响应的黑客。 So I'd like to know how to do it in correct way. 所以我想知道如何以正确的方式做到这一点。

To prevent the image from overflowing the column: 要防止图像溢出列:

.headimage {
  max-width: 100%;
  padding: 1em;
}

.headimage > img {
  width: 100%;
}

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

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