div 11 does not get stylized in css [closed]

-1

People are doing something to me that I do not understand

I created several divs like this:

div id="nome"

img src="img/00001.jpg"

/div

To put an image in the background of a page, but as I want to put some variables on top of that image I put her css like this:

#nome img{
    width:1100px;
    margin-top:0;
    margin-left:0;
    height:730px;

    z-index: 0;

    } 

The problem is that when I put the tenth div with the same id, it does not receive the value of the css until the first eleven has already tried almost everything.

I know it might be a silly question, but I'm just asking here because I did not find the answer anywhere.

    
asked by anonymous 25.01.2017 / 21:44

2 answers

2

Instead of ID it tries to use class. the id can only be used once per page. The class can be used multiple times on the same page. in CSS you will have to change * by. non-html syntax: no html syntax:

<div class="nome">
    
25.01.2017 / 22:05
0
  

However this might work, this should not work.

id is meant to be unique, only one element should have a single id , duplicate them is a mistake .

Your code, as it stands, will not be valid in the W3C test . In the end, this indicates that your website will potentially have different behaviors depending on which browser the user uses. A browser can accept this normally by styling all elements with id duplicated, while another can only stylize the first element.

An easy alternative is to change id to class so that it stays:

.nome img{ ... }

As HTML becomes:

<div class="nome"> ... </div>

Furthermore, the use of id duplicates prevents the use of manipulation by Javascript, basically.

    
25.01.2017 / 22:25