Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

HTML Forum


You are currently viewing our HTML Forum as a guest. Please register to participate.
Login



Post a Project »

Find a Professional HTML Freelancer!

Find a Freelancer to help you with your HTML projects

FREE Outsourcing eBook!

Reply
<p> vertical margins don't effect <div>?
Old 10-15-2007, 02:03 PM <p> vertical margins don't effect <div>?
Junior Talker

Posts: 2
Trades: 0
Hey Guys,

In my attempt to fully understand css something has always thrown me off. Why is it that the vertical margins of any <p>, <h1> etc element don't expand the <div> unless it has a border?

For example:
<div style="background-color:blue; margin:0px; border:1px solid black">
<div style="background-color:red; margin: 0px; ">
<h1 style="margin:50px;">Here we go</h1>
</div>
</div>

In this example the h1 margin won't push the "red" <div> up or down by 50px. Instead it will push the "blue" <div> surrounding it, up by 50px because it has the border. What is the reasoning behind this? And is there a way to make it so the "red" <div> would expand up and down without putting a border on it?

Thanks
ParadigmShift is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-15-2007, 02:17 PM Re: <p> vertical margins don't effect <div>?
l3lueMage's Avatar
Skilled Talker

Posts: 73
Location: San Jose, California
Trades: 0
Can you give a screenshot of what you mean? I'm not sure what you are saying.
l3lueMage is offline
Reply With Quote
View Public Profile
 
Old 10-15-2007, 02:22 PM Re: <p> vertical margins don't effect <div>?
LadynRed's Avatar
Defies a Status

Posts: 10,017
Location: Tennessee
Trades: 0
You need to read up on the CSS Box Model:
http://www.w3.org/TR/REC-CSS2/box.html

Then read up on inline vs. block level elements
http://www.autisticcuckoo.net/archiv...ck-vs-inline-1
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

LadynRed is offline
Reply With Quote
View Public Profile
 
Old 10-15-2007, 02:44 PM Re: <p> vertical margins don't effect <div>?
Junior Talker

Posts: 2
Trades: 0
@LadynRed:
Thanks. I'll see if I can find the answer in those resources.

@bluemage
Here's 2 different screen shots with the corresponding code. Notice which div the border is located on.

Example 1:
<div style="background-color:blue; margin:0px; border:1px solid black">
<div style="background-color:red; margin: 0px; ">
<h1 style="margin:50px;">Here we go</h1>
</div>
</div>

Screenshot 1:
http://www.fuse11.com/examples/marginborder/screen1.jpg


Example 2:
<div style="background-color:blue; margin:0px; ">
<div style="background-color:red; margin: 0px; border:1px solid black">
<h1 style="margin:50px;">Here we go</h1>
</div>
</div>
Screenshot 2:
http://www.fuse11.com/examples/marginborder/screen2.jpg
ParadigmShift is offline
Reply With Quote
View Public Profile
 
Old 10-15-2007, 03:01 PM Re: <p> vertical margins don't effect <div>?
l3lueMage's Avatar
Skilled Talker

Posts: 73
Location: San Jose, California
Trades: 0
I'd say the main reason is also the margin: 0px in the red style, you are giving no margin,although I'm not sure why it takes away the margin...when you move the border and stuff.
l3lueMage is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to <p> vertical margins don't effect <div>?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.53452 seconds with 12 queries