Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS circle with dynamic text inside

Tags:

css

css-shapes

I need to build a circle shape (in css) which has 2 lines of text that could change in length based on translation selected and always centered.

So far I have this:

h3 {
  background-color: #fcd141;
  border-radius: 50%;
  padding: 12px 5px 5px 5px;
  margin-top: 30px;
  width: 20%;
  height: 20%;
}
<h3>
  <span style="vertical-align: middle;">98%</span>
  <span style="margin-top: -4px; display: block;">Ratingfasdasfasfsad</span>
</h3>

The circle needs to respond dynamically to the length of the text keeping the aspect ration intact.

like image 642
Aessandro Avatar asked Feb 17 '26 17:02

Aessandro


1 Answers

You can have a look at the code as in your code it looks like an ellipse to me

.circle-text {
  width: 50%;
  padding 10px;
}
.circle-text:after {
  content: "";
  display: block;
  width: 100%;
  height: 0;
  padding-bottom: 100%;
  background: #4679BD;
  -moz-border-radius: 50%;
  -webkit-border-radius: 50%;
  border-radius: 50%;
}
.circle-text div {
  float: left;
  width: 100%;
  padding-top: 50%;
  line-height: 1em;
  margin-top: -0.5em;
  text-align: center;
  color: white;
}
<div class="circle-text">
  <div>I'm asddddddssssssssssssssssssasdasdashd asfafjsldfashdfisdpf sdjf pe!</div>
</div>
like image 162
Tushar Avatar answered Feb 20 '26 10:02

Tushar