Skip to content Skip to sidebar Skip to footer

:target Selector Doesn't Work With Option Tags

I tried to help a fellow StackOverflow member here and I found out that the CSS :target selector doesn't work with option tags. I have created an example to illustrate using w3scho

Solution 1:

The <option> tag only must have text inside, so what happens is that browser ignore the other tags, and show only the text. You can inspect the rendered HTML and you can see what I am saying. In this case this render as:

<select><option>This doesn't work!</option><option>Selection2</option><option>Selection3</option></select>

Solution 2:

This is because option doesn't allow other elements in it.

Only solution is with Javascript i guess/

Post a Comment for ":target Selector Doesn't Work With Option Tags"