Doubt in the css selector> [#id (.class1 or .class2)]

I think he should have a better way to do this ...

I use the following css selector

#book_form .ano_chegada, #book_form .ano_partida {...}

Html:

<form id="book_form">
<input class='ano_chegada' .../>
<input class='ano_partida' .../>
</form>

I really dislike repeating the form id twice. Is it strictly necessary? I know that it should work without a second id (#book_form), but it will select all elements that have the same class (.ano_partida), right?

Thanks =) (Origigado, Portuguese)

Greetings from Portugal

+3
source share
3 answers

Yes, it is strictly necessary if you want to select only those elements that live inside #book_form.

CSS , CSS, ​​.

+2

You can customize your HTML code a bit to make it easier to use CSS selectors. (This is not necessarily worth it, and may increase the size of your output.)

Add another class name to the class tags:

<form id="book_form"> 
<input class='ano_chegada something' .../> 
<input class='ano_partida something' .../> 
</form>

#book_form .something {...}

Or split what is in several classes:

<form id="book_form"> 
<input class='ano chegada' .../> 
<input class='ano partida' .../> 
</form>

#book_form .ano {...}
+2
source

Source: https://habr.com/ru/post/1767029/


All Articles