我试图将 div 保持#chat-inner
在 div 的中间#chat-main
,我可以通过使用百分比值来做到这一点,但我的问题是应该存在2px
百分比值无法提供的间隙(相对于宽度和高度)。为了清楚理解,请参阅 CSS 代码中的注释。
HTML
<div id="chat-outline">
<div id="chat-main">
<div id="chat-inner">
</div>
</div>
</div>
CSS
#chat-outline
{background-color:grey;width:30%;height:40%;
position:fixed;bottom:5px;right:5px;
padding:2px;}
#chat-main
{
width:100%;
height:100%;
background-color:silver;
overflow:hidden;
}
#chat-inner
{
width:95%;
height:97%;
/*How can I give pixels here? I need 2px value*/
margin:2.5% 2.5% 2.5% 2.5%;
/*margin:2px;*/
background-color:cornflowerblue;
}