这种样式在边框外部呈现圆角,但是角的内部是方形的,我能让它们也变成圆角吗?
img{
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
border:white solid 8px;
}
请注意,问题仅限于图片,提供的建议仅适用于div。
这种样式在边框外部呈现圆角,但是角的内部是方形的,我能让它们也变成圆角吗?
img{
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
border:white solid 8px;
}
请注意,问题仅限于图片,提供的建议仅适用于div。
您可以使用边框大小的两倍作为border-radius值,以获得内部圆角。
-webkit-border-radius: 16px;
-moz-border-radius: 16px;
border-radius: 16px;
border:white solid 8px;
您需要设置一个 比边框宽度更大的 border-radius 值。请参考这个 jsfiddle。
-webkit-border-radius: 12px;
-moz-border-radius: 12px;
border-radius: 12px;
border:black solid 8px;
这种技术要求将图像包裹在一个 div 中,因为——我不确定为什么——在 Safari 中,伪元素似乎无法渲染 img
元素。
HTML
<div class="box"><img src="http://placehold.it/200x200/" /></div>
CSS
.box {
display:inline-block; /* Makes the wrapper flush with the image */
line-height: 0; /* Stops a gap appearing underneath image */
}
.box, .box:before {
border: 8px solid #fff;
border-radius: 16px;
position: relative;
z-index: 1;
}
.box:before {
display: block;
content: '';
position: absolute;
top: -8px;
left: -8px;
right: -8px;
bottom: -8px;
z-index: 2;
}
:before
伪元素位于图像顶部,其内部曲线边框模拟了图像的内部曲线边框。这是一个相当不错的解决方法,可以实现所需的内部曲线边框。border-width
以及:before
伪元素的top
、left
、right
和bottom
位置需要是包装器元素边框半径的一半。
http://jsfiddle.net/nvG5S/
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
border:#000 solid 4px;
你可以通过子元素的第二个边框来模拟内部边框
<style type="text/css">
body {
background:#f0f5f9;
}
.border-outside{
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
border:white solid 8px;
background-color: white;
}
.border-inside {
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
background: #7bada4;
}
</style>
<body>
<div class="border-outside">
<div class="border-inside">
content
</div>
</div>
</body>