Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

div refuses to go insde a div

Posted on 2010-08-30
6
Medium Priority
?
415 Views
Last Modified: 2012-05-10
I have some markup and css posted below, my problem is with the div that is taking alignment from the html body and not the div that it is in, see screen shot using firebug to illustrate.

Tks,
Owen.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
		<link rel=stylesheet type="text/css" href="static.css">

		<title>Untitled Document</title>
	</head>
	<body><div>
				
					<div class="first">
						
						<img id="img-one" height="46" width="49" src="img/buttonotwo.png" />
						
						<div id="tp-middle">O2</div>
						<div id="centre-middle">O2.ie My Account</div>
						<div id="bottom-middle">&#9733&#9733&#9733</div>
						<div id="free">FREE ></div>
						
						</div>
						
						
					
					<div class="second">second</div>
					<div class="third">third</div>
					<div class="fourth">fourth</div>
					
			</div>
	</body>
</html>

body {
  font-family:Arial;
  color:#303030;
  font-size:1.0em;
	
}


table, th, td, tr{
  border-collapse:separate;
}

table,tr,td,p,tbody{
  margin:0;
  padding:0;
}

tr,td{
  width:100%;
}

.first{
	height:64px;
	width:322px;
	background-color:#99999D;
	background-repeat:no-repeat;
	}
	
#fst-button
	{
	margin-top: 0px;
	margin-left: 0px;
	margin-bottom:0px;
	}
#img-one
	{
	margin-top: 5px;
	margin-left: 5px;
	margin-bottom: 5px;
	}	
#tp-middle
	{
	margin-top: -42px;
	margin-left:63px;
	}	
#centre-middle
	{
	margin-top:1px;
	margin-left:63px;	
	}
#bottom-middle
	{
	margin-top:-4px;
	margin-left:58px;
	}
#free
	{
	margin-top:-36px;
	margin-left:247px;
	}		
.second{
	height:64px;
	width:322px;
	background-color:#ACABA1;
	background-repeat:no-repeat;
}
.third{
	height:64px;
	width:322px;
	background-color:#99999D;
	background-repeat:no-repeat;
}
.fourth{
	height:64px;
	width:322px;
	background-color:#ACABA1;
	background-repeat:no-repeat;
}

Open in new window

ee1-css.png
0
Comment
Question by:OwenMoriarty
[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
6 Comments
 
LVL 3

Expert Comment

by:WiB
ID: 33558061
#free
      {
      margin-top:-36px; -> root of your problem
0
 

Author Comment

by:OwenMoriarty
ID: 33558125
I want the content of #free to be over on the right, it is correct where it is (relatively) now. The earlier screen shot was misleading, can you look at the attached? the div 'tp-middle' is not inside the div 'first'
Tks,
ee2-css.png
0
 
LVL 7

Accepted Solution

by:
frankky earned 1200 total points
ID: 33558184
#tp-middle
      {
      margin-top: -42px;
      margin-left:63px;
      }

Negative margin again
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 29

Assisted Solution

by:chilternPC
chilternPC earned 400 total points
ID: 33558217
if you are putting styles inside each other then you should define them that way. otherwise it will relate to the body tag
i.e.
see attahched sample from dreamweaver

you also have a <div> with no class after the <body>                  
                                                
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css"> 
<!-- 
body  {
	font: 100% Verdana, Arial, Helvetica, sans-serif;
	background: #666666;
	margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
	padding: 0;
	text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
	color: #000000;
}

/* Tips for Elastic layouts 
1. Since the elastic layouts overall sizing is based on the user's default fonts size, they are more unpredictable. Used correctly, they are also more accessible for those that need larger fonts size since the line length remains proportionate.
2. Sizing of divs in this layout are based on the 100% font size in the body element. If you decrease the text size overall by using a font-size: 80% on the body element or the #container, remember that the entire layout will downsize proportionately. You may want to increase the widths of the various divs to compensate for this.
3. If font sizing is changed in differing amounts on each div instead of on the overall design (ie: #sidebar1 is given a 70% font size and #mainContent is given an 85% font size), this will proportionately change each of the divs overall size. You may want to adjust based on your final font sizing.
*/
.twoColElsLtHdr #container { 
	width: 46em;  /* this width will create a container that will fit in an 800px browser window if text is left at browser default font sizes */
	background: #FFFFFF;
	margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
	border: 1px solid #000000;
	text-align: left; /* this overrides the text-align: center on the body element. */
} 
.twoColElsLtHdr #header { 
	background: #DDDDDD; 
	padding: 0 10px;  /* this padding matches the left alignment of the elements in the divs that appear beneath it. If an image is used in the #header instead of text, you may want to remove the padding. */
} 
.twoColElsLtHdr #header h1 {
	margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */
	padding: 10px 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */
}

/* Tips for sidebar1:
1. Be aware that if you set a font-size value on this div, the overall width of the div will be adjusted accordingly.
2. Since we are working in ems, it's best not to use padding on the sidebar itself. It will be added to the width for standards compliant browsers creating an unknown actual width. 
3. Space between the side of the div and the elements within it can be created by placing a left and right margin on those elements as seen in the ".twoColElsLtHdr #sidebar1 p" rule.
*/
.twoColElsLtHdr #sidebar1 {
	float: left; 
	width: 12em; /* since this element is floated, a width must be given */
	background: #EBEBEB; /* the background color will be displayed for the length of the content in the column, but no further */
	padding: 15px 0; /* top and bottom padding create visual space within this div */
}
.twoColElsLtHdr #sidebar1 h3, .twoColElsLtHdr #sidebar1 p {
	margin-left: 10px; /* the left and right margin should be given to every element that will be placed in the side columns */
	margin-right: 10px;
}

/* Tips for mainContent:
1. If you give this #mainContent div a font-size value different than the #sidebar1 div, the margins of the #mainContent div will be based on its font-size and the width of the #sidebar1 div will be based on its font-size. You may wish to adjust the values of these divs.
2. The space between the mainContent and sidebar1 is created with the left margin on the mainContent div.  No matter how much content the sidebar1 div contains, the column space will remain. You can remove this left margin if you want the #mainContent div's text to fill the #sidebar1 space when the content in #sidebar1 ends.
3. To avoid float drop, you may need to test to determine the approximate maximum image/element size since this layout is based on the user's font sizing combined with the values you set. However, if the user has their browser font size set lower than normal, less space will be available in the #mainContent div than you may see on testing.
4. In the Internet Explorer Conditional Comment below, the zoom property is used to give the mainContent "hasLayout." This avoids several IE-specific bugs that may occur.
*/
.twoColElsLtHdr #mainContent {
	margin: 0 1.5em 0 13em; /* the right margin can be given in ems or pixels. It creates the space down the right side of the page. */
} 
.twoColElsLtHdr #footer { 
	padding: 0 10px; /* this padding matches the left alignment of the elements in the divs that appear above it. */
	background:#DDDDDD;
} 
.twoColElsLtHdr #footer p {
	margin: 0; /* zeroing the margins of the first element in the footer will avoid the possibility of margin collapse - a space between divs */
	padding: 10px 0; /* padding on this element will create space, just as the the margin would have, without the margin collapse issue */
}

/* Miscellaneous classes for reuse */
.fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
	float: right;
	margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page */
	float: left;
	margin-right: 8px;
}
.clearfloat { /* this class should be placed on a div or break element and should be the final element before the close of a container that should fully contain a float */
	clear:both;
    height:0;
    font-size: 1px;
    line-height: 0px;
}
--> 
</style><!--[if IE]>
<style type="text/css"> 
/* place css fixes for all versions of IE in this conditional comment */
.twoColElsLtHdr #sidebar1 { padding-top: 30px; }
.twoColElsLtHdr #mainContent { zoom: 1; padding-top: 15px; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]--></head>

<body class="twoColElsLtHdr">

<div id="container">
  <div id="header">
    <h1>Header</h1>
  <!-- end #header --></div>
  <div id="sidebar1">
    <h3>sidebar1 Content</h3>
    <p>The background color on this div will only show for the length of the content. If you'd like a dividing line instead, place a border on the left side of the #mainContent div if the #mainContent div will always contain more content than the #sidebar1 div. </p>
    <p>Donec eu mi sed turpis feugiat feugiat. Integer turpis arcu, pellentesque  eget, cursus et, fermentum ut, sapien. </p>
  <!-- end #sidebar1 --></div>
  <div id="mainContent">
    <h1> Main Content </h1>
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam,  justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam  ante ac quam. Maecenas urna purus, fermentum id, molestie in, commodo  porttitor, felis. Nam blandit quam ut lacus. </p>
    <p>Quisque ornare risus quis  ligula. Phasellus tristique purus a augue condimentum adipiscing. Aenean  sagittis. Etiam leo pede, rhoncus venenatis, tristique in, vulputate at,  odio. Donec et ipsum et sapien vehicula nonummy. Suspendisse potenti. Fusce  varius urna id quam. Sed neque mi, varius eget, tincidunt nec, suscipit id,  libero. In eget purus. Vestibulum ut nisl. Donec eu mi sed turpis feugiat  feugiat. Integer turpis arcu, pellentesque eget, cursus et, fermentum ut,  sapien. Fusce metus mi, eleifend sollicitudin, molestie id, varius et, nibh.  Donec nec libero.</p>
    <h2>H2 level heading </h2>
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Praesent aliquam,  justo convallis luctus rutrum, erat nulla fermentum diam, at nonummy quam  ante ac quam. Maecenas urna purus, fermentum id, molestie in, commodo  porttitor, felis. Nam blandit quam ut lacus. Quisque ornare risus quis  ligula. Phasellus tristique purus a augue condimentum adipiscing. Aenean  sagittis. Etiam leo pede, rhoncus venenatis, tristique in, vulputate at, odio.</p>
	<!-- end #mainContent --></div>
	<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
   <div id="footer">
    <p>Footer</p>
  <!-- end #footer --></div>
<!-- end #container --></div>
</body>
</html>

Open in new window

0
 
LVL 7

Assisted Solution

by:frankky
frankky earned 1200 total points
ID: 33558281
This should do the trick:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
body {
  font-family:Arial;
  color:#303030;
  font-size:1.0em;
	
}


table, th, td, tr{
  border-collapse:separate;
}

table,tr,td,p,tbody{
  margin:0;
  padding:0;
}

tr,td{
  width:100%;
}

div .first{
	height:64px;
	width:322px;
	background-color:#99999D;
	background-repeat:no-repeat;
	}
	
div .first #fst-button
	{
	margin-top: 0px;
	margin-left: 0px;
	margin-bottom:0px;
	}
#img-one
	{
	margin-top: 5px;
	margin-left: 5px;
	margin-bottom: 5px;
	}	
.first #tp-middle
	{
	margin-top: -42px;
	margin-left:63px;
	}	
.first #centre-middle
	{
	margin-top:1px;
	margin-left:63px;	
	}
.first #bottom-middle
	{
	margin-top:-4px;
	margin-left:58px;
	}
.first #free
	{
	margin-top:-36px;
	margin-left:247px;
	}		
.second{
	height:64px;
	width:322px;
	background-color:#ACABA1;
	background-repeat:no-repeat;
}
.third{
	height:64px;
	width:322px;
	background-color:#99999D;
	background-repeat:no-repeat;
}
.fourth{
	height:64px;
	width:322px;
	background-color:#ACABA1;
	background-repeat:no-repeat;
}
</style>

		<title>Untitled Document</title>
	</head>
	<body>
<div>
				
					<div class="first">
						
						<img id="img-one" height="46" width="49" src="img/buttonotwo.png" alt="no img" />
						
						<div id="tp-middle">O2</div>
						<div id="centre-middle">O2.ie My Account</div>
						<div id="bottom-middle">***</div>
						<div id="free">FREE ></div>
						
						</div>
						
						
					
					<div class="second">second</div>
					<div class="third">third</div>
					<div class="fourth">fourth</div>
					
			</div>
	</body>
</html>

Open in new window

0
 
LVL 3

Assisted Solution

by:WiB
WiB earned 400 total points
ID: 33566660
.first{
      height:64px; ->increase height
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
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).

618 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