Css 为什么图像会随着浏览器移动而不居中?
我如何让它保持居中。我试过很多不同的方法,但都不管用。显示器无需保留,因为我需要它来显示和隐藏图像。我还需要添加什么才能让它工作?我只希望它保持水平居中 这是js小提琴Css 为什么图像会随着浏览器移动而不居中?,css,Css,我如何让它保持居中。我试过很多不同的方法,但都不管用。显示器无需保留,因为我需要它来显示和隐藏图像。我还需要添加什么才能让它工作?我只希望它保持水平居中 这是js小提琴 您可以尝试将当前的#边框搜索内部img元素居中,并在CSS中进行以下更改,相对使用自动(相等)左右边距定位图像,并使其居中 #border-search { position: relative; top: 50% !important; left: 25% !important; width:
您可以尝试将当前的
#边框搜索
内部img
元素居中,并在CSS中进行以下更改,相对使用自动(相等)左右边距定位图像,并使其居中
#border-search {
position: relative;
top: 50% !important;
left: 25% !important;
width: 100% !important;
margin-left: auto !important;
margin-right: auto !important;
display: none;
}
#border-search.center img {
position: absolute; top: 50%; left: 50%;
transform: translate(-50%, -50%);
width: 30%;
height: auto;
}
显示:块代码>语句是将图像视为块元素所必需的,因此它可能会受到边距属性的影响
检查以验证我刚才所说的。:) Fiddle请帮助你?位置:固定
使DIV在你滚动时保持在原位这里是js Fiddle Volvox:我只希望它保持水平居中。我添加了你的代码,它似乎没有任何作用。
#border-search {
margin: 0 auto;
position: relative;
}
#border-search img {
display: block;
margin: 0 auto;
position: relative;
}