2017-08-02 89 views
1

我必須創建一個導航菜單,使用HTML和CSS,而不使用JavaScript來顯示我的易趣店鋪。我想要做的是創建許多帶有許多標籤的單選按鈕,然後單擊標籤使標籤變爲粗體並顯示爲文本。單選按鈕選中更改樣式並顯示文字

上的jsfiddle

首先影響:https://jsfiddle.net/fb2yn5ts/

(點擊標籤上做出出現一個文本)

<a href="#descrizione">My Label</a> 

<div id="descrizione"> 
This is some text 
</div> 

CSS

#descrizione{ 
    display: none; 
} 

#descrizione:target{ 
    display: block; 
} 

上的jsfiddle二效:https://jsfiddle.net/cv83q9ow/

(點擊在標籤上使標籤粗體)

<div> 
    <input type="radio" id="check" class="check-with-label" /> 
    <label for="check" class="label-for-check">My Label</label> 
<div> 

CSS:

.check-with-label:checked + .label-for-check { 
    font-weight: bold; 
} 

我不能將這些影響合併成一個,你知道爲什麼,我該如何解決這個問題? 非常感謝你!

回答

0

確定傢伙,我做這個解決了這個問題:

HTML:

<input type="radio" name="navbar_menu_store" id="input_description" class="radio_item_menu"> 
<label for="input_description" class="label_item_menu">Description</label> 
<input type="radio" name="navbar_menu_store" id="input_shipping" class="radio_item_menu"> 
<label for="input_shipping" class="label_item_menu">Shipping</label> 

<div id="contentDescription"><p class="testo_scheda"> 
This is some text</p> 
</div> 

<div id="contentShipping"><p class="testo_scheda"> 
This is some other text</p> 
</div> 

CSS:

#input_description:checked ~ #contentDescription, #input_shipping:checked ~ #contentShipping { 
    display: block; 
} 

#contentDescription, #contentShipping{ 
    display: none; 
} 

.radio_item_menu:checked + .label_item_menu { 
    font-weight: bold; 
} 

前瞻:https://jsfiddle.net/LLornfn8/

非常感謝你呢!