Solved

margin problem

Posted on 2011-02-21
6
792 Views
Last Modified: 2012-05-11
hi
maybe i have stopped thinking but i do not get what is wrong.

i have a div id= containet
and inside that div a div class= initialbox.

when i give margin-top to the initialbox it is the container that moves. i want to move the inner div and untouch the outer div.

best regards
0
Comment
Question by:derrida
[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 11

Expert Comment

by:level9wizard
ID: 34943777
This might be a sign of the 'containet' div (you mentioned) or it's parent having invalid styles  - can you provide us some source code to look at? Below is a simple example that does exactly what you're asking for.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
  <title>example</title>
  <style type="text/css">
	div.Main{
		width:500px;

		border: 2px solid red;
	}
	#inner{
		border: 2px solid green;
		margin-top: 100px;
	}
  </style>
</head>

<body>

<div class="Main">
	<div id="inner">
		Hello World
	</div>	
</div>

</body>
</html>

Open in new window

0
 
LVL 1

Author Comment

by:derrida
ID: 34944036
hi

i made a test myself so its very clean but still does not work fine.

i attach my code.

hope you can see what i am doing wrong.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <style type="text/css">

        #container{
            width: 960px;
            height: 600px;
            background-color: wheat;
            
}

#container .initialbox{
    width: 300px;
    height: 300px;
    background-color: red;
    margin-top: 5em;
}

    </style>

  </head>
  <body>
    <div id="container">
        <div class="initialbox">this is the box</div>
    </div>
  </body>
</html>

Open in new window

0
 
LVL 15

Accepted Solution

by:
Jagadishwor Dulal earned 500 total points
ID: 34948240
Change  your page style to

 
  #container{
            width: 960px;
            height: 600px;
            background-color: wheat;
			padding:5em 0 0 0;
}

#container .initialbox{
    width: 300px;
    height: 300px;
    background-color: red;
}

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:derrida
ID: 34948929
hi

jagadishdulal obviously your code does work but it does not use the margin property, and that is my issue. i try to see WHY margin does not work.

it kills me but i cannot see why level9`s example does work and mine does not. level maybe you can explain?

best regards
0
 
LVL 6

Expert Comment

by:kmead6
ID: 34952214
I believe it's because you have the margin applied to "#container .initialbox" instead of just ".initialbox". But applying padding to the parent box, like jagadishdulal did would be the better option anyway.
0
 
LVL 1

Author Comment

by:derrida
ID: 34952395
hi its not the selector. i have tried all this. i will go with the outter div padding
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

733 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