Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/33.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.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
Html 中心位置水平固定_Html_Css - Fatal编程技术网

Html 中心位置水平固定

Html 中心位置水平固定,html,css,Html,Css,我想动态地在主体的末端附加一个固定位置,该位置位于底部框中,宽度为1000px,水平居中 当我用百分比宽度创建它时,我可以轻松地添加边距,一切都正常,但当我用像素创建它时,我就不能再添加边距了(它必须是响应性的)自动也不起作用 我该怎么做 <div style="position: fixed; bottom: 0; width: 1000px; margin: 0 auto; padding: 0;height: 100px; background-color: green;">

我想动态地在
主体的末端附加一个固定位置,该位置位于底部框中,宽度为1000px,水平居中

当我用百分比宽度创建它时,我可以轻松地添加边距,一切都正常,但当我用像素创建它时,我就不能再添加边距了(它必须是响应性的)<代码>自动
也不起作用

我该怎么做

<div style="position: fixed; bottom: 0; width: 1000px; margin: 0 auto; padding: 0;height: 100px; background-color: green;">
</div>

试试这个:

div{
位置:固定;
底部:0;
宽度:1000px;
左:50%;
左边距:-500px;
高度:100px;
背景颜色:绿色;
}

试试这个:

div{
位置:固定;
底部:0;
宽度:1000px;
左:50%;
左边距:-500px;
高度:100px;
背景颜色:绿色;
}

body:after{
内容:“;
宽度:1000px;
高度:100px;
位置:固定;
左:50%;
底部:0;
左边距:-500px;
背景颜色:绿色;
}

body:after{
内容:“;
宽度:1000px;
高度:100px;
位置:固定;
左:50%;
底部:0;
左边距:-500px;
背景颜色:绿色;

}
尝试CSS3,以避免为边距提供像素计算值

left:50%;
transform: translateX(-50%);

这里有一个演示:

尝试CSS3,以避免为边距提供像素计算值

left:50%;
transform: translateX(-50%);
这里有一个演示:

也可以尝试一下:

div{
  position: fixed; 
  bottom: 0; 
  width: 1000px; 
  left: 50%;
  transform:translateX(-50%);
  height: 100px; 
  background-color: green;
}
也可以尝试以下方法:

div{
  position: fixed; 
  bottom: 0; 
  width: 1000px; 
  left: 50%;
  transform:translateX(-50%);
  height: 100px; 
  background-color: green;
}

向我们展示一个不起作用的演示。提供一些代码,请注意,我提供了一些代码,它必须附加到body标记的末尾,而我不知道网站上的其他元素会有什么css。@Karol展示您尝试过的内容您使用了“动态”一词,但没有提供任何JS代码向我们展示一个不起作用的演示。提供一些代码请注意,我提供了一些代码,它必须附加到body标记的末尾,而我不知道网站上的其他元素会有什么css。@Karol显示您尝试的内容您使用了“动态”一词,但没有提供任何JS代码根据您最近的编辑,如果您只想附加到body标记的末尾,您不需要div。您可以使用伪选择器:after来实现它。在这种情况下,在上面的css上更改body:after的div。根据您最近的编辑,如果您只想附加到body标记的末尾,则不需要div。您可以使用伪选择器:after来实现它。在这种情况下,在上面的css上更改body:after的div。