【发布时间】:2014-01-22 09:52:29
【问题描述】:
尊敬的 stackoverflow 用户,
我有一个包含图像的 div(由 php 在 wordpress 中生成)。此图像将根据父 div 大小为 100% 宽度和自动高度。
我想应用一个覆盖该图像顶部和底部的边框图像。这可以通过 box-sizing:border-box 来完成。所以我做到了。
但由于某种原因,边框没有覆盖图像,并且图像的高度尺寸减小了,或者父级的高度尺寸增加了。
我已经坚持了很久。无论如何,这可以只用 css 完成吗?
jsfiddle:http://jsfiddle.net/SE3Na/
HTML
<div class="box1">
<div class="box2">
<img src="http://s29.postimg.org/oj8fdc5nb/example_image.png"/>
</div>
</div>
CSS
.box1{
position:relative;
width:400px;
height:auto;
border:1px solid grey;}
.box2{
width:100%;
height:auto;}
.box2 img{
width:100%;
height:auto;
border-image:url(http://s30.postimg.org/atduh061p/border_banner_3.png) 12 12 12 12 repeat;
-webkit-border-image:url("http://s30.postimg.org/atduh061p/border_banner_3.png") 12 12 12 12 repeat;
-moz-border-image:url("http://s30.postimg.org/atduh061p/border_banner_3.png") 12 12 12 12 repeat;
border-width: 12px 0px 12px 0px;
box-sizing:border-box;
-webkit-box-sizing:border-box;}
【问题讨论】:
标签: html css border-box