473,769 Members | 4,470 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

<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 2968
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="IntraSiteNa vigation">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>

"Superfluou s 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
6519
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 show: function show(divbox) { divbox.style.display=''; } <div id="divbox" style="display:none" >
2
3526
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
1430
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? ---------------------------------------------------------------------------- ------------------------------------------ <form id="form1" runat="server"> <div> </div> </form>
61
9834
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 align: top, but this hasn't made a differance. http://www.paulwatt.info/test/calendar.htm Thanks guys
28
5372
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 </p>s included as well. <P>aaaaaaaaa</p><DIV>bbbbbbbbb</DIV><DIV>cccccccc<P>dddddddd</p></DIV>
2
3386
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 field(s). The popping-up seems to work just fine; it's the tearing down that's giving me grief. If I stick a onmouseout event on the same input field that caused the onmouseover/pop-up, it starts to flicker 'cos the <divis placed for esthetically...
2
9452
by: bgold12 | last post by:
Are there any non-semantic (i.e. actual) differences between the <p> tag and the <divtag?
4
3623
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 place of tr but not working to create nicely div, What can i use? all the bold text are the problem areas. <div id="light" class="white_content"> <div class="bgErrorMessage">
17
4302
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
10225
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10053
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10001
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.