Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
How to position div text beside shape

I was wondering if it is possible to position the div text exactly at the end of the CSS shape within the same div without requiring any additional html elements? Currently, they are overlapping.

div {
    width: 10px;
    height: 10px;
    background: var(--color);    
}
<div style="--color:red">AB</div>  
    <div style="--color:green">CD</div>
    <div style="--color:blue">EF</div>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Like this? The ::before pseudo element can be styled. It's not "positioning the text at the end of the <div>" since the text is still contained in the <div>, but it does get you the colored square before the text with no additional (explicit) elements in the markup.

div::before {
    content: '';
    display: inline-block;
    width: 10px;
    height: 10px;
    background: var(--color);    
}
<div style="--color:red">AB</div>  
<div style="--color:green">CD</div>
<div style="--color:blue">EF</div>

about 4 years ago · Juan Pablo Isaza Report

0

You can try out something with the pseudo-elements (:before or :after). In my example changing the padding-left: 15px; inside div you can control the space between the boxes and text, and by changing bottom: 4px; inside the div:before you can align them in the middle of text

div {
  position: relative;
  padding-left: 15px;  
}

div:before {
  position: absolute;
  content: '';
  left: 0;
  bottom: 4px;
  width: 10px;
  height: 10px;
  background: var(--color); 
}
<div style="--color:red">AB</div>  
<div style="--color:green">CD</div>
<div style="--color:blue">EF</div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!