Javascript HTML |居中
当我使用particles.js时,我的图像无法居中。图像居中,但稍微偏离中心。它为什么要这样做?我怎样才能使它居中 htmlJavascript HTML |居中,javascript,html,css,Javascript,Html,Css,当我使用particles.js时,我的图像无法居中。图像居中,但稍微偏离中心。它为什么要这样做?我怎样才能使它居中 html <!DOCTYPE html> <html> <head> <title>particles.js demo</title> <link href="css/style.css" rel="stylesheet"> </head> <body> <div id="par
<!DOCTYPE html>
<html>
<head>
<title>particles.js demo</title>
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<div id="particles-js" width='100%'></div>
<script src="http://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js">
</script>
<script src="js/index.js">
</script>
<img id='downarrow' height="75" width="75" src='images/arrowdown.png'>
</body>
</html>
您正在使用
左:50%代码>-将图像的左边缘置于页面宽度的50%。如果希望图像居中,请添加transform:translateX(-50%)代码>
正文{
保证金:0;
高度:2000px;
宽度:100%;
}
:-webkit滚动条{
显示:无;
}
#粒子js{
位置:绝对位置;
宽度:100%;
身高:100%;
背景色:#00a4ff;
背景图像:url(“http://i.imgur.com/yHL4C4u.png");
背景重复:无重复;
背景位置:50%50%;
-webkit背景尺寸:封面;
-moz背景尺寸:封面;
-o-背景尺寸:封面;
背景尺寸:封面;
}
#向下箭头{
左边距:50%;
}
img{
位置:绝对位置;
}
使用负片左边距
将图像拉回到中心:
#downarrow {
left: 50%;
margin-left: -37px; /* Half of the image width */
}
如果我想将图像放置在天空图像的底部,我会怎么做?
#downarrow {
left: 50%;
margin-left: -37px; /* Half of the image width */
}