简体   繁体   English

CSS / HTML-无法将DIV放置在右侧

[英]CSS / HTML - Unable to place DIV to the right side

On our website, we have a container, with a DIV box inside which leaves a space along the right hand side so we can add some more boxes with images / text. 在我们的网站上,我们有一个容器,其中有一个DIV框,该框沿右侧留有空间,因此我们可以添加一些带有图像/文本的框。

I got as close as the boxes to the right hand side but underneath the "main" div. 我和盒子一样靠近右侧,但在“主” div的下面。

http://jsfiddle.net/Ug5pz/2/ http://jsfiddle.net/Ug5pz/2/

Thanks! 谢谢!

CSS: CSS:

#container {
    position: relative;
    width: 600px;
    height: 400px;
    margin: 0 auto 0;
    background: #FFF;
    border-style:solid;
    border-width:2px;
}
#main {
    position:relative;
    width: 450px;
    height: 300px;
    border-style:solid;
    border-width:2px;
}
#sidebox {
    position:relative;
    width:120px;
    height:50px;
    float:right;
    border-style:solid;
    border-width:2px;
}

HTML: HTML:

<div id="container">
    <div id="main">Welcome to our website!</div>
    <div id="sidebox">Sidebox</div>
</div>

Try adding float:Left to the #main CSS 尝试将float:Left添加到#main CSS

Alternatively you could modify the #sidebox CSS as follows: 或者,您可以按以下方式修改#sidebox CSS:

position:absolute;
right:0px;
top:0px;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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