将多行内容与:内容之前和之后对齐

时间:2017-10-31 08:41:23

标签: html css

我有一个文本,我使用CSS来添加引号标签。当文本到达新行时,它不会在引号符号之后但在

之前对齐



div {
  width: 240px;
}

p:before {
  content: "“";
  font-size: 30px;
}

p:after {
  content: "”";
  font-size: 30px;
}

<div>
  <p class="quote">This is some text that represents a quote that is rather long and splits into multiple lines</p>
</div>
&#13;
&#13;
&#13;

我希望它看起来像这样

enter image description here

可以使用:before:after完成,还是应该寻找其他方法?

2 个答案:

答案 0 :(得分:1)

:before及其父p分别定位为absoluterelative以完成此操作。请查看下面的代码段以供参考。

div {
  width: 240px;
}

p {
  padding: 10px 15px;
  position: relative;
}

p:before {
  content: "“";
  font-size: 30px;
  position: absolute;
  left: 0;
  top: 0;
}

p:after {
  content: "”";
  font-size: 30px;
  position: absolute;
  bottom: 0;
  margin-left: 5px;
}
<div>
  <p class="quote">This is some text that represents a quote that is rather long and splits into multiple lines</p>
</div>

答案 1 :(得分:0)

试试这个

&#13;
&#13;
div {
  width: 240px;
}
p:before,
p:after {
  display: inline-block;
  vertical-align: middle;
}

p:before {
  content: "“";
  font-size: 30px;
}

p:after {
  content: "”";
  font-size: 30px;
}
&#13;
<div>
  <p class="quote">This is some text that represents a quote that is rather long and splits into multiple lines</p>
</div>
&#13;
&#13;
&#13;