Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CSS相对定位,不断变化_Css_Css Position - Fatal编程技术网

CSS相对定位,不断变化

CSS相对定位,不断变化,css,css-position,Css,Css Position,所以基本上我有一个,它包含两个按钮。我想将这些按钮(div)放置在页面中某个点的另一个点上 我真的没有花太多的心思,我使用relative设置了定位,并将其定位在我想要的位置。然而,当我在几天后回到它的时候,它又被放错地方了,我没有改变CSS 下面是我对div的CSS: #button_menu { position: relative; top: 263px; left: 710px; width: 250px; } 基本上,我希望它总是放在同一个位置,在一个特定的分区“bodyA

所以基本上我有一个
,它包含两个按钮。我想将这些按钮(div)放置在页面中某个点的另一个点上

我真的没有花太多的心思,我使用relative设置了定位,并将其定位在我想要的位置。然而,当我在几天后回到它的时候,它又被放错地方了,我没有改变CSS

下面是我对div的CSS:

#button_menu {
position: relative; 
top: 263px; 
left: 710px;  
width: 250px; 
}
基本上,我希望它总是放在同一个位置,在一个特定的分区“bodyArea”

<div id="bodyArea">

<div id="button_menu">
<input type="button" class="smallbutton" id="add" value="add"/>
<input type="button" class="smallbutton" id="remove" value="remove"/>
</div>

.....

.....
我假设我做错了,所以如果有人能向我解释我如何才能实现我真正想要的


非常感谢,

给出了“bodyArea”元素的相对位置,以及“button\u menu”元素的绝对位置

这样做:

#bodyArea {position: relative; width: 250px;}
#button_menu {position: absolute; left: 100px; top: 100px;}

您必须认识到,需要固定的元素应该定位为“绝对”,并且它们的位置相对于最接近的父元素,父元素定位为“相对”(默认为“主体”)。

将相对位置指定给元素“主体区域”,将绝对位置指定给“按钮菜单”

这样做:

#bodyArea {position: relative; width: 250px;}
#button_menu {position: absolute; left: 100px; top: 100px;}

您必须认识到,需要固定的元素应该定位为“绝对”,并且它们的位置相对于最接近的父元素,而父元素定位为“相对”(默认为“主体”)。

您需要父div为
位置:相对
和子div的位置为
绝对

#bodyArea {
    position: relative;
}

#button_menu {
    position: absolute; 
    top: 263px; 
    left: 710px;  
    width: 250px; 
}

您需要父div是
position:relative
和子div的位置为
绝对

#bodyArea {
    position: relative;
}

#button_menu {
    position: absolute; 
    top: 263px; 
    left: 710px;  
    width: 250px; 
}
或者可能是
#buttonArea{…rel…}
.smallButton{…abs…}
或者可能是
#buttonArea{…rel…}
.smallButton{…abs…}