Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am planning to place a div inside another div with padding . but i face some problem top position remains same. how can i solve this issue

<style type="text/css">
#outdiv
{
    margin: 20px auto 20px auto;
    width: 1100px;
    height: 630px;
    max-height: 100%;
    background: #1C4675;
    font-size: 14px;
    -webkit-border-radius: 15px;
    -moz-border-radius: 15px;
    border-radius: 15px;
    position:relative;
}

#outdiv_inner
{   
    margin: 10px 5px 10px 5px;
    width: 1090px;
    height: 620px;
   
    background: #E8E8E8;
    font-size: 14px;
    -webkit-border-radius: 15px;
    -moz-border-radius: 15px;
    border-radius: 15px;
}

</style>



<div id="outdiv">
    <div id="outdiv_inner"></div>
</div>
Posted

Just add below css in #outdiv_inner

CSS
position: absolute;


and change the width of #outdiv_inner to 610px;

Modified CSS Will be like

CSS
#outdiv_inner
{   
    margin: 10px 5px 10px 5px;
    width: 1090px;
    height: 610px;   
    background: #E8E8E8;
    font-size: 14px;
    -webkit-border-radius: 15px;
    -moz-border-radius: 15px;
    border-radius: 15px;
	position: absolute;
}
 
Share this answer
 
Comments
SteveyJDay 19-Sep-14 14:32pm    
This is a very fragile approach. It will require you to change multiple width values if you want to change size of the outer div.
Shemeemsha (ഷെമീംഷ) 19-Sep-14 23:47pm    
Yes..Yes..I know.. But based on requirement we can use..In some cases % approach is not good..At that time we can use this..
You need to remove the position. That should only be used if you are trying to move content without respect to its container.

The big change was the padding on the outer div. Then you just need the inner div to fill it with width: 100% and height:100%

Try this.
CSS
<style type="text/css">
    #outdiv
    {
        margin: 20px auto 20px auto;
        padding: 15px;
        width: 1100px;
        height: 630px;
        background: #1C4675;
        font-size: 14px;
        -webkit-border-radius: 15px;
        -moz-border-radius: 15px;
        border-radius: 15px;
    }
 
    #outdiv_inner
    {
        width: 100%;
        height: 100%;
        background: #E8E8E8;
        font-size: 14px;
        -webkit-border-radius: 15px;
        -moz-border-radius: 15px;
        border-radius: 15px;
    }
</style>


HTML
<div id="outdiv">
    <div id="outdiv_inner"></div>
</div>
 
Share this answer
 
Comments
jinesh sam 19-Sep-14 15:36pm    
thanks dear.. its works fine as i expected..
Even though you already got the solution, I'll suggest another one.

You already said the key work in your question: "padding". So, use the property "padding" ("padding-top", "padding-left" and so on...), not only "margin". It is designed specially for such cases. For understanding, please learn the box model:
http://www.w3.org/TR/CSS2/box.html[^].

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900