I want to make text work as a radio button for html, so from multiple options when i click one option (text) it get highlighted (selected) and carries value forward.

有帮助吗?

解决方案

The most straightforward way is to simply use radio buttons, which you make invisible. Then turn the texts into labels for the radio buttons.
I put each of the radio buttons and its label in a wrapper, to make positioning them easier.

<div class="radiowrapper" id="wrap1">
    <input type="radio" name="problem" value="headaches" id="problem1">
    <label for="problem1">I get headaches</label>
</div>
<div class="radiowrapper" id="wrap2">
    <input type="radio" name="problem" value="teeth" id="problem2">
    <label for="problem2">I grind my teeth</label>
</div>
<div class="radiowrapper" id="wrap3">
    <input type="radio" name="problem" value="heartburn" id="problem3">
    <label for="problem3">I experience heart burn</label>
</div>

And the css:

.radiowrapper {position:absolute;}

.radiowrapper input {visibility:hidden; width:0;}

.radiowrapper label:hover {font-weight:bold}

.radiowrapper input:checked + label {font-weight:bold; text-transform:uppercase}

#wrap1 {left:100px; top:50px;}

#wrap2 {left:80px; top:100px;}

#wrap3 {left:0px; top:150px;}

See jsFiddle.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top