Differences Between CSS Selectors

I don’t know if this question has been asked before or not, but right now I am writing some CSS styles like this

[myclass]{
/*some styles*/
}

HTML

<div myclass></div>

but I know that many people write like this.

.myclass{
    /*some styles*/
    }

HTML

<div class="myclass"></div>

Who cares? Maybe some browsers support or not? or what about mobile phones do they support it? Is this a legal css script style?

+4
source share
2 answers

The selector [myclass]in the first example is not for classes, but rather for other HTML attributes. See attribute selectors for more information .

+5
source

, , , , , , HTML ( ). , , , . HTML.

, "" elt.classList.add $(elt).addClass , elt.className getElementsbyClassName. " " . elt.removeAttribute, , elt.setAttribute, , querySelectorAll('[myClass]') ..

+1

All Articles