[英]Creating a gradient border with the same width around each column in CSS
我需要在页面中的文本周围创建一个渐变边框,我有四列,我需要边框围绕外部和列内部并且宽度相同。
例如,我添加了一个图像:
边界需要与上面相同。
这是我在下面使用的HTML,到目前为止的问题是列连接边框的位置是向它添加边框和border-left:none;
不起作用。 我还需要知道这是否是最好的方法,以及其他方式。
<html>
<head>
<style>
.border{
padding: 15px 20px;
border-top: 20px solid #000;
border-bottom: 20px solid #FF0000;
<!--margin: 40px auto;-->
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#000), to(#FF0000));
background-image: -webkit-linear-gradient(#000, #FF0000);
background-image:
-moz-linear-gradient(#808, #FF0000),
-moz-linear-gradient(#000, #FF0000)
;
background-image:
-o-linear-gradient(#000, #FF0000),
-o-linear-gradient(#000, #FF0000)
;
background-image:
linear-gradient(#000, #FF0000),
linear-gradient(#000, #FF0000)
;
-moz-background-size:17px 100%;
background-size:20px 100%;
background-position:0 0, 100% 0;
background-repeat:no-repeat;
}
#primary {
float: left;
width: 200px;
}
#content {
float: left;
width: 200px;
}
#secondary {
float: left;
width: 250px;
}
#third {
float: left;
width: 250px;
}
</style>
</head>
<body>
<div id="primary" class="border">
<p>Column information</p>
</div>
<div id="content" class="border">
<p >Column information</p>
</div>
<div id="secondary" class="border">
<p >Column information</p>
</div>
<div id="third" class="border">
<p >Column information</p>
</div>
</body>
</html>
是否广泛支持渐变边界。 这里简单的解决方案是添加一个包含渐变的包装器div,并为每个列div提供一个背景颜色来掩盖包装器的背景。 像这样的东西:
<div class='wrapper'>
<div class='col'>...</div>
<div class='col'>...</div>
<div class='col'>...</div>
<div class='col'>...</div>
</div>
和css:
.wrapper {
float: left; /* no need to be wider then the content */
overflow: hidden; /* clearfix */
padding: 10px 10px 0 0; /* no padding left / bottom, the margin left on the cols takes care of that */
background: linear-gradient(to bottom, #ff3232 0%,#000000 100%); /* don't forget to add prefixes here */
}
.col {
width: 150px; /* just some width, any number will do */
float: left; /* make them appear as columns */
margin: 0 0 10px 10px; /* same margin as the padding on the wrapper, but only left/bottom */
background-color: #fff; /* a color to mask the gradient */
padding: 5px;
}
要查看一个实例: http : //jsfiddle.net/Pevara/6vDmH/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.