2017-08-24 47 views
0

嘿,所以我有一點難以放在一邊,部分正確定位時,屏幕變小。縮小屏幕時,會發生什麼情況會導致節落在旁邊。在這裏,筆:https://codepen.io/anon/pen/gxjbyg定位部分和一邊

下面的代碼:

#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; 
} 
+0

在{{從20px改爲2%}部分{}中將margin-right更改爲 –

回答

1

使用width:calc(86% - 20px);一個部分承擔考慮margin-right您在aside使用的是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>

+0

哇,它有效,但是您能解釋原因嗎? :D –

+0

@ BenasLengvinas保證金右邊的固定寬度使得它不包含在百分比值中,並且可以使整個百分比(除了+部分+保證金)超過100%,並且導致該部分破裂的原因 – Chiller

+0

我想通了另一種做法是(https://codepen.io/anon/pen/gxjbyg)。你會說哪種解決方案更好? –

1

Here拋開內因的導致整體寬度增加超過100%。將此減至margin-right: 15px;這將解決問題。