I am developing a wysiwyg page using javascript (without libraries), and since it has a rather specialized application, it must be executed separately, and not by default.
Oddly enough, I have come a long way, and this is quite a lot, but I have some difficulties with properly setting up the display.
I have a div that contains text and images with images located to the right so that the text flows around them.
In some places, I need images centered, so I inserted a div to contain them.
Below is an example of code that works well.
The problem arises if I have more than one div containing centered images because the identifier of these centering divs is the same.
If I change the centering dividers to a class, the images are not centered, but accept the correct float of the parent div.
Is there any way to overcome this?
Is there any real problem with multiple divs with the same id?
I am not worried about supporting any browsers other than FF.
Any advice would be greatly appreciated, thanks for reading.
Dim Tim: o)
#details { width: 698px; background-color: #FFC; } #details img { float: right; } .centreimage img { float: none; } .centreimage { float: none; text-align: center; } <div id="details"> <p>Some text here</p> <img src="10750bath.jpg" height="166" width="250"> <p>Which flows around the image on the right</p> <p>blah</p> <p>blah</p> <p>blah</p> <p>blah</p> <p>blah</p> <p>blah</p> <p>The next image should be centred</p> <div><img src="10750bath.jpg" width="250" height="166" class="centreimage"></div> <p>more text</p> <p>more text</p> </div>
Thank you all for your help.
Even when I changed CSS and HTML to be a class, the images were still not centered.
The answer was a tip from Pekka, and the reason was certainty.
Specificity rules give an identifier a higher priority than a class.
The “detail” div had an ID, but “centreimage” was a class.
I changed the CSS for the "details" to the class (of course, the markup, of course), and now it works.
I can’t believe that I spent at least 10 hours trying to figure it out, thanks to everyone for their help.
(Now you know why I am "Dim Tim"): o)