2012-04-03 74 views
7

有没有一种简单的方法来设计这样的元素?CSS剪辑角落?

Example

应该是在移动中使用,以便CSS3是完全可用。想不到一个简单的方法。图像没有问题。

它必须是这个块状并有应该是内部的文本(这是一种块状的8位按钮)

+1

您是否在寻找圆角或移除这些小广场? – mikevoermans 2012-04-03 16:27:22

+0

一张照片通常胜过千言万语,但在这种情况下,您需要更多的单词来解释照片。或者你真的想要*完全*显示什么? – gilly3 2012-04-03 16:28:34

+0

是的,这是整个点。从角上的bg减去正方形。它是8位浏览器游戏的一部分。希望它是有道理的,为什么我需要这种块状外观:)而且应该有一个文本在这个元素 – Max 2012-04-03 16:29:45

回答

5

这从feeela的开始就跳了出来,但它不同于自己的答案。

  1. 而不是把一个彩色块overly,它只增加了红色的元素,允许背景显示。但是,要正确计算它(以便它们是方形的角落!)我必须设置一个固定的高度为 宽度 高度。可能有某种古怪的方式来用百分比来做到这一点,但对于概念证明来说,想想它太令人头疼。由于要求是固定高度可变宽度,所以这应该起作用。

  2. 伪元素需要内容或他们将“崩溃”。内容可以是空的,但该属性需要设置。

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; 
} 

小提琴:http://jsfiddle.net/3R9c5/2/

+0

完美!刚刚好!谢谢布罗姆! – Max 2012-04-04 11:23:34

+0

不用担心!这是一个令人愉快的挑战。 :-) – 2012-04-05 03:42:54

0

的CSS边界半径属性

+0

它可以做正方形吗? – Max 2012-04-03 16:26:29

+0

像素是一个正方形,但我认为你不是这个意思 - 所以你的回答是:不。边框半径将创建圆角边框。 – feeela 2012-04-03 16:30:47

+0

错误的答案,实际上没有看到广场! – 2012-04-03 18:21:35

0

也许this会帮助你。或者你可以添加新的类,例如“干部”

.cadre 
{ 
border-radius: 10px; 
} 

你的css文件,然后影响到div。

0

我不认为border-radius可以做到这一点。这是我能想到的最简单的方法:

http://jsfiddle.net/DpLdt/

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>​ 
2

您可以将每四个块状的通过::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 */ 
/* … */ 
+0

同意,我试图制定出相同的概念。 – mikevoermans 2012-04-03 16:35:07

+0

我喜欢这种方法的开始。棘手的部分是弄清楚如何获得第四个角落。 ;-)可能需要添加一个额外的标记来完成。 D'哦,它也似乎并没有工作:http://jsfiddle.net/3R9c5/ – 2012-04-03 16:48:56

+0

背景可以不同,我有这个页面上的渐变背景:(是的,我知道,8位和渐变像whaaaaaaa。仍然 – Max 2012-04-03 16:49:44

3

如何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;} 

编辑:最新分析上市公司问题的需求后更新。

+0

不错!必须弄清楚如何避免硬编码宽度 – Max 2012-04-03 17:08:07

+0

是的,因为使用4px的边角,外边缘必须比主矩形少8px。嗯。如果我们将多余的矩形应用到左侧和右侧而不是顶部和底部,该怎么办?这会工作吗?高度是否固定? – 2012-04-03 17:10:11

+0

差异宽度,修正高度http://imm.io/kZvh http://imm.io/kZvn – Max 2012-04-03 17:16:34