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.

CSS Forum


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



Reply
When do you use padding?
Old 11-13-2008, 06:42 AM When do you use padding?
Skilled Talker

Posts: 84
Location: Brussels, Belgium
Trades: 0
When do you use padding in your DIV's to get the content inside it away from the edge? Or do you just use "left: 20px;" ?


Code:
<div id="container">

<div id="left_column"></div>

<div id="right_column"></div>

<div id="footer_clears_all"></div>

</div>
I have something like this above, with following css:

Code:
div#container {
  width: 500px;
}

div#left_column {
  position: relative; float: left;
  width: 250px;
}

div#right_column {
  position: relative; float: right;
  width: 250px;
}

div#footer_clears_all {
  clear: both;
}
The problem is, when you want to do a "padding-left: 20px;" in the left_column DIV, it's not working properly in most browsers.
Or the backgrounds are moving to the right, or it's pushing the right_column DIV out of the container, etc...

Is the padding only for text? Like padding only the text of the div:

Quote:
#left_column p h1 h2 h3 {
padding-left: 20px;
}
Or do I have to use just:

Quote:
#left_column p h1 h2 h3 {
left: 20px;
}
What's the difference between the "padding-left" and the normal "left".
__________________

Please login or register to view this content. Registration is FREE
Bulevardi is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-13-2008, 06:46 AM Re: When do you use padding?
djura's Avatar
Super Talker

Posts: 135
Name: Darko Krsmanovic
Location: Belgrade
Trades: 0
You have to reduce width of those containers when you use right or left padding.
div#left_column {
position: relative; float: left;
width: 230px;
padding:0 0 0 20px;
}

div#right_column {
position: relative; float: right;
width: 230px;
padding:0 0 0 20px;
}
__________________

Please login or register to view this content. Registration is FREE
||
Please login or register to view this content. Registration is FREE
djura is offline
Reply With Quote
View Public Profile Visit djura's homepage!
 
Old 11-13-2008, 07:20 AM Re: When do you use padding?
Skilled Talker

Posts: 84
Location: Brussels, Belgium
Trades: 0
Hmm, I see. That's a possibility.

But... isn't it so that your DIVs need to stay the way they are, without padding to the DIV. And instead you add padding to the things inside the div, like an img or a paragraph,... ?

Like here in this tutorial:
http://css.maxdesign.com.au/floatuto...torial0406.htm
__________________

Please login or register to view this content. Registration is FREE
Bulevardi is offline
Reply With Quote
View Public Profile
 
Old 11-13-2008, 07:28 AM Re: When do you use padding?
djura's Avatar
Super Talker

Posts: 135
Name: Darko Krsmanovic
Location: Belgrade
Trades: 0
well I think if all elements in that container have padding left the same, why define it for all elements inside and not only for that container? It all depends from case to case what is better
__________________

Please login or register to view this content. Registration is FREE
||
Please login or register to view this content. Registration is FREE
djura is offline
Reply With Quote
View Public Profile Visit djura's homepage!
 
Old 11-13-2008, 07:37 AM Re: When do you use padding?
Skilled Talker

Posts: 84
Location: Brussels, Belgium
Trades: 0
Mmyeah.. indeed.

And what about the other "left: 20px;" attributes.

Like here at W3schools, they don't do it with padding but like this :
http://www.w3schools.com/css/tryit.a...ition_relative

I don't understand what the difference is, and why there is a difference and for what you have to use these 2.
__________________

Please login or register to view this content. Registration is FREE
Bulevardi is offline
Reply With Quote
View Public Profile
 
Old 11-13-2008, 08:19 AM Re: When do you use padding?
djura's Avatar
Super Talker

Posts: 135
Name: Darko Krsmanovic
Location: Belgrade
Trades: 0
http://www.w3schools.com/css/tryit.a...trycss_padding

I personally use padding a lot more then positioning left, right, top, and bottom.
As I said before, if all element are aligned in that container, use padding, If you want it different values for that element, use positioning especially if you want to use negative values like left:-20px, because it is not standard for padding...
__________________

Please login or register to view this content. Registration is FREE
||
Please login or register to view this content. Registration is FREE
djura is offline
Reply With Quote
View Public Profile Visit djura's homepage!
 
Old 11-13-2008, 09:13 AM Re: When do you use padding?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,371
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
padding is for when you need the content of the element to be away from the element inner edge or border.

to move elements away from each other you should be using margins.

Positioning. left | right | top | bottom is for moving the element in a direction relative to it's predecessor

margins set the distance from the outer edge of the element to the outer edge of the surrounding elements. Or in the case of margins on a child element, it will be the distance between the inner edge (plus padding) of the parent element

padding sets the distance from the inner edge of an element to the outer edge (plus margins) of any child elements.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-13-2008, 12:32 PM Re: When do you use padding?
Skilled Talker

Posts: 84
Location: Brussels, Belgium
Trades: 0
Still, the problem stays !

Well, feel free to test it.
I added margins to put the columns neat away from each other.
I put some dashed borders around it so you can see it all clearly.

If you add the padding inside the div, so your content goes away from your border or inner edge, the columns go out of the container grid or will be set underneath each other instead of next to each other.

Take this beautiful grid I made:
Code:
body {
  margin-top: 20px; margin-bottom: 40px;
  background-color: #000000;
  text-align: center;
  font-family: Arial; color: #CCCCCC; font-size: 3mm; 
}
 
div#container {
  width: 800px;
  margin: 0 auto;
  text-align: center;
  border: 1px dashed #CCCCCC;
}
 
div#header  {
  height: 170px; width: 760px;
  margin-top: 20px;
}
 
div#left_column {
  width: 370px; height: 300px;
  border: 1px dashed #CCCCCC;
  position: relative; float: left;
  margin-left: 20px; 
  display: inline;   /* fixes the IE bug for margins */
padding: 20px;
}
 
div#right_column {
  width: 370px;  height: 500px;
  border: 1px dashed #CCCCCC;
  position: relative; float: left;
  margin-left: 20px; 
padding: 20px;
}
 
div#footer_clears_all {
  clear: both;
  width: 760px;  height: 100px;
  margin: 20px 20px 20px 20px;
  border: 1px dashed #CCCCCC;
}
With this container:

Code:
<div id="container">
<div id="header">some text</div>
<div id="left_column">some text</div>
<div id="right_column">some text for example: Lorem Ipsum...</div>
<div id="footer_clears_all">imagine some possible text!</div>
</div>
The problem with this padding: it moves your columns away, your background image will be positioned out of the box, etc...

When you only put your padding to the content inside it, it works:

#left_column p h1 h2 ... { padding: 20px; }


The question is: why...
And also: why there is a possibility to position with only "left: 20px;" instead of "padding-left: 20px;".
__________________

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

Last edited by Bulevardi; 11-13-2008 at 12:42 PM..
Bulevardi is offline
Reply With Quote
View Public Profile
 
Old 11-13-2008, 06:40 PM Re: When do you use padding?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,371
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You do realise that padding:20px; equates to
padding-top:20px;
padding-bottom:20px;
padding-left:20px;
padding-right:20px;

don't you?

YOU DO NOT position elements using padding, that is NOT it's purpose!!

post a link to the page and we'll will tell you where you are going astray.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-13-2008, 07:02 PM Re: When do you use padding?
djura's Avatar
Super Talker

Posts: 135
Name: Darko Krsmanovic
Location: Belgrade
Trades: 0
Your container have width 800px and your left and rigt column together have 370px + 370px + both of them have padding left and right 20px=40px more for each layer +plus borders left and right, that is 4px so its:
370px+370px+40px+40px+4px=8204px, that is more than 800px

Chris said to you what padding:20px; means. I told you that you have to reduce widths of containers when you want to give them left or right padding and height for top or bottom padding this is also for border too. So if i would like to keep those widths and heights you posted I would do it this way:

div#left_column {
width: 338px; height: 258px;
border: 1px dashed #CCCCCC;
position: relative; float: left;
margin-left: 20px;
display: inline; /* fixes the IE bug for margins */
padding: 20px;
}

div#right_column {
width: 338px; height: 458px;
border: 1px dashed #CCCCCC;
position: relative; float: left;
margin-left: 20px;
padding: 20px;
}

What I did here is to reduce height by 20px(padding-top)+20px(padding-bottom)+1px(border-top)+1px(border-bottom)=42px reducing height for both inner layers.

Regarding widths, I reduced it with same logic but I had to reduce it more for 20px because of those left margins..
__________________

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

Last edited by djura; 11-13-2008 at 07:03 PM..
djura is offline
Reply With Quote
View Public Profile Visit djura's homepage!
 
Old 11-14-2008, 05:50 AM Re: When do you use padding?
Skilled Talker

Posts: 84
Location: Brussels, Belgium
Trades: 0
Quote:
Originally Posted by djura View Post
So if i would like to keep those widths and heights you posted I would do it this way:

div#left_column {
width: 338px; height: 258px;
border: 1px dashed #CCCCCC;
position: relative; float: left;
margin-left: 20px;
display: inline; /* fixes the IE bug for margins */
padding: 20px;
}

div#right_column {
width: 338px; height: 458px;
border: 1px dashed #CCCCCC;
position: relative; float: left;
margin-left: 20px;
padding: 20px;
}
Quote:
Originally Posted by chrishirst
post a link to the page and we'll will tell you where you are going astray.
Ok, on djura's way, I get this result:
http://www.bulevardi.be/cedric/djura.php
In IE 6.0, I get following result: the right column is pushed against the edge of the container on the right.
I don't know how it looks in FF, maybe it looks better there, but I ran out of browsers on the computer from where I'm working right now.

If I do it my own way, the right column stays neat with a neat gap between the container.
I added the following to get the content inside the columns padding away from its border:
p {
padding: 20px;
}
http://www.bulevardi.be/cedric/index.php

What I also think that's strange (for both examples): the padding doesn't look like 20px, but it even looks doubled.
__________________

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

Last edited by Bulevardi; 11-14-2008 at 06:23 AM..
Bulevardi is offline
Reply With Quote
View Public Profile
 
Old 11-14-2008, 08:38 AM Re: When do you use padding?
djura's Avatar
Super Talker

Posts: 135
Name: Darko Krsmanovic
Location: Belgrade
Trades: 0
Now when we have a link it is easier to go on.
Here is my solution now. You will notice that I have reduced width of the right container so it wont be pushed to the right border of #container. Also i have aligned text to the left for both containers so it will not look like it have padding greater than 20px. Now it looks the same in FF IE6 and IE7

div#content_left{
width: 338px; height: 258px;
border: 1px dashed #CCCCCC;
position: relative; float: left;
margin-left: 20px;
display: inline; /* fixes the IE bug for margins */
padding: 20px;
text-align:left;
}

div#content_right {
width: 318px; height: 458px;
border: 1px dashed #CCCCCC;
position: relative; float: left;
margin-left: 20px;
padding: 20px;
text-align:left;
}
__________________

Please login or register to view this content. Registration is FREE
||
Please login or register to view this content. Registration is FREE
djura is offline
Reply With Quote
View Public Profile Visit djura's homepage!
 
Old 11-14-2008, 09:45 AM Re: When do you use padding?
Skilled Talker

Posts: 84
Location: Brussels, Belgium
Trades: 0
> it works !
I edited the code http://www.bulevardi.be/cedric/djura.php

Thanks

But still, it's a lot easier when you don't have to do all the calculations of paddings, margins, width,...
Isn't it easier by just let the columns to be like they need to be and add just some paddings to the elements of the divs?

Edit: perhaps I just missed something about "the box model".
I didn't know that the padding inside a DIV-border counts extra to the width of the DIV. I thought that everything inside the DIV-border (like padding), was included in the width of the DIV.
So that's what I learned.
Thank you guys.
__________________

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

Last edited by Bulevardi; 11-14-2008 at 11:11 AM..
Bulevardi is offline
Reply With Quote
View Public Profile
 
Old 11-14-2008, 11:54 AM Re: When do you use padding?
Skilled Talker

Posts: 84
Location: Brussels, Belgium
Trades: 0
Still, for some older browsers it's not working:
http://browsershots.org/screenshots/...0dd354ee7aeeb/

That's the famous box model bug in IE.
Probably I was totally thinking in that way, because the old IE method is such more logical than the box model there is from W3C. The old IE model takes the width till the border, which is quit logical.
http://en.wikipedia.org/wiki/Interne..._box_model_bug
__________________

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

Last edited by Bulevardi; 11-14-2008 at 11:56 AM..
Bulevardi is offline
Reply With Quote
View Public Profile
 
Old 11-14-2008, 02:52 PM Re: When do you use padding?
LadynRed's Avatar
Defies a Status

Posts: 10,017
Location: Tennessee
Trades: 0
Quote:
That's the famous box model bug in IE.
I don't know why you'd even lose any sleep over such an OLD version of IE - my stats don't show a single visitor using anything below IE 6.
__________________
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 11-15-2008, 07:05 AM Re: When do you use padding?
djura's Avatar
Super Talker

Posts: 135
Name: Darko Krsmanovic
Location: Belgrade
Trades: 0
Quote:
Originally Posted by LadynRed View Post
I don't know why you'd even lose any sleep over such an OLD version of IE - my stats don't show a single visitor using anything below IE 6.
This is so true, I haven't seen more than 2 hits on my sites stats with IE below version 6, even IE6 is now at 15% and IE7 at 25%....so like LadynRed said, don't bother with it
__________________

Please login or register to view this content. Registration is FREE
||
Please login or register to view this content. Registration is FREE
djura is offline
Reply With Quote
View Public Profile Visit djura's homepage!
 
Old 11-17-2008, 04:33 PM Re: When do you use padding?
Skilled Talker

Posts: 84
Location: Brussels, Belgium
Trades: 0
-deleted-

I made a new topic for another problem (footer).
__________________

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

Last edited by Bulevardi; 11-18-2008 at 06:30 AM..
Bulevardi is offline
Reply With Quote
View Public Profile
 
Old 11-17-2008, 11:00 PM Re: When do you use padding?
Novice Talker

Posts: 6
Name: Aroldo
Trades: 0
when you use padding you have to move the x.y. to place a picture.

allways think of the width per sample
700 by -10 on left padding is 690

if that doesn't work in IE , allways use relative rule.

regards
varriastudios is offline
Reply With Quote
View Public Profile
 
Old 11-18-2008, 04:08 AM Re: When do you use padding?
Skilled Talker

Posts: 84
Location: Brussels, Belgium
Trades: 0
-deleted-
__________________

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

Last edited by Bulevardi; 11-18-2008 at 06:30 AM..
Bulevardi is offline
Reply With Quote
View Public Profile
 
Old 11-23-2008, 09:44 PM Re: When do you use padding?
SEO Specialist

Posts: 989
Trades: 0
great! but I wanna ask what is the use of padding? I'm a newbie I know its a silly question but I wanna know, I want to learn this.
__________________
best-selling brands of
Please login or register to view this content. Registration is FREE
and
Please login or register to view this content. Registration is FREE
full house is offline
Reply With Quote
View Public Profile Visit full house's homepage!
 
Reply     « Reply to When do you use padding?

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.82736 seconds with 12 queries