Search code examples
htmlcssvertical-alignment

CSS vertical-align: text-top; not working for the span elements in my <p> tag?


enter image description here

I want the top of any lower span tag attached to the base (bottom) of the an upper span tag, just like in the image.

I wanted to make the span elements align, so that the top of each span tag is at the base of an upper span tag. I tried using vertical-align: text-top; but I saw no changes.

p#highlighter {
  border: 5px solid black;
  color: black;
  font-family: tusker-grotesk;
  text-align: left;
  vertical-align: text-top;
  width: 50%;
  position: absolute;
  top: 6%;
  left: 2%;
}

p#highlighter span#pos {
  color: #DE000D;
  font-size: 50px;
}
<p id="highlighter">
  <span id="pos">POS</span> <br />
  <span id="smaller">IS     AVAILABLE</span> <br />
  <span id="here">HERE</span>
</p>

I also tried vertical-align: top; but I still saw no changes.
My goal is that the span tags are vertically clustered (attached) to each other in the p container.


Solution

  • I'm not sure I got you right but if you just need something like on the picture, my snippet may help. It's mainly based on yours.

    #highlighter {
        position: absolute;
        padding: 10px;
        border: 5px solid black;
        line-height: 1;
        text-align: left;
        font-family: sans-serif;
        font-weight: 900;
        color: black;
    }
    
    #highlighter span {
        font-size: 4em;
        line-height: 0.7;
    }
    
    #highlighter #pos {
        color: red;
    }
    
    #highlighter #smaller {
        font-size: 1.5em;
        padding-left: 0.15em;
        letter-spacing: 0.015em;
    }
    <p id="highlighter">
      <span id="pos">POS</span> <br />
      <span id="smaller">IS AVAILABLE</span><br />
      <span id="here">HERE</span>
    </p>