有沒有一種簡單的方法來設計這樣的元素?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