473,398 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Basic question re margins and padding

Hi all,

I have a container which I want to have a consistant gap around the
edges before any content starts. The obvious way to do this is the
padding style.

However, anything with a margin then adds the margin to the already
existing padding whitespace, so for things like paragraphs which
require legitimate whitepace between them, this whitespace pushes them
away from the edges of the container.

I've setup a very simple example here:
http://www.thebunnyshed.co.uk/htmltest.htm

What is the "correct" way to do this?

1) Scrap the padding on the container, and explicitly give everything
on the edges an appropriate margin? (yuck!)

2) Fudge the margins on certain elements. For instance I could specify
only a bottom margin for <pin my example which would mean only the
bottom of the container is too far down. I could then further fudge
this somehow by using a negative padding-bottom on the container.

3) Live with it because it's "correct". ie paragraphs have a margin
therefore they SHOULD be away from the container edges. (it just
doesn't look right)

4) Insert clever CSS guru answer here.

Many thanks,
Jeremy
Jan 15 '08 #1
1 1727
Je****@thebunnyshed.co.uk wrote:
Hi all,

I have a container which I want to have a consistant gap around the
edges before any content starts. The obvious way to do this is the
padding style.

However, anything with a margin then adds the margin to the already
existing padding whitespace, so for things like paragraphs which
require legitimate whitepace between them, this whitespace pushes them
away from the edges of the container.

I've setup a very simple example here:
http://www.thebunnyshed.co.uk/htmltest.htm

What is the "correct" way to do this?

1) Scrap the padding on the container, and explicitly give everything
on the edges an appropriate margin? (yuck!)

2) Fudge the margins on certain elements. For instance I could specify
only a bottom margin for <pin my example which would mean only the
bottom of the container is too far down. I could then further fudge
this somehow by using a negative padding-bottom on the container.
That is what your should do,

..container p { margin-top: 0; }

The margin collapses anyway to 40px vertically on sibling P's as it is
supposed to. Confirm by adding background color

p, img { background-color: #eee; }

and measure and you will see on 40px not 80px between paragraphs.

example on W3c http://www.w3.org/TR/CSS21/box.html#mpb-examples

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Jan 15 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Frances Del Rio | last post by:
when I test my stuff with the validator in HomeSite it tells me the body tag no longer reads margin attributes.. does this mean now margins are to be specified only in CSS? I work for an...
7
by: Richard Lawrence | last post by:
Hi, Consider the following: #Content { margin:0px 210px 50px 200px; padding:10px; } If I use it with the following HTML:
12
by: Secret Guy | last post by:
I'm trying to understand generally how to make a grid of variously sized boxes using CSS. The first idea I had was to make a box where I can see the margin, padding, border and content edges, and...
2
by: Jeff Thies | last post by:
I have something like this: <span>a</span><span style="margin-left: 15px">b</span> It appears to me that horizontal margins are allowed for inline elements. (broken on preceding element right...
7
by: Gnolen | last post by:
Hi there! I am wondering why this div moves to a bit to the left in IE 5.5 but not in 6. I think I have tried to change everything but nothing will help. It happend when I did the display:block...
1
by: yb | last post by:
Hi, I'm looking for clarification of css 2.1 specification in section 8.3.1 "Collapsing Margins" The 6th bullet reads "If the top and bottom margins of a box are adjoining ..." I won't paste...
4
by: alternium | last post by:
Hi all, Thanks for providing this forum. I know every other poster tries to hammer the time-sensitivity point, so I'll forego that. Suffice to say, Monday is go-day. I'm having an issue getting my...
3
by: alice | last post by:
Can someone tell me how I can make it so that on this page http://s195679515.onlinehome.us/essence/index.html in Firefox, the space after the main content and the bottom boxes is only 5px? As it...
14
by: Mark Shroyer | last post by:
I just noticed an unintuitive aspect of how nested blocks are positioned under a specific set of conditions, and although this is ostensibly correct behavior (unless Firefox, Safari, and Opera are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.