The problem is that you have an ID that is just numbers. This is valid in HTML5 (not in previous versions where the names and IDs were stricter ), but it can bring problems in CSS where it is not for ID selectors . Hence the mistake you see.
One solution if you want to use a numeric-only ID would be to put
in front of the number in the CSS selector. Actually what we would be doing is escaping the number in ASCII (where the character 31 in hexadecimal equals number 1, 32 to 2, 33 to 3, etc.). You can read more information in this W3C page .
Then it would not be #1
but #
and it works:
#segundo {
width: 1351px;
height: 500px;
background-color: white;
margin: -10px;
margin-top: -10px;
}
#segundo h1 {}
# {
background-color: Blue;
position: relative;
top: 90px;
left: 50px;
width: 351px;
height: 50px;
}
<div id="segundo">
<h1>Prueba</h1>
<div id="1">Hola</div>
</div>
Another option would be to use a attribute selector using the ID, something like this [id="1"]
:
#segundo {
width: 1351px;
height: 500px;
background-color: white;
margin: -10px;
margin-top: -10px;
}
#segundo h1 {}
[id="1"] {
background-color: Blue;
position: relative;
top: 90px;
left: 50px;
width: 351px;
height: 50px;
}
<div id="segundo">
<h1>Prueba</h1>
<div id="1">Hola</div>
</div>
Personally I would prefer to avoid problems and consider changing the ID in the HTML. Although I understand that it is not always possible.