【发布时间】:2018-06-01 04:40:44
【问题描述】:
我正在尝试在某些文本上获取背景图像,该文本位于屏幕左侧,而文本位于右侧。我希望它是背景图片,所以我可以这样做:
background-position: left center;
我在上面的同一个 CSS 文件中做了同样的事情,但是,这一次它不想工作,我一生都无法弄清楚为什么。
HTML:
<section class="skillset">
<div class="spaceage">
<h1>-filler-</h1>
<p>-filler-</p>
</div>
<div class="ability">
<h3>-filler-</h3>
<p>-filler-</p>
<img src="img/xdlogo.svg" alt="Adobe Experience Design Logo">
<img src="img/pslogo.png" alt="Adobe Photoshop Logo">
<img src="img/html5logo.png" alt="HTML 5 Logo">
<img src="img/css3logo.svg" alt="CSS 3 Logo">
</div>
</section>
<section class="aboutMe">
<div class="aboutMeText">
<h1>-filler-</h1>
<p>-filler-</p>
<p>-filler-</p>
</div>
</section>
我在“技能组”部分中做了同样的事情,但在“关于我”部分中无法实现。这是我的 CSS:
.skillset {
font-family: 'Montserrat', sans-serif;
position: relative;
margin-top: 50px;
background-image: url(img/asteroid.gif);
background-repeat: no-repeat;
background-position: right center;
background-size: 40%;
}
.aboutMe {
margin-top: 150px;
margin-right: 5%;
font-family: 'Montserrat', sans-serif;
position: relative;
background-image: url(img/asteroid.gif);
background-repeat: no-repeat;
background-position: left center;
background-size: 40%;
}
我不明白为什么背景图片没有显示在文本旁边。其他人知道为什么吗?
编辑: 我现在发现,如果我使用 HTML 中文本下方的标签添加图像,背景图像会奇迹般地出现!?!?!
【问题讨论】:
-
如果你想要它在右边,把它设置在右边而不是左边,并期望它在右边。
-
什么意思?左边我要的设置在左边,右边我要的设置在右边。
-
将背景设置在左侧并不意味着将文本推到右侧。
-
因此我使用 float: 对
-
浮动元素意味着浮动它的内容,内容是文本和背景。
标签: html css background-image css-position