简体   繁体   English

右浮动div和min-width,div移动到浏览器调整大小的新行

[英]right floated div and min-width, div moves to the new line on browser resize

Sorry for not well-explained title, but I will try my best to explain the problem here. 很抱歉没有很好解释的标题,但我会尽力在这里解释问题。 There is probably a very easy solution to this particular problem, if i can call it that way, but I just can't figure it out with using only css. 对于这个特定的问题,可能有一个非常简单的解决方案,如果我可以这样称呼它,但我只能用css来解决它。

Basically I have a parent ('wrapper') div which has min-width set and 2 floated children. 基本上我有一个父('包装')div,它有最小宽度设置和2个浮动子项。 As I am creating a dynamic page, user will be able to click on the 'right' floated div, and when he clicks on it new content will be added inside that div. 当我创建一个动态页面时,用户可以点击“正确”浮动div,当他点击它时,新内容将被添加到该div中。

Problem occurs if the user wants to resize the browser after adding content to the div. 如果用户想要在向div添加内容后调整浏览器大小,则会出现问题。 Because the width of the main wrapper will be increased (when user adds content) when user tries to reduce the browser width (resize the browser) the 'right' floated div will go to the new line. 因为当用户尝试减小浏览器宽度(调整浏览器大小)时,主包装器的宽度将增加(当用户添加内容时),“正确”浮动div将转到新行。 So my question is: Is there any way (css) to disable div from moving to the new line? 所以我的问题是:有没有办法(css)禁止div移动到新行?

Here is the link to the jsfiddle: http://jsfiddle.net/LKgbx/30/ 这是jsfiddle的链接: http//jsfiddle.net/LKgbx/30/

HTML: HTML:

<div id="wrapper">
     <div id="left">I'm left</div>
     <div onclick="changeText()" id="right">I'm right</div>
 </div>

CSS: CSS:

#wrapper{
    min-width:400px;
    background-color:#A3F8A9;
    display:inline-block;
}
#left{
    float:left;
    width:300px;
    background-color:red;
}
#right{
    float:right;
    background-color:blue;
}

JS: JS:

function changeText(){
    document.getElementById('right').innerHTML="Just adding some text to make div longer";
}
<script type="text/javascript">
function changeText(){
    document.getElementById('right').innerHTML="Just adding some text to make div longer";
}
</script>
<style type="text/css">
#wrapper{
    background-color:#A3F8A9;
    position:relative;
}
#left{
    position:absolute;
    left:0px;
    width:300px;
    background-color:red;
}
#right{
    position:absolute;
    left:300px;
    width:100%;
    background-color:green;
}
</style>


<div id="wrapper">
     <div id="left">I'm left</div>
     <div onclick="changeText()" id="right">I'm right</div>
 </div>

Try removing float:right; 尝试删除float:right; from #right 来自#right

#right{
    background-color:blue;
}

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

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