Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top