根据盒子模型,内边距在内容和边框之间。您可以按以下方式设置图像样式:
.img-btn {
background: #FFF; // inner border color
padding: 2px; // inner border width
border: 2px solid #[yourgreen]; // outer border
}
即使是对于纯CSS按钮,你也不需要额外的div
来完成这个操作。以下样式适用于图像作为背景图片的情况:
.img-btn {
background: #FFF url('your.img') no-repeat;
padding: 2px;
border: 2px solid #[yourgreen];
width: [image width];
height: [image height];
background-position: center center;
}
以下是双边框的示例DEMO。
background
的颜色和图片不会冲突吗? - john<divs>
和一个 <a>
来创建按钮。您可以使用单个 <a>
完成它。对于图片和按钮,您可以使用 box-shadow
属性来创建外部边框。将 background-images
居中显示在 <img>
元素中。
演示:http://jsfiddle.net/ThinkingStiff/bNmzB/
输出:
HTML:
<a id="add" href="#">Add To Cart</a>
<img id="facebook" class="icon" />
<img id="twitter" class="icon" />
<img id="email" class="icon" />
CSS:
#add {
background-color: #9bc9c7;
border: 1px solid white;
box-shadow: 0 0 0 2px #9bc9c7;
color: white;
display: inline-block;
font: normal 13px/25px Helvetica, Arial, Sans Serif;
height: 25px;
margin-right: 6px;
text-align: center;
text-decoration: none;
text-transform: uppercase;
width: 120px;
vertical-align: top;
}
#add:hover {
background-color: #eabeb2;
box-shadow: 0 0 0 2px #eabeb2;
}
.icon {
background-color: rgb( 155, 201, 199 );
border: 1px solid white;
box-shadow: 0 0 0 2px rgb( 155, 201, 199 );
height: 25px;
margin-right: 3px;
width: 25px;
}
box-shadow
是CSS3的一部分,因此浏览器兼容性可能会成为一个问题。特别是,在IE 8及以下版本中不支持它(https://developer.mozilla.org/en/CSS/box-shadow)。 - Joe Whitebackground-position: center center;
background-size: 24px 24px;
将背景缩小一点,这样白色边框就不会与符号重叠。