【问题标题】:float right and left with fixed position using css使用css在固定位置左右浮动
【发布时间】:2016-03-19 04:17:29
【问题描述】:

我有三个 div。我在中间的那个是 ma​​rgin:auto 所以它显示在中间。

现在一个 div 将浮动在页面的左侧和右侧,同时将中间的 div 保持在中间。

现在我可以使用示例 here 来实现这一点

但我希望左右 div 的位置都用 - 固定

 position:fixed;

这是造成问题的原因。

我是否必须使用子位置:固定 div 在右侧和左侧浮动 div 中?

【问题讨论】:

    标签: html css


    【解决方案1】:

    position:fixed 的元素不尊重浮动。你可以更换你的浮动:左; left:0px; 和你的 float:right 和 right:0px;

    https://jsfiddle.net/tny0t6ps/3/

    .aleft {
    
        left:0px;
        width:100px;
        margin-right: 5px;
        background-color: #e3e3e3;
        padding:5px;
        height: 100%;
        position:fixed;
    }
    
    .aright {
       width:100px;
        background-color: #e3e3e3;
        padding:5px;
        position:fixed;
        right:0px
    }
    

    【讨论】:

    • 这对整个页面都很好。但不适合当我想将这三个都保持在一个固定宽度的 div 内时。
    • 然后将容器定位固定,容器内的3个孩子用float..
    【解决方案2】:

    您不应该将高度设置为 100% 尝试自动或添加您希望我完成的像素数

       height: auto;
        position:fixed;
    

    https://jsfiddle.net/tny0t6ps/4/

    【讨论】:

      猜你喜欢
      • 2012-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-30
      • 2012-10-13
      • 1970-01-01
      • 1970-01-01
      • 2014-05-06
      相关资源
      最近更新 更多