473,395 Members | 1,692 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,395 software developers and data experts.

<p> within <div>

Hey,

I am trying to learn the exact behavior of CSS and was just placing a
couple of <div>'s after each other.
Each of the <divhas a <pwithin and some text within the <p>
Now when I add a background-color to the div, the color won't fill up
the entire space I believe it should. The div only has color around the
text though it has one line space to the above element. I hope it is
clear what I mean:

#navigation {background-color:#009933;}
#web_intro { background-color:#CC9933;}

<div id="navigation"><p>Home | Gigs | Audio | Community</p></div>
<div id="web_intro"><p>Again we've had a totally insane show last
night. Check the video here or get some audio pieces here</p></div>

I am wondering why this behavior happens (at least in FF 1.5 and Safari
2.0.4) - it seems that the <poverlays the <diveven though its a
child element.
Any advice would be apprechiated.

Best regards,

Nikolai

Oct 14 '06 #1
2 2936
On 2006-10-14, Nikolai Onken <ni***********@gmail.comwrote:
Hey,

I am trying to learn the exact behavior of CSS and was just placing a
couple of <div>'s after each other.
Each of the <divhas a <pwithin and some text within the <p>
Now when I add a background-color to the div, the color won't fill up
the entire space I believe it should. The div only has color around the
text though it has one line space to the above element. I hope it is
clear what I mean:

#navigation {background-color:#009933;}
#web_intro { background-color:#CC9933;}

<div id="navigation"><p>Home | Gigs | Audio | Community</p></div>
<div id="web_intro"><p>Again we've had a totally insane show last
night. Check the video here or get some audio pieces here</p></div>

I am wondering why this behavior happens (at least in FF 1.5 and Safari
2.0.4) - it seems that the <poverlays the <diveven though its a
child element.
Any advice would be apprechiated.
The spaces you're seeing are the top and bottom margins on the <p>
element in the default stylesheet.

It's because of margin collapsing that the margins end up outside the
boxes that you've given background colours to.

The <p>s' top and bottom margins count as "adjoining" the <div>'s top
and bottom margins, since there's no border or padding in the way, and
so therefore they are combined with them.

This is explained in section 8.3.1 of the CSS 2.1 spec.

If you add "padding: 1px 0px;" to your selectors for #navigation and
#web_intro, the <p>s' margins will be enclosed inside the green and
brown areas and you'll see the effect you want (plus the extra four
pixels...)
Oct 15 '06 #2
Nikolai Onken wrote :

#navigation {background-color:#009933;}
#web_intro { background-color:#CC9933;}

<div id="navigation"><p>Home | Gigs | Audio | Community</p></div>
<div id="web_intro"><p>Again we've had a totally insane show last
night. Check the video here or get some audio pieces here</p></div>

A <divis only supposed to be used to group related elements together.
What you do just increase the DOM tree unneedlessly.

<p id="IntraSiteNavigation">Home | Gigs | Audio | Community</p>

<!-- Sometimes, also called breadcrumbs navigation-->

<p id="web_intro">Again we've had a totally insane show last
night. Check the video here or get some audio pieces here</p>

"Superfluous elements and classes
When starting out with CSS, it's common to make the mistake of using
unnecessary XHTML elements, superfluous classes, and extra <div>
elements. This doesn't necessarily mean that the code will be invalid,
but it counteracts one of the reasons of separating structure from
presentation; to get simpler, cleaner markup."

Best CSS practices
http://www.456bereastreet.com/lab/de...dards/css/#css

See also:
Web Page Development: Best Practices
Tagitis
http://developer.apple.com/internet/...estwebdev.html

Gérard
--
remove blah to email me
Oct 17 '06 #3

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

Similar topics

3
by: Jens Kristensen | last post by:
I have a problem displaying a divbox containing a html-textarea - everything works fine with "normal" characters. However, when the textarea contains special chars like <P> or ' , the box fails to...
2
by: Matthew | last post by:
Hello! What is the best NS/IE compliant way to accomplish this using the least amount of javascript code? <div id="block1"> Group 1 Code </div> <div id="block2"> Group 2 Code </div>
2
by: ad | last post by:
When we create a new aspx in VS.Net, it will insert <div> tag inside <form> tag, like below. What is the function of <div> do?...
61
by: Paul Watt | last post by:
Hi, i've placed a table within a <div> to dispay some data. All is well in FF, but in MSIE the table starts inline with the bottom of the <div> to the left. I've set the css div to vertical...
28
by: Kent Feiler | last post by:
1. Here's some html from a W3C recommendations page. <P>aaaaaaaaa<DIV>bbbbbbbbb</DIV><DIV>cccccccc<P>dddddddd</DIV> 2.Although I didn't think it would make any difference, I tried it with the...
2
by: Richard Maher | last post by:
Hi, I'm trying to use the Visibility Style attribute for a Div to effectively PopUp a lightweight window with some additional context-sensitive information, when a user mouses over a given...
2
by: bgold12 | last post by:
Are there any non-semantic (i.e. actual) differences between the <p> tag and the <divtag?
4
by: ismailc | last post by:
Good day, RamananKalirajan helped me with a great script to do a popup div. The problem i now have is that the popup div within the div does not like any table><tr><td>, so itried using <div> in...
17
by: Kaushal Elsner | last post by:
<contact_us_client_email> <message> &lt;!]&gt; </message> <header> <!]>From: support@blurbpoint.com </header> </contact_us_client_email>
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.