2015-04-26 265 views
0

我想通過使用複選框的CSS創建產品選擇。 我的代碼是在這裏我可以選擇CSS父元素嗎?

.vfb-checkbox{ 
 
    width:180px; 
 
    height:130px; 
 
background:url('http://i304.photobucket.com/albums/nn181/Amam_Dewan/2932337756_1845773ed4_q_d_zpsea5idhnt.jpg'); 
 
} 
 
/* checkboxes */ 
 

 
.vfb-checkbox label { 
 
\t \t cursor: pointer; 
 
\t  display: block; 
 
\t  position: relative; 
 
    width:100%; 
 
    height:100%; 
 

 
\t } 
 
\t 
 
.vfb-checkbox label:before { 
 
\t  content: ""; 
 
     height:100%; 
 
     width:100%; 
 
\t  position: absolute; 
 
\t  left: 0; 
 
\t } 
 
.vfb-checkbox label:hover{ 
 
    background:rgba(0,0,0,.7) url(http://i304.photobucket.com/albums/nn181/Amam_Dewan/selected_zpsvfoaira0.png)center center no-repeat; 
 
} 
 

 
\t 
 
.vfb-checkbox input[type=checkbox] { 
 
    \t display: none; 
 
\t } 
 
\t 
 
\t 
 
    input[type=checkbox]:checked + label:before { 
 
\t  background: rgba(0,0,0,.4) url('http://i304.photobucket.com/albums/nn181/Amam_Dewan/selected_zpsvfoaira0.png') center center no-repeat; 
 
\t }
<div class="vfb-checkbox"> 
 
    
 
    <label for="check1"> 
 
    <input id="check1" type="checkbox" name="check" value="check1"> 
 
    </label> 
 

 
</div>

當我在圖片的點擊應檢查,但它不是工作。當我設置標籤標籤後跟輸入標籤時它正在工作,但我想要完全相同的html結構。

+0

令人難以置信的是,當我嘗試將這個問題的標題輸入問題頁面時,我剛剛標記的重複問題不會出現在提示問題列表中。 – BoltClock

回答

1

目前CSS中沒有父選擇器。

+0

可以使用JavaScript嗎? –

+0

這將是很容易使用jQuery執行。查看jQuery庫和文檔 http://api.jquery.com/ – Arthelon