Solved

HTML Inner element extending beyond outer element

Posted on 2007-11-15
3
574 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

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.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remaiā€¦
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

705 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