无法居中背景图片
Trouble centering background image
我在将背景图像置于某个 div 中心时遇到问题。我正在为 CSS 使用以下代码:
.background3 {
max-width: 90%;
height: 400px;
margin: 0 auto;
background: linear-gradient( rgba(86, 71, 71, 0.56), rgba(86, 71, 71, 0.56)), url(img/kitpage.jpg) no-repeat 50% 50%;
}
我已经修改并尝试过,但无济于事。我很确定这是一个简单的答案,在此先感谢大家的帮助和建议。
下面附上问题截图
在您的 CSS 中使用以下内容:
display: block;
您必须使用背景位置 属性 例如:
.background3 {
max-width: 90%;
height: 400px;
margin: 0 auto;
background-position:20% 20%; // Margin background from top and left
}
您可以根据需要调整保证金,但这不是一个好方法。如果你想要更正确的方法,那么试试这个:
.background3 {
max-width: 90%;
height: 400px;
margin: 0 auto;
background-size:auto 100%;
background-position:center center;
}
我在将背景图像置于某个 div 中心时遇到问题。我正在为 CSS 使用以下代码:
.background3 {
max-width: 90%;
height: 400px;
margin: 0 auto;
background: linear-gradient( rgba(86, 71, 71, 0.56), rgba(86, 71, 71, 0.56)), url(img/kitpage.jpg) no-repeat 50% 50%;
}
我已经修改并尝试过,但无济于事。我很确定这是一个简单的答案,在此先感谢大家的帮助和建议。
下面附上问题截图
在您的 CSS 中使用以下内容:
display: block;
您必须使用背景位置 属性 例如:
.background3 {
max-width: 90%;
height: 400px;
margin: 0 auto;
background-position:20% 20%; // Margin background from top and left
}
您可以根据需要调整保证金,但这不是一个好方法。如果你想要更正确的方法,那么试试这个:
.background3 {
max-width: 90%;
height: 400px;
margin: 0 auto;
background-size:auto 100%;
background-position:center center;
}