Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Relative positioned <span> inside a <p> element

I need a span to be displayed as a marker BENEATH important texts on my page.

It should have been positioned at the bottom of the p element – but it does not.

Can someone tell me what’s wrong in the code?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

.marker {
  position: absolute;
  bottom: 0px;
  background-color: red;
  height: 3.9px;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="a.css">
</head>

<body>
  <div>
    <p>
      This is
      <span>IMPORTANT INFORMATION THAT NEEDS TO BE EMPHASIZED
          <span class="marker"></span>
      </span>
    </p>
  </div>
</body>
</html>

>Solution :

Quote in comments: "What is it that you actually try to do? Do you want to mark that by underlining it?
Respond of OP: "Yes, exactly"

XY problem here. Instead of using a pseudo-element and positioning it, Simply add the underline as border-bottom to element itself:

.marker {
  border-bottom: 3.9px solid red;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="a.css">
</head>

<body>
  <div>
    <p>
      This is
      <span class="marker">IMPORTANT INFORMATION THAT NEEDS TO BE EMPHASIZED</span>
    </p>
  </div>
</body>
</html>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading