Solved

HTML Inner element extending beyond outer element

Posted on 2007-11-15
3
572 Views
Last Modified: 2013-11-19
I'm having a problem where when I set a parent element to 100% and then the child element to 100% with a margin or padding, the child element will extend beyond the parent element.

I've narrowed it down that this only occurs with a certain doctype being:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">


However it works with the following doctypes:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">


If you copy the attached code snippet and add the doctypes you'll see what I'm talking about..
<table style="width:100%; border: 1px solid black">
  <tr>						
    <td> 
      <div style="width: 100%; border: red 1px solid; margin:10px;">testing the width of a portlet.
      </div>
    </td>
  </tr>		
</table>

Open in new window

0
Comment
Question by:cfans
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
rucky544 earned 250 total points
ID: 20289027
Why are you putting a div set to 100% in a <td> anyway?

Divs are automatically block elements, so just set the width to auto.
0
 
LVL 16

Assisted Solution

by:rbudj
rbudj earned 250 total points
ID: 20289082
You should reverse your margins and padding.  Add them to the Parent instead of the Child.
0
 
LVL 16

Expert Comment

by:rbudj
ID: 20289105
BTW, the difference you are seeing in the doctypes is because one is STRICT and the other is TRANSITIONAL.  Strict meaning there is no leeway for the browser to identify your mistake and adjust itself accordingly.  Transitional will allow the browser to adjust itself to overcome the mistake.  Again, make the Parent with the margins or padding.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Question about traversing a tree using jQuery 7 33
html input 8 42
Make footer stick to bottom 6 18
Effective CSS style applied to an element 5 15
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Find out what you should include to make the best professional email signature for your organization.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question