css - 有没有更好的方法将此背景图像与其上方的文本对齐?
问题描述
我正在尝试使用多个媒体查询将背景图像(右侧的灰色圆圈)与其上方的文本对齐,但我没有取得多大成功。我可以进行更多的媒体查询,但我只是想知道是否有更智能、更自动化的方法来做到这一点。
这是页面:https ://veritywebsvs.com/wmjw/ 我需要让右侧的灰色圆圈与上面的文本居中,如前所述。
这是我用来尝试使圆居中的 CSS:
#hero .fl-node-60bfc0dd0afeb > .fl-row-content-wrap {
background-image: url(circles-2-gray-trans.svg);
background-repeat: no-repeat;
background-position: right center;
background-attachment: scroll;
background-size: cover;
border-width: 0;
background-clip: border-box;
min-height: 650px;
}
#hero > .fl-row-content-wrap {
background-size: 60vw;
}
@media (min-width: 1920px) {
#hero > .fl-row-content-wrap {
background-position: 95% center;
}
}
@media (min-width: 1100px) and (max-width: 1919px) {
#hero > .fl-row-content-wrap {
background-position: 110% center;
}
}
@media (min-width: 992px) and (max-width: 1099px) {
#hero > .fl-row-content-wrap {
background-position: 120% center;
background-size: 75vw;
}
}
@media (max-width: 991px) {
#hero > .fl-row-content-wrap {
background-position: 130% center;
background-size: 80vw;
}
}
解决方案
与其使用背景图像并尝试将图像放置在正确的位置,<img>
不如在使用负边距的情况下使用并将其放置在任何您想要的位置position: relative
,或者top, bottom, right, left positioning
如果使用position: absolute
. 连同用于z-index
正确分层图像的用途。
添加一个 div 和 img 就像我在此处添加的一样,它将解决您当前的定位问题。
https://www.w3schools.com/css/css_positioning.asp
.for-bg {
width: 1080px;
margin-top: -1050px;
max-width: revert;
right: 150px;
position: relative;
overflow: hidden;
z-index: 0;
margin-right: -300px;
margin-bottom: -630px;
}
<div class="fl-module fl-module-rich-text fl-node-60c015378acf7" data-node="60c015378acf7">
<div class="fl-module-content fl-node-content">
<div class="fl-rich-text">
<p>WMJW has been serving clients<br>
<span style="color: #ca9130;">for ___ years</span><br> and ________.</p>
</div>
</div>
</div>
<div><img src="https://veritywebsvs.com/wmjw/wp-content/uploads/2021/06/circles-2-gray-trans.svg" class="for-bg"></div>
推荐阅读
- javascript - 为什么 classList.() 函数中的句点适用于某些而不适用于其他?
- go - go-colly:如何在 c.OnResponse 中获取 HTML 标题,以便填充结构?
- mips - 删除前导和尾随空白 mips?
- php - 验证请求中是否只有指定的参数 - Laravel
- jquery - Wordpress rest API 自定义端点,使用 Jquery .getJSON 模板文字,只有一项未显示
- database - MongoDB 集合更新尝试给出“标识符在数字文字后立即启动”错误
- php - 在特征中使用构造函数的替代方法
- c++ - 在一个方法中设置多个类成员是个好主意吗?
- sql-server - 无法删除索引,因为它不是统计信息集合
- python - 使用 Python 向 JSON 数据添加“值”信息