2013-09-25 50 views
0

我試圖隱藏radio-button並使用:before來創建一個自定義的。隱藏單選按鈕但顯示僞元素?

這裏是我的CSS:

input[type=radio]{ 
    display: none; 
} 

input[type=radio]:before{ 
    content: ""; 
    display: inline-block; 

    width: 19px; 
    height: 19px; 
    margin-bottom: 0; 
    border: 1px solid #ddd; 
} 

我預計這將產生一個空方。問題似乎是,當我將display: none應用於我的輸入時,這也會影響:before元素。

回答

1

試試這個

<input type="radio" id="r1" name = "r1" class="rdb" style="visibility:hidden" /> 
<label for="r1">Male</label> 
<input type="radio" id="r2" name = "r2" class="rdb" style="visibility:hidden" /> 
<label for="r2">Female</label> 

Live Demo

+0

yes!ie8 + only only ... – Himmators

+0

但是,使用「visibility:hidden」會刪除表單元素的鍵盤可訪問性。 – theJBRU

0

這是預期的行爲。 :before:after應用於INSIDE元素,因此遵守相同的顯示規則。

我認爲Checkbox Hack可能是您需要的。

CSS-Tricks article

0

只要改變無線電本身是0像素寬乘高0像素:所以僞元件被示出,但是無線本身是不可見的。

input[type=radio]{ width:0; height:0;} 

http://jsbin.com/AYIGuyi/1/edit

+1

我艾克這樣的想法,但在Chrome輸出的一個小單選按鈕的最新版本。 – Himmators

+0

而且不能用不透明的方法隱藏它,因爲它也適用於僞元素:-( – guymid