Forum Moderators: not2easy
I have a little squiggle image that flanks the right and left of my h1 title. I need to add some padding but nothing I do seems to affect it. This what I have, (the CSS is linked to in a separate file)
<div id="textBody">
<h1><img src="/images/squid.gif" width="40" height="17"/>location<img src="/images/squid.gif" width="40" height="17"/></h1>
</div>
#textBody img {
padding: 5px;
}
I even tried applying a class to the image itself like this:
<div id="textBody">
<h1><img src="/images/squid.gif" width="40" height="17" class=”squid”/>location<img src="/images/squid.gif" width="40" height="17" class=”squid”/></h1>
</div>
img.squid {
padding: 5px;
}
This too is on a linked to style sheet.
Alas, nothing affects the image. Note, I have no other styles relating to img tags anywhere in my css.
Does anyone know what is happening?
Thanks,
Cienwen
I had a similar problem this morning and moved an inline style (padding-right) out to my stylesheet and used margin-right instead, which fixed my problem, but your issue is very different.
You could try replacing
<img src="/images/squid.gif" width="40" height="17"/> with a div and then setting it as a background-image in the CSS, where you could also set background-position. Another suggestion would be to keep your
<h1>location</h1> tidy and add the surrounding bg image divs around your h1 tag, would be better from an optimization point of view. Could be that the margin and padding of the h1 tag is interfering with the images.
If that's not the case, then it could be a problem with some other style overwriting it. Here's how I would suggest you debug it.
1. Install Firefox (if you don't already have it).
2. Get the Firebug extension for Firefox.
3. Open the page with Firefox and use Firebox to see exactly what style rules are being applied to your image and where they're coming from.
Oh and one more thing you'll hopefully love:
You can use the before and after pseudo-elements on your H1 tag to save you time. I know what you're thinking though, what about IE support?
for IE, you can use a JS fix, such as this: [dean.edwards.name...]
[edited by: Xapti at 5:55 am (utc) on April 14, 2007]
So the easiest thing was to just change the image.
Thank you all for your help.
Cienwen
...but by putting the image in the <h1> tag I can’t effect the <img> and <h1> padding separately.
Hhhmmm, it shouldn't matter whether it's in an <h1> element or not. Just to reiterate my post above... IE will only apply padding to the <img> element if you have a valid DOCTYPE, whether the <img> is in an <h1> (or <div>) or not.