Forum Moderators: not2easy

Message Too Old, No Replies

How do I get hspace/vspace to work with zero'ed out margins?

         

smithaa02

3:35 pm on Jun 3, 2008 (gmt 0)

10+ Year Member



I'm stuck with a template that sets margins and paddings to 0px at the top of the stylesheet (set to keep things looking consistent).

Here is the code:

* {
margin: 0;
padding: 0;
}

The problem is that hspace and vspace won't work for images in firefox (the zero'ed out margin nullifies these image attributes).

Is there a way I can block inheritance just for img's?

So something like:

* {
margin: 0;
padding: 0;
}
* img {
margin: none; //which of course doesn't work
}

Any ideas on how I can get hspace and vspace working again, while retaining the zero'ing out styles?

Wlauzon

4:55 pm on Jun 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hspace and vspace are HTML, and won't do anything in a CSS stylesheet, if that is what you are trying to do.

Probably something like: img {margin: x y}

See [webmasterworld.com...]

[edited by: Wlauzon at 5:17 pm (utc) on June 3, 2008]

smithaa02

6:25 pm on Jun 3, 2008 (gmt 0)

10+ Year Member



The problem is no matter what I set my margin to for img's, it always voids any hspaces/vspaces in firefox (although not in IE).

So I could certainly set say

* img {margin-left:5px;margin-right:5px }

to emulate a hspace value, but the problem is this style would set that margin for each and every img for every page on my website. I want to be able to control the hspace for each separate tag using the hspace attribute and this works fine in firefox if I get rid of

* {
margin: 0;
padding: 0;
}

However I can't do that because other parts of my template are depending on this.

What I need is for everything to have 0 margin and 0 padding except for img's.

Is this possible?

Wlauzon

8:51 pm on Jun 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why don't you just set the image margins with CSS?

Basically some browsers override the hspace with CSS, some do not. hspace and vspace are deprecated for HTML 4+.

[edited by: Wlauzon at 8:58 pm (utc) on June 3, 2008]

smithaa02

9:17 pm on Jun 3, 2008 (gmt 0)

10+ Year Member



If I set any margin to the img tag, I can no longer use hspace (I really want to use hspace because I'm porting over a ton of content from a old website that is filled with hspace instances).

I could create a class for each image that has a different hspace, but this would be awkward because there are so many images and I would have to set the class to each and every image.

The preferable solution would be to fix something in the master stylesheet but I'm not sure how to do this. If I get rid of * {margin:0px;} this will cause my template to look all funky.

Setek

12:43 am on Jun 4, 2008 (gmt 0)

10+ Year Member



If you're adamant about letting hspace and vspace do its thing, you're going to have to remove the universal selector reset.

You'll have to do a more complicated reset, e.g.:

html, 
body,
div,
p,
h1,
h2,
h3,
h4,
h5,
h6,
address,
blockquote,
ul,
ol,
dl { margin: 0;
padding: 0; }

... that sort of thing. I think Eric Meyer has a pretty... advanced reset.css, which you could just remove the instances of

img

smithaa02

1:39 pm on Jun 4, 2008 (gmt 0)

10+ Year Member



I was afraid I would have to do something like that :(

Well it did do the trick. If anybody has a similar problem (especially with drupal templates) just replace

* {
margin: 0;
padding: 0;
}

with:

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
margin:0px;
padding:0px;
}

Thanks for the tip Setek about reset.css which looks pretty nifty for future reference: [meyerweb.com...]