简体   繁体   English

CSS:最小宽度和绝对定位

[英]CSS: min width and absolute positioning

<style type="text/css">
html, body {
margin: 0;
padding: 0
}

.column1
{
position:absolute;
left:0;
top:0;
width:100px;
background-color:black;
}
.column2
{
position:absolute;
left:100px;
right:100px;

background-color:gray;
}

.middle {

min-width:900px;
}

.column3
{
position:absolute;
right:0;
top:0;
width:100px;
background-color:black;
}

#container
{

text-align: center; 
width:100%;
}

.clearfix 
{
position:relative;
display: inline-block; 
}
</style>

<div id="container" class="clearfix">
  <div class="column1">left</div>
  <div class="column2">
  <div class="middle">
  middle
  </div>
  </div>
  <div class="column3">right</div>
</div>

I was wondering if it would be possible for the min-width for the center column would make it so the right column would stick to the screen as it does, but up until the center column is 900px. 我想知道中心列的最小宽度是否有可能使右列像它一样粘在屏幕上,但是直到中心列为900px。 If it is less than that, the resizing of the window smaller horizontally would just cut-off the right column. 如果小于此值,则将窗口的大小调整为水平较小将仅切断右列。

Is this possible with css only? 这仅适用于CSS吗?

Thanks so much! 非常感谢!

Absolutely positioned elements aren't affected by their neighbors, so you can't affect the right column with the width of the center. 绝对定位的元素不受其相邻元素的影响,因此您不能影响中心宽度的右列。

However, you could easily do this by simply putting min-width:1100px on your #container div. 不过,您只需在您的#container div上放置min-width:1100px即可轻松地做到这一点。

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

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