首先,我试图用一个类似的问题在堆栈溢出上寻找答案,但结果仍然是一样的,它没有显示我所指的图像。
这就是我的html结构:
<div class="header__shape">
<img src="img/rose.png" alt="rose couples" class="header__shape-img">
<p class="header__shape-quote">
Being someone’s first love may be great, <br>
but to be their last is beyond perfect.
</p>
</div>这是为我的css和伪::之前
&-quote{
position : absolute;
font-size : $font-size-2;
font-family: $font-secondary;
color : $color-font;
line-height: 1.3;
right : 45rem;
top : 45rem;
&::before{
content : "";
background-image: url(../../img/quote.png);
height : 50px;
display : block;
width : 50px;
}
}我想要的是这样的

但实际上什么都没发生

发布于 2020-09-11 12:40:13
下面是我将如何解决这个问题。首先,您需要为父级提供一个position: relative,以便在div中移动p标记
然后将伪元素的位置设为绝对位置,以便在p标记周围移动它。
.header__shape {
position: relative;
}
.header__shape-quote {
line-height: 1.3;
font-size: 3rem;
color: red;
position: absolute;
right: 30rem;
top: 40rem;
}
.header__shape-quote::before {
font-size: 4rem;
position: absolute;
top: -50px;
left: -60px;
/* must have for fontawesome */
display: inline-block;
font-style: normal;
font-variant: normal;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
font-family: "Font Awesome 5 Free";
font-weight: 900;
content: "\f10e";
}

以一种不同的方式。我个人推荐这个。而不是上面例子中的绝对数。但我不知道哪个对你更好。所以我把两个都加进去了
.header__shape {
position: relative;
}
.header__shape-quote {
line-height: 1.3;
font-size: 3rem;
color: red;
margin-left: 5rem;
margin-top: 5rem;
position: relative;
}
.header__shape-quote::before {
font-size: 4rem;
position: absolute;
top: -50px;
left: -60px;
/* must have for fontawesome */
display: inline-block;
font-style: normal;
font-variant: normal;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
font-family: "Font Awesome 5 Free";
font-weight: 900;
content: "\f10e";
}<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css" integrity="sha512-1PKOgIY59xJ8Co8+NE6FZ+LOAZKjy+KY8iq0G4B3CyeY6wYHN3yt9PW0XpSriVlkMXe40PTKnXrLnZ9+fkDaog==" crossorigin="anonymous" />
<div class="header__shape">
<img src="https://picsum.photos/600" rose couples class="header__shape-img">
<p class="header__shape-quote">
Being someone’s first love may be great, <br> but to be their last is beyond perfect.
</p>
</div>

编辑
使用你的资产是很正常的。只需在URL中添加路径,并赋予其height和width,您就应该可以运行了。
.header__shape {
position: relative;
}
.header__shape-quote {
line-height: 1.3;
font-size: 3rem;
color: red;
margin-left: 5rem;
margin-top: 5rem;
position: relative;
}
.header__shape-quote::before {
font-size: 4rem;
position: absolute;
top: -50px;
left: -60px;
/* must have for fontawesome */
display: inline-block;
/* content: url('../images/caret-down-solid.svg'); */
content: url("https://picsum.photos/40");
}<div class="header__shape">
<img src="https://picsum.photos/600" rose couples class="header__shape-img">
<p class="header__shape-quote">
Being someone’s first love may be great, <br> but to be their last is beyond perfect.
</p>
</div>

您还可以将其添加为background-image,而不是在content中添加URL。这完全没问题。
.header__shape {
position: relative;
}
.header__shape-quote {
line-height: 1.3;
font-size: 3rem;
color: red;
margin-left: 5rem;
margin-top: 5rem;
position: relative;
}
.header__shape-quote::before {
font-size: 4rem;
position: absolute;
top: -50px;
left: -60px;
/* must have for fontawesome */
display: inline-block;
content: "";
height: 40px;
width: 40px;
/* background: url('../images/caret-down-solid.svg') no-repeat; that works fine i'm just using external link */
background: url('https://picsum.photos/40') no-repeat;
}<div class="header__shape">
<img src="https://picsum.photos/600" rose couples class="header__shape-img">
<p class="header__shape-quote">
Being someone’s first love may be great, <br> but to be their last is beyond perfect.
</p>
</div>
请随意选择最适合您的方式。
这不管用吗?请让我知道。我会尽我所能帮助你。
发布于 2020-09-11 12:28:10
你可以尝试添加<q>标签,这样如果你想为<q>标签添加CSS,你可以添加你的CSS类
<div class="header__shape">
<img src="pic_trulli.jpg" alt="rose couples" class="header__shape-img">
<p><q>
Being someone’s first love may be great, <br>
but to be their last is beyond perfect.</q>
</p>
</div>发布于 2020-09-11 13:01:07
将浮动、背景大小属性添加到伪元素的样式中,如下所示:
&-quote {
position : absolute;
font-size : $font-size-2;
font-family: $font-secondary;
color : $color-font;
line-height: 1.3;
right : 45rem;
top : 45rem;
&::before {
content : "";
background-image: url(../../img/quote.png);
height : 50px;
width : 50px;
/* new properties */
float: left;
background-size: contain;
}
}https://stackoverflow.com/questions/63840561
复制相似问题