简体   繁体   中英

Positioning section and aside

Heyo, so I'm having a bit of hard time making aside and section to position correctly when making the screen smaller. What happens is the section drops below the aside when shrinking the screen. Here the pen: https://codepen.io/anon/pen/gxjbyg

Here's the code:

#container {
width:90%;
margin: 0 auto;
background:pink;
height:300px;
}
aside {
width:12%;
height:100px;
background:green;
border-radius:20px;
display:inline-block;
margin-right:20px;
}
section {
width:86%;
height:100px;
background:purple;
border-radius:20px;
display:inline-block;
}

Use width:calc(86% - 20px); one the section to take on consideration the margin-right that you used on aside which is 20px;

 #container { width:90%; margin: 0 auto; background:pink; height:300px; } aside { width:12%; height:100px; background:green; border-radius:20px; display:inline-block; margin-right:20px; } section { width:calc(86% - 20px); height:100px; background:purple; border-radius:20px; display:inline-block; } 
 <div id="container"> <aside>ASIDE</aside> <section>SECTION</section> </div> 

Here margin-right: 20px; of aside inturn causes the overall width to increase above 100%. Reduce this to margin-right: 15px; which will solve the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM