Solved

margin problem

Posted on 2011-02-21
6
787 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

"I want to put my photos online, but I don't want them stolen.  What settings should I use?" When You Put Photos Online First and foremost, any digital file published on the WWW can be copied, stored, modified, retransmitted, etc.  Remember Naps…
This is a how to build your own CSS3 slideshow and when I say CSS3 I mean just CSS with no javascript in sight! There a few examples online of how to do this but most just show you an example without any explanation, others make it more complicat…
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

758 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

21 Experts available now in Live!

Get 1:1 Help Now