可调整大小的图像使用Twitter Bootstrap

4

我正在尝试使用 Twitter 的框架来开发自己的网站,希望我的图片能够随着浏览器大小的缩小而调整大小。我感到很困惑,尝试了各种方法,但无法找到解决方案。以下是我的结构:

HTML

<section id="intro">
      <div class="row" id="ruby">
        <div class="span6" id="heading">
          <h1>Journey Into Ruby and Beyond</h1>
          <p>A blog about my journey into ruby, my experiences and lots of fun!</p>
        </div>

        <div class="span6" id="pic" align="right">
           <p>Akash Soti<br>RoR Developer<br>@xyz company </p>
        </div>
    </section><!--/intro-->

CSS

#ruby.row{

margin-left: 0px;
padding-right: 0px;
padding-bottom: 0px;
}

#pic{

background: url(img/Akash.png);
background-repeat: no-repeat;
height: 150px;
width: 200px;
margin-left: 200px;

}

#pic img{

max-width:100% ;
    max-height:100% ;
    display:block;

}

#pic p{
position: relative;
right: 110px;
margin-top: 90px;
margin-left: 0px;
text-align: left;
}

用于设置背景大小属性。 - Rohit Azad Malik
1
除非你真的需要使用自己的CSS,否则所有内容都在这里:http://twitter.github.com/bootstrap/components.html#thumbnails - DaveP
2个回答

9

Twitter bootstrap旨在使图像(以及布局)响应式,也就是说,您在内容中使用的图像:

<img src="path/to/images.jpg" alt="some">

而非您在CSS中使用作为背景图像的图片。


1

您必须使用

@media (max-width: 699px) {
#pic{
background: url(img/Akash.png);
background-repeat: no-repeat;
height: 100px;
width: 150px;
margin-left: 200px;
}
}

但是如果你想要响应式设计,请尽量避免使用像素,而是使用百分比。如果你的背景意味着图片(例如照片、图片),而不是背景类型的图像,请使用<img>


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接