Reputation: 83
<div id="mydiv">
<img width="190" height="190" src="http://distilleryimage0.s3.amazonaws.com/9fe1cfd2cd4311e28e5722000a9f195f_6.jpg" id="1">
<img width="190" height="190" src="http://distilleryimage0.s3.amazonaws.com/9fe1cfd2cd4311e28e5722000a9f195f_6.jpg" id="2">
<img width="190" height="190" src="http://distilleryimage0.s3.amazonaws.com/9fe1cfd2cd4311e28e5722000a9f195f_6.jpg" id="3">
<img width="190" height="190" src="http://distilleryimage0.s3.amazonaws.com/9fe1cfd2cd4311e28e5722000a9f195f_6.jpg" id="4">
<img width="190" height="190" src="http://distilleryimage0.s3.amazonaws.com/9fe1cfd2cd4311e28e5722000a9f195f_6.jpg" id="5">
<img width="190" height="190" src="http://distilleryimage0.s3.amazonaws.com/9fe1cfd2cd4311e28e5722000a9f195f_6.jpg" id="6">
</div>
<style>
div#mydiv img#1 {width:30px}
div#mydiv img#2 {width:60px}
</style>
Why styling doesn't work?
Js fiddle: http://jsfiddle.net/FqrDR/1/
Upvotes: 0
Views: 78
Reputation: 1981
You can start ID selectors with a number(To Elaborate more look at Xec's answer), but within CSS its not good practice, it needs to be escaped or begin with a letter. I recommend you change it with a name like id="img2"
in the HTML. and also use #img2
in css
Upvotes: 2
Reputation: 18024
ID's starting with a number is perfectly valid in HTML5, but unfortunately you can't select it using hash notation in css without escaping the first character, or alternatively using the attribute selector;
/* unicode 0031 == "1" */
div#mydiv img#\0031 {width:30px}
/* works, but has less specificity than hash notation */
div#mydiv img[id="2"] {width:60px}
To make your selectors simpler, i recommend you name the ID starting with an alpha character (a-z).
Upvotes: 1