Welcome to WebmasterWorld Guest from

Forum Moderators: not2easy

Message Too Old, No Replies

Problem with CSS specificity



6:42 am on Oct 1, 2011 (gmt 0)

Hey everyone,

I am new to CSS and I am having trouble with CSS specificity.

I used the code:
img {
display: block;
margin-left: auto;
margin-right: auto;

To center all my images on my website, but I forgot that the
logo should be margin-left: 0px;

I tried to give the logo a div id and make it go to the left
but it is not working.

Can anyone help me put my logo on the left of my pages without
having to edit my entire website?

Thanks in advance.


9:05 am on Oct 1, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Hi there R8kit,

and a warm welcome to these forums. ;)

Try it like this...

<html lang="en">
<base href="http://www.pubcon.com/exhibitor/gfx/">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english">
<meta http-equiv="Content-Style-Type" content="text/css">

<title>two centered one left</title>

<style type="text/css">
img {
#logo {


<img src="website_magazine_logo.jpg" alt="">
<img src="readwriteweb_logo.jpg" alt="">
<img id="logo" src="raven_seo_logo.jpg" alt="">




9:34 pm on Oct 1, 2011 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

I've never understood this preference for id over class when the id isn't actually going to be used for something (like anchoring, or being called by a script). Isn't that that whole point of classes? Sure, it saves three bytes in the HTML, but let's not overdo it.

td {default behavior that you want your td to follow unless it gets instructions otherwise}
td.foo {instructions otherwise}
td.bar {other instructions still otherwise}

And, at that, you've only scratched the surface. If you have

table.foo td {stuff}
td.bar {other stuff, including some that's mutually exclusive with the previous stuff}

and your code has

<table class = "foo">
<td class = "bar">

the td will generally follow the rules for "table.foo td" unless you explicitly say

table.foo td.bar {take that, cascading styles!}


10:58 pm on Oct 1, 2011 (gmt 0)

Thanks for the warm welcome and for the replies. The problem has been resolved. Now I understand CSS specificity so much better.

Featured Threads

Hot Threads This Week

Hot Threads This Month