I’m trying do an arrow to point a direction, chosen by a gamepad. I stylised my arrow like this :
A screen of my arrow, as an image is better than 1000 words
When an angle is given by the joystick, all the stuff is rotating with this angle (rotate
applyed to cercle
class). Thus the tip of the black triangle is pointing a direction. Pretty, isn’t it ? 😀
But ! you can see a number, in the middle. It’s an important information (a PWM setting I’m sending over TCP, but not the subject here) And I want it to be in the center of the circle for… style ?
My issue is : I centered this number with a flexbox, then, when all the circle is rotating, the number is rotating too ! It’s ugly ! How can I avoid this ? 🙁
Please find the CSS and the HTML bellow :
<div class="cercle" id="fleche">
<div class="middle">
<p id="vitesse">1306</p>
</div>
<div class="triangle">
</div>
</div>
.cercle {
order:0;
border-radius: 50%;
height: 80%;
aspect-ratio: 1/1;
background: linear-gradient(45deg, pink, red);
display: flex;
rotate: 0deg;
transition: 350ms;
.middle{
border-radius: 50%;
height: 92%;
width: 92%;
background-color: black;
align-self: center;
margin: auto;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.triangle {
width: 0px;
border-style: solid;
border-width: 20px;
border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) black rgba(0, 0, 0, 0) ;
margin-left: 44.4%;
margin-top: -7.2%;
background: rgba(0, 0, 0, 0);
position: absolute;
}
#vitesse{
/*...*/
}
}
You probably guessed it, there is no critical issue, just aesthetic. I tried to apply an opposed rotation to this number, but the result is not satisfying (seems like "clipping".) I think the best option is to forbid the rotation of the number… by getting it out of the circles ? But I’ve to keep it inside, if I want the number to dynamically stay in the center of the circle.
Thanks for your help !
3
Answers
You can do one of two things:
you can essay this
Here is a simple idea without too much code: