为了账号安全,请及时绑定邮箱和手机立即绑定

如何将一些文本放入另一个文本节点的第一行末尾 (p)

如何将一些文本放入另一个文本节点的第一行末尾 (p)

德玛西亚99 2023-10-30 15:33:20
我想在段落的第一行最后位置放置一些文本。我如何使用 css 来做到这一点? (如果这对 CSS 来说是不可能的,那么我该如何用 JS 做到这一点)我想要像下面这样https://i.stack.imgur.com/VIk9n.png
查看完整描述

2 回答

?
慕容3067478

TA贡献1773条经验 获得超3个赞

一种方法是使用float


.small-text{

  float: right;

  font-weight: italic;

  font-size:.8rem;

  color:grey

}

<br/>

<div>

  <span class="small-text"> March 07, 5:45pm </span>

  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum

  </p>

<div>


查看完整回答
反对 回复 2023-10-30
?
catspeake

TA贡献1111条经验 获得超0个赞

使用CSS


<!DOCTYPE html>

<html>

    <body>

        <br/>

<div>

    <span style="float: right;font-weight: italic;font-size:.8rem;color:grey"> March 07, 5:45pm </span>

    <p style="text-align: right;">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum

    </p>

<div>

    </body>

</html>


使用JavaScript


<!DOCTYPE html>

<html>

    <body>

        <p id="p1">Lorem ipsum dolor sit amet consectetur adipisicing elit.<br>Quaerat quas tenetur aliquam ipsum vitae, excepturi, accusamus <br> vel nostrum obcaecati praesentium neque id inventore laborum <br>distinctio quam dolor ullam consectetur nesciunt?</p>

    </body>

    <script>

        var textnode = document.createTextNode(" March 07,5:45pm");  // Create a text node

        var p = document.getElementById("p1");    // Get the <ul> element to insert a new node

        p.insertBefore(textnode, p.childNodes[1]);  // Insert <li> before the first child of <ul>


    </script>

</html>


查看完整回答
反对 回复 2023-10-30
  • 2 回答
  • 0 关注
  • 79 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信