简体   繁体   English

使用css固定位置左右浮动

[英]float right and left with fixed position using css

I am having three div.我有三个 div。 The one on the middle i am having is with margin:auto so its displayed in the middle.我在中间的那个是margin:auto所以它显示在中间。

Now a div is to be floated on left of the page and one to the right while keeping the middle div in the middle.现在一个 div 将浮动在页面的左侧,一个向右浮动,同时将中间的 div 保持在中间。

Now I can achieve this using the example here现在我可以使用这里的示例实现这一点

But I want the position of the both the left and right divs to be fixed with -但我希望左右 div 的位置都固定 -

 position:fixed;

which is creating the problem.这造成了问题。

Should I have to use a child position:fixed div inside the right and the left floated divs?我是否应该在右侧和左侧浮动 div 内使用子位置:固定 div?

element with position:fixed don't respect floating.具有位置的元素:固定不尊重浮动。 You can replace your float:left;你可以替换你的 float:left; with left:0px; left:0px; and your float:right with right:0px;你的 float:right 和right:0px;

https://jsfiddle.net/tny0t6ps/3/ 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
}

you shouldn't do the height 100% try it auto or add how much px you want i done that你不应该做高度 100% 尝试自动或添加你想要多少像素我这样做

   height: auto;
    position:fixed;

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

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

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