div 11 does not receive styling in css

Asked

Viewed 75 times

-1

Guys, there’s something going on with me that I don’t understand

I created several Ivs like this:

div id="nome"

img src="img/00001.jpg"

/div

to put an image at the bottom of a page, but as I want to put some variables on top of this image I put the css of it like this:

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

    z-index: 0;

    } 

the problem that when I put up the second div with same id it does not get the value of css only until the first decimo I tried almost everything.

Obs: I know this may be a silly question, but I’m just asking here because I couldn’t find the answer anywhere

2 answers

2


Instead of ID you try to use class. id can only be used once per page. Class can be used several times on the same page. in the CSS you have to trade * for . html syntax: html syntax:

<div class="nome">
  • Thanks for the personal help, I really went soft but before seeing this answer of vcs I had already changed the id to class but still the error persists.

0

As much as it might work, it shouldn’t.

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

Your code, as it is, will not be valid on W3C test. In the end, this indicates that your website will potentially behave differently depending on the browser you use. A browser can accept this normally, styling all elements with the id duplicated, while another can just style the first element.

An easy alternative is to change the id for class, in order to stay:

.nome img{ ... }

While HTML becomes HTML:

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

In addition, the use of id duplicate prevents the use of Javascript manipulation, basically.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.