【问题标题】:border and image responsive simultaneously边框和图像同时响应
【发布时间】:2017-06-28 07:48:26
【问题描述】:

所以我在 div 框中有一张图片。图像有 .img-responsive 但是如果我想让边框也响应,那么当我缩小屏幕尺寸时,边框和图像会按比例缩小。此外,框内的文本也应该响应收缩。如果有引导方法来做到这一点。也请告诉我。

div id="quote_box">
    <p id="quote">
        This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph.
    </p>
</div>

而css是:

#quote_box{
background-image: url('parchment.jpg');
border: solid black;
border-radius:5px;
height:400px;
width:300px;
background-size:cover;
background-repeat: no-repeat;
box-shadow:20px 20px 10px;
display: block;

}

#quote {
margin:10%;
text-align:center;
font-size: 22px;
font-weight: bold;
font-family:Georgia;
color: black;

}

【问题讨论】:

  • 你的 .img 响应在哪里?
  • 您需要这样的东西吗? jsfiddle.net/d4ftjzrt/1
  • 你在使用引导程序吗?

标签: html css twitter-bootstrap


【解决方案1】:

如果您想分配widthheight,只需从quote_box 中删除heightwidth,然后使用max-widthmax-height,如下所示。

#quote_box{
   max-width:300px;
   max-height:400px;
}

不使用 bootstrap 工作 sn-p

#quote_box {
  background-image: url('http://lorempixel.com/400/200/sports/1');
  border: solid black;
  border-radius: 5px;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center center;
  /* Add this  and remove height and width */
  box-shadow: 20px 20px 10px;
  display: block;
}

#quote {
  margin: 10%;
  text-align: center;
  font-size: 22px;
  font-weight: bold;
  font-family: Georgia;
  color: black;
}
<div id="quote_box">
  <p id="quote">
    This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph.
  </p>
</div>

使用 Bootstrap,您必须使用一些引导类,例如跟随 fiddle

fiddle link with bootstrap

【讨论】:

  • 这很好。谢谢你。只是一件事,如果缩小到一定大小,背景中的图像似乎会受到一点影响,尽管我在背景中的图像是对称精灵类型。有什么想法吗?
  • 图像与纵横比一致,所以它会发生,并且您正在使用 background-size:cover 所以图像将以其纵横比占据整个 div。
猜你喜欢
  • 1970-01-01
  • 2016-01-21
  • 2012-11-05
  • 1970-01-01
  • 1970-01-01
  • 2016-06-25
  • 2021-12-02
  • 2012-04-24
  • 1970-01-01
相关资源
最近更新 更多