473,808 Members | 2,869 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DIV height behaviour

2 New Member
Hi,
I am a bit confused about the height behaviour of DIV elements. In particular, if I give a div a border it will include the padding of anything inside it when deciding the height. If I use no border the padding is not included in the height. This is very obvious if you color the background of the div.

Is this the correct behaviour? Can someone point me to where it is described on w3? Also any recommendations for books that really cover css well would be appreciated.

Many thanks,
Alex.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <style>
  5. .div1
  6. {
  7.   background: blue;
  8.   width: 200px;
  9. }
  10.  
  11. .div2
  12. {
  13.   background: blue;
  14.   width: 200px;
  15.   border: 1px solid black;
  16. }
  17. </style>
  18. </head>
  19. <body>
  20. <div class="div1">
  21. <p>Hello</p>
  22. </div>
  23. <div class="div2">
  24. <p>World</p>
  25. </div>
  26. </body>
  27. </html>
  28.  
Jun 14 '10 #1
3 1465
drhowarddrfine
7,435 Recognized Expert Expert
This may be what you need as well as this. In the first link, pay attention to collapsing margins. height and width have nothing to do with margin/padding and is the height/width of the content only.

The background style of the content, padding, and border areas of a box is specified by the 'background' property of the generating element. Margin backgrounds are always transparent.
"Transcendi ng CSS" is highly recommended.
Jun 14 '10 #2
alexdarlington
2 New Member
Thanks for the reply. At the moment I still find that css doesn't behave how I expect it to very often. Unfortunately there is no substitute for a good knowledge!
Jun 15 '10 #3
drhowarddrfine
7,435 Recognized Expert Expert
Make sure you are using a modern browser. Do not trust any version of IE to do anything right.
Jun 15 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
7888
by: Not4u | last post by:
Hello, I have a problem with CSS code. I want to have one menu column with a fixed width and a 100% height and the rest of the page for content. ---------------- |.|.|<--100%-->| |.M.|----------| |.E.|----------| |.N.|----------| |.U.|----------|
12
10182
by: Kepler | last post by:
How do you get the height of the client browser in IE? Both document.body.clientHeight and document.body.offsetHeight return the height of the document. If the page is long and there's a vertical scrollbar, you get the height of the entire document, screwing up any chance of centering a window in the browser using these values. Is there a way to get the height of the actual browser window and not the entire page height? Thanks.
2
16836
by: Clemens Quoss | last post by:
Hello, I just encountered a strange thing when switching the doctype on and off in the following html testpage (with IE 6.0): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
5
1910
by: S | last post by:
Whew! Thanks for your help on that last post. I actually understand what you wrote. I'm trying not to use these groups as a way to get my code written for me, I really want to understand what I'm doing wrong (and right!) so your explanations have been very helpful. I really appreciate them. My last problems involve DIV sizing and MSIE Win spacing issues. I have several DIVs on my page that need to be a minimum width and height.
1
2774
by: Dan Bass | last post by:
I'm looking to develop a listbox with in-place editing where as each item is selected, it grows to fit in all the text boxes. When the item is deselected, it shrinks back to its original size. The editing bit is not a problem, but I can't get the selected item to resize, as the listbox does for the "Add/Remove programs". The initial thought I had was to have a handler for the MeasureItem event, then have the condition of whether the...
6
5136
by: . | last post by:
I have an absolutely-positioned div with a y-repeating background inside a container div of variable height (but taller than the browser screen). I need the child div to expand to fill the entire height of the container. This currently works in Firefox with the Transitional DTD, but IE6 didn't tile at all. By adding "height:100%" to the container and to the BODY tag, IE will then expand to the screenheight, not to the actual container...
1
1730
by: astrochelonian | last post by:
Hello, all, First time I post, so I beg for everyone's patience. I am writing because I have the following doubt. in the page http://atuin.no-ip.org, you can see a blue-grey bar stretching down the length of the right side of the website. In order to achieve the effect in IE, I had to add height: 700px (or another outrageously long number), or else the coloring of the sidebar would stop when the last item within the sidebar finished...
0
2413
by: amrhi | last post by:
Hy Guys , Can anybody help me ? I try to make small web database in my unit. Some of fields have on change behaviour to get other data that automatically filled other text field. But when i try to hit "enter" after i fill text field , its automatically save data in my table database . I just want to save data after , i click "save" button. <?php include"session.php"; mb_http_input("iso-8859-1"); mb_http_output("iso-8859-1"); $tgl=$_POST;...
1
1672
by: =?ISO-8859-1?Q?Andr=E9_Wagner?= | last post by:
Hello! (please read this message using fixed-font) I'm writting a website with boxes of content. The number of cells in each row might change depending on the browser window size, and the content will be something like this: AAAAA BBBBB CCCCF AAAAA BBBBB
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10631
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
10374
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
10374
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
10114
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7651
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
6880
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();...
2
3859
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
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.