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

我想在段落的第一行最后位置放置一些文本。我如何使用 css 来做到这一点? (如果这对 CSS 来说是不可能的,那么我该如何用 JS 做到这一点)

我想要像下面这样

https://i.stack.imgur.com/VIk9n.png


德玛西亚99
浏览 80回答 2
2回答

慕容3067478

一种方法是使用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>

catspeake

使用CSS<!DOCTYPE html><html>&nbsp; &nbsp; <body>&nbsp; &nbsp; &nbsp; &nbsp; <br/><div>&nbsp; &nbsp; <span style="float: right;font-weight: italic;font-size:.8rem;color:grey"> March 07, 5:45pm </span>&nbsp; &nbsp; <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&nbsp; &nbsp; </p><div>&nbsp; &nbsp; </body></html>使用JavaScript<!DOCTYPE html><html>&nbsp; &nbsp; <body>&nbsp; &nbsp; &nbsp; &nbsp; <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>&nbsp; &nbsp; </body>&nbsp; &nbsp; <script>&nbsp; &nbsp; &nbsp; &nbsp; var textnode = document.createTextNode(" March 07,5:45pm");&nbsp; // Create a text node&nbsp; &nbsp; &nbsp; &nbsp; var p = document.getElementById("p1");&nbsp; &nbsp; // Get the <ul> element to insert a new node&nbsp; &nbsp; &nbsp; &nbsp; p.insertBefore(textnode, p.childNodes[1]);&nbsp; // Insert <li> before the first child of <ul>&nbsp; &nbsp; </script></html>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Html5