What does .class-name mean as a CSS selector?

So, if I have a CSS class called "class-name", what does the following mean?

.class-name {
  margin: 0;
}

And why, if I had the following HTML

<div id="some-id">
    <ul>
        <li class="class-name">
    ...

there will be a selector

#some-id .class-name ul li

does not exist?

+3
source share
8 answers

The first means that you probably think it means: Any HTML element with a class class-namewill have a width of 0 width (for each side, that is, top, bottom, left and right).

The second question is a little more subtle. This selector

#some-id .class-name ul li

Applies only to lithat which is under ul, found under the element with the class class-namefound under the element with id some-id.

, HTML, :

#some-id ul li.class-name

, li .class-name . li.class-name "a li class-name", li .class-name ( ) " class-name, li".

+4

.class_name .

#some-id .class-name ul li " li, ul, " _ ", html " some-id "

+6
#some-id ul li.class-name 

- , .

#some-id .class-name ul li

# some-id

+3

class-name li , li.

:

<div id="some-id">
   <div class="class-name">
     <ul>
       <li>

.

+2

.class-name , class-name. #some-id .class-name ul li a li, ul - class-name, #some-id. , class-name, tag.class-name - , div.author-credit.

+2

ul li .class-name. HTML

#some-id ul li.class-name
+1

, , "class-name":

#some-id ul li.class-name  
+1

Just skip using the selectors in most cases. This makes reading css easier to read and use. also your programmer. Yes, you can use them to apply CSS, but what classes are for an identifier are scripts to search for elements and replace them, or other programs to extract information from them, etc.

You can really hurt things now or in the future using an identifier for CSS.

0
source

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


All Articles