我正在尝试使用div来设置三个部分,一个是中间的主要部分,另一个是左边和右边的一个较小的部分。我能够做到这一点,但无法获得正确的列以获得固定的位置。每当我为此部分添加“position:fixed”时,它会忽略“float:right”并将该部分放在左列的顶部。请注意,我需要在代码中订购div的左右中间,否则右侧列位于其他内容下方的右侧。感谢。
<div style = "height: 100%">
<div style = "width: 15%; float:left; background-image: url(image.jpg);
background-size: 100% 100%;height: 100%; background-repeat:no-
repeat; background-position:left top; position: fixed" >
<div style = "margin-left:20px; margin-right:20px; margin-top:40px; margin-
bottom:40px">
<p2>
content
</p2>
</div>
</div>
<div style = "width: 15%; float:right; background-image: url(image.jpg);
background-size: 100% 100%; min-height: 100%; background-repeat:no-
repeat; **position: fixed;** background-position:right top">
<div style = "margin-left:20px; margin-right:20px; margin-top:40px; margin-
bottom:40px">
<p2>
content
</p2>
</div>
</div>
<div style = "width: 60%; margin-left:300px; margin-right:300px; top: 100px" >
<h1>head </h1>
<p>content
</p>
</div>
</div>
答案 0 :(得分:1)
当您给元素固定位置时,可以强制其在屏幕上的位置。例如,如果您的div卡在左侧,您可以添加“left:100px”将其向右移动100px。也就是说,它从左侧移动元素100px(将其移动到右侧)。您可以将此测量更改为此情况下的任何工作,例如75%。
另外看看CSS。将样式放入标记可能会变得混乱和重复,我不知道您是否打算让页面缩小浏览器窗口,但大多数网页指定列的宽度(以像素为单位)而不是百分比。