473,400 Members | 2,145 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,400 software developers and data experts.

Float and padding

Hi there,

I have following CSS definitions:

div.limits { margin: 0 20px 0 20px; }

div.halfleft {
float: left;
left: 0;
width: 50%;
padding: 0 4px 0 0;
}

div.halfright {
float: right;
right: 0;
width: 50%;
padding: 0 0 0 4px;
}

..hide {
clear: both;
display: block;
visibility: hidden;
margin: 0;
padding: 0;
}

I use them this way:

<div class="limits">
<div class="halfleft">
<table ...
</table>
</div><!--/halfleft-->
<div class="halfright">
<table ...
</table>
</div><!--/halfright-->
<hr class="hide">
</div><!--/limits-->

I tried with Konqueror, Opera, Mozilla and Firefox. It works as expected
only in Opera. Everywhere else the two tables which should be side by
side with a fixed space of 8px in between are instead, the tables on the
left and on the right but the one under the other.

I tried various display properties and I found that "display: table"
works in Konqueror. Alas Mozilla and Firefox still didn't understand
what I want.

My way around was to remove the padding from "halfleft" and "halfright"
and to apply it to nested divs.

<div class="limits">
<div class="halfleft" style="padding: 0">
<div style="padding-right: 4px">
<table ...
</table>
</div>
</div><!--/halfleft-->
<div class="halfright" style="padding: 0">
<div style="padding-right: 4px">
<table ...
</table>
</div>
</div><!--/halfright-->
<hr class="hide">
</div><!--/limits-->

(That's what I call patching!) ;-)

It works everywhere but I can't help thinking "That's stupid". I use
floating divs with paddings and margins everywhere and this is the only
place where it doesn't work as it should.

The question is: Is there a way to prevent a div from adding the width
of the padding to its own defined width?

I made some tests and I discovered that the problem occurs whatever the
width of the content of the div. So I guess it's a div width problem.

Have mercy for my page that I'm about to burn... virtually. ;-)

--
==================
Remi Villatel
maxilys_@_tele2.fr
==================
Sep 22 '05 #1
2 4388
Remi Villatel <maxilys@SPAMCOP_tele2.fr> wrote:
div.halfleft {
float: left;
left: 0;
width: 50%;
padding: 0 4px 0 0;
}
The "left" box offset property only works on positioned elements. It
appears that you are new to CSS, check out the box model:
http://www.w3.org/TR/CSS21/box.html
Note that padding is added to a specified width, 50% + 4px thus ends up
larger than 50%.
I tried with Konqueror, Opera, Mozilla and Firefox. It works as expected
only in Opera. Everywhere else the two tables which should be side by
side with a fixed space of 8px in between are instead, the tables on the
left and on the right but the one under the other.


You also need to read up on the phenomena called doctype switching and
quirks vs standards mode, Google for it. Making sure that browsers run
in standard compliant mode will make Opera do the right thing as well
and display the divs beneath one another.

--
Spartanicus
Sep 22 '05 #2
Spartanicus wrote:
div.halfleft {
float: left;
left: 0;
width: 50%;
padding: 0 4px 0 0;
}
The "left" box offset property only works on positioned elements. It
appears that you are new to CSS, check out the box model:
http://www.w3.org/TR/CSS21/box.html
Thank you but I have the W3C archive on CSS as bedside book... well,
screenside book. I'm not a newbie since I can write CSS from the top of
my head. As for the "left: 0" statement, probably I wrote it when I was
a newbie but the W3C CSS validator doesn't even complain so it has
remained untouched. It has no effect, why bother? Even my sense of CSS
aesthetic isn't affected...
Note that padding is added to a specified width, 50% + 4px thus ends up
larger than 50%.


Well, I was looking for some apparently non-existant solution against
this behavior. Let's call this a misconception and I'll use my "patch"
i.e. another nested <div> without any defined width but with the padding
I'd like to apply to its parent <div>. (Grumble, stupid CSS, grumble.)

Waiting for CSS 3,

--
==================
Remi Villatel
maxilys_@_tele2.fr
==================
Sep 23 '05 #3

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

Similar topics

1
by: Robert | last post by:
I created two pages. One using CSS and the other using a table. I'd like the css version to work like the table version. The problem arises when the full image doesn't fit in the window. Click...
2
by: Dr. Richard E. Hawkins | last post by:
I've googled around, and asked everyone I know, but I still can't find any reference to anyone else having faced this particular IE bug with floats. I've put a page at...
2
by: krsgoss | last post by:
I'm trying to do a two column "form" layout based on article here: http://www.alistapart.com/stories/practicalcss/ The idea is to have a label, and a value using definition list markup. I...
9
panachepad
by: panachepad | last post by:
I arrived here from a websearch that found this thread from your archives: http://www.thescripts.com/forum/thread97805.html It helped me to understand that I am on the right track, but I still have...
3
by: cbjewelz | last post by:
hey I've been suffering from several float problems. I want a Title on the left to be aligned vertically with several links on the right. However with my code the Title is lower than the links....
2
by: pbd22 | last post by:
Hi. I am learning my way around formatting DIVs and am stuck. Can somebody tell me how to format the below so the left column is, say, 30% wide and the right column is the remainder. And, there...
27
by: GloStix | last post by:
WARNING VIDEO TAKES A WHILE TO LOAD http://screencast.com/t/BWQ6DNtsM I really don't know how to fix this other than putting another div. But I dont' exactly want to do that for every page....
4
by: smartic | last post by:
hi i'm having problem with designing css layout i'm not expert so i need any one good in css help me in this page, my problem in this page i need to make menus to be displayed in one line beside each...
2
by: comedyboy19 | last post by:
hey guys, so i am editing the header section of my website and for some reason there is an issue with the logo and header section. Whenever i float the logo to the right side of the header the...
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
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
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
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...
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.