Solved

margin problem

Posted on 2011-02-21
6
788 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This article discusses four methods for overlaying images in a container on a web page
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now