2012-04-03 73 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