Quantcast
Channel: Active questions tagged flexbox - Stack Overflow
Viewing all articles
Browse latest Browse all 1312

How to create a responsive circle with two lines of text in HTML and CSS?

$
0
0

body {  display: flex;  justify-content: center;  align-items: center;  gap: 15px;}.circle {  display: flex;  flex-direction: column;  align-items: center;  justify-content: center;  background-color: #333;  color: #fff;  font-size: 32px;  font-weight: 600;  border-radius: 50%;  padding: 20px;  aspect-ratio: 1 / 1;}
<body><div class="circle"><div>2</div><div>AP</div></div><div class="circle"><div>200,000</div><div>AP</div></div></body>

Why is the aspect-ratio CSS property not working here? When the text inside is long enough (like if I use 200,000 instead of 2, it is a square aspect ratio perfect circle). But I need it to work when the text is short too.

I want to avoid Javascript and hardcoding any widths or heights, because the circle should be fully responsive to the text inside of it, and be the minimum size required to display it (while also being a square aspect ratio).


Viewing all articles
Browse latest Browse all 1312

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>