2017-08-02 88 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/

非常感谢你呢!