-1

Hope you can help, really stuck:

I have these circle divs with a linear gradient border - I need to have some text centrally aligned within the circle but I have no idea how to achieve this - I am quite stuck so any help would be much appreciated!!

The code is below:

For the circle:

.white-grad {
  --b:12px;  /* border width*/

  color: #313149;
  display: inline-block;
  margin: 10px;
  width:214px;
  position:relative;
  z-index:0;
}
.white-grad:after {
  content:"";
  display:inline-block;
  padding-top:100%;
}
.white-grad:before {
  content:"";
  position:absolute;
  z-index:-1;
  top:0;
  left:0;
  right:0;
  bottom:0;
  background: var(--c,linear-gradient(26deg, #a347dc 13%, #697cfe 87%));
  -webkit-mask:radial-gradient(farthest-side,transparent calc(100% - var(--b) - 1px),#fff calc(100% - var(--b)));
          mask:radial-gradient(farthest-side,transparent calc(100% - var(--b) - 1px),#fff calc(100% - var(--b)));
  border-radius:50%;
}

And the text:

.text {
  width: 98px;
  height: 44px;
  font-family: OpenSans;
  font-size: 19px;
  font-weight: 600;
  font-stretch: normal;
  font-style: normal;
  line-height: 1.16;
  letter-spacing: -0.52px;
  text-align: center;
  color: #000000;
}

Many thanks in advance,

1 Answers1

2

In class .white-grad, change your display to inline-flex and add some centering properties:

.white-grad {
   display: inline-flex;
   justify-content: center;
   align-items: center;
 }
ddprrt
  • 7,424
  • 3
  • 29
  • 25
  • Thanks so much! @ddprrt One last issue - If I have two blocks of text within a circle ' flex-direction: column' seems to break it - maybe row wrap could work? – trailrunner89 Nov 26 '20 at 00:46
  • I suggest a wrapping element so can separate layouting the entire frame from layouting individual items: https://codepen.io/ddprrt/pen/jOMOPaE – ddprrt Nov 26 '20 at 07:21