Как поместить некоторый текст в конец первой строки другого текстового узла (p) - PullRequest
1 голос
/ 03 апреля 2020

Я хочу поместить некоторый текст в первые строки последней позиции абзаца. Как мне сделать это, используя css? (если это невозможно с CSS, то как мне сделать это с JS)

Я хочу выполнить следующее

my expected outcome

Ответы [ 2 ]

1 голос
/ 03 апреля 2020

Один из способов сделать это - использовать 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>
0 голосов
/ 03 апреля 2020

Использование 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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...