有没有一种简单的方法来设计这样的元素?CSS剪辑角落?
应该是在移动中使用,以便CSS3是完全可用。想不到一个简单的方法。图像没有问题。
它必须是这个块状并有应该是内部的文本(这是一种块状的8位按钮)
有没有一种简单的方法来设计这样的元素?CSS剪辑角落?
应该是在移动中使用,以便CSS3是完全可用。想不到一个简单的方法。图像没有问题。
它必须是这个块状并有应该是内部的文本(这是一种块状的8位按钮)
这从feeela的开始就跳了出来,但它不同于自己的答案。
而不是把一个彩色块overly,它只增加了红色的元素,允许背景显示。但是,要正确计算它(以便它们是方形的角落!)我必须设置一个固定的高度为
宽度
高度。可能有某种古怪的方式来用百分比来做到这一点,但对于概念证明来说,想想它太令人头疼。由于要求是固定高度可变宽度,所以这应该起作用。
伪元素需要内容或他们将“崩溃”。内容可以是空的,但该属性需要设置。
CSS:
/* main button block */
.button {
display:inline-block;
background: #f00;
position: relative;
line-height: 60px;
text-align: center;
padding: 0 20px;
height: 60px;
margin-left: 0.5em;
}
/* common background color to all */
.button, .button::before, .button::after {
background-color: #f00;
}
/* shared styles to make left and right lines */
.button::before, .button::after {
content: "";
position: absolute;
height: 50px;
width: 5px;
top: 5px;
}
/* pull the left 'line' out to the left */
.button::before {
left: -5px;
}
/* pull the right 'line' out to the right */
.button::after {
right: -5px;
}
完美!刚刚好!谢谢布罗姆! – Max 2012-04-04 11:23:34
不用担心!这是一个令人愉快的挑战。 :-) – 2012-04-05 03:42:54
我不认为border-radius
可以做到这一点。这是我能想到的最简单的方法:
CSS:
body {
background:blue;
}
div#clipcorners {
width:500px;
height:200px;
background:red;
position:relative;
margin:100px auto;
}
span#a,span#b {
position:absolute;
width:10px;
height:180px;
top:10px;
background:red;
}
span#a {
left:-10px;
}
span#b {
right:-10px;
}
HTML:
<div id="clipcorners">
<span id="a">
</span>
<span id="b">
</span>
</div>
您可以将每四个块状的通过::before
或0123添加伪元素。
例如为:
.button {
background: #f00;
position: relative;
}
/* corner top left */
.button::after {
position: absolute;
top: 0; left: 0;
width: 5px; height: 5px;
background: #00f;
}
/* corner top right */
.button::after {
position: absolute;
top: 0; right: 0;
width: 5px; height: 5px;
background: #00f;
}
/* corner bottom left */
/* … */
同意,我试图制定出相同的概念。 – mikevoermans 2012-04-03 16:35:07
我喜欢这种方法的开始。棘手的部分是弄清楚如何获得第四个角落。 ;-)可能需要添加一个额外的标记来完成。 D'哦,它也似乎并没有工作:http://jsfiddle.net/3R9c5/ – 2012-04-03 16:48:56
背景可以不同,我有这个页面上的渐变背景:(是的,我知道,8位和渐变像whaaaaaaa。仍然 – Max 2012-04-03 16:49:44
如何this?
HTML:
<div class="block">(text goes here)</div>
CSS:
body {background:#1990D7;}
.block {background:#FF1200; line-height:52px; margin:8px auto; width:359px;
position:relative; text-align:center; font-weight:bold; color:yellow}
.block::before {display:inline-block; background:#FF1200; content:'';
position:absolute; top:4px; left:-4px; bottom:4px; width:4px;}
.block::after {display:inline-block; background:#FF1200; content:'';
position:absolute; top:4px; right:-4px; bottom:4px; width:4px;}
编辑:最新分析上市公司问题的需求后更新。
您是否在寻找圆角或移除这些小广场? – mikevoermans 2012-04-03 16:27:22
一张照片通常胜过千言万语,但在这种情况下,您需要更多的单词来解释照片。或者你真的想要*完全*显示什么? – gilly3 2012-04-03 16:28:34
是的,这是整个点。从角上的bg减去正方形。它是8位浏览器游戏的一部分。希望它是有道理的,为什么我需要这种块状外观:)而且应该有一个文本在这个元素 – Max 2012-04-03 16:29:45