[英]How to center text within a border-radius?
I have a border-radius circling a letter grade but not all of the letters appear centered within their border radius. 我的边框半径环绕字母等级,但并非所有字母都以其边框半径为中心。 For example the letter D looks the worst:
例如,字母D看起来最糟:
Does anyone know of a way to make sure the text inside of the border radius always appears centered? 有谁知道一种确保边界半径内的文本始终居中的方法? (This app uses react if it matters.)
(如果需要,此应用会使用react。)
Here is the css for it: 这是它的css:
const buttonStyle = {
width: 40,
height: 40,
borderRadius: 100,
borderWidth: 2,
borderColor: stylesColors.grey,
padding: 0,
marginRight: 15,
fontSize: 27,
textAlign: 'center',
verticalAlign: 'middle',
display: 'table-cell'
};
And the html though I doubt it matters much: 而html虽然我怀疑这有多重要:
grades.map((grade, index) => {
return (
<Track key={index}>
<Button
className={(grade.letter === value.grade) ? 'green-button' : null}
style={buttonStyle}
id={`reviews--rating-${ratingTypeName}--${grade.letter}`}
key={index}
data-track-autopopulated={false}
data-track-rating-type={`${ratingTypeName.toLowerCase()}Grade`}
data-track-selected-grade={grade.letter}
data-track-draft-review-id={draftReviewId}
data-track-service-provider-id={serviceProviderId}
onClick={() => this.handleSelect(grade.letter)}>
{grade.letter}
</Button>
</Track>
);
})
There are some issues in your css/scaffolding as isolating the snipped results in correctly centered items: 在CSS /脚手架中存在一些问题,因为在正确居中的项目中隔离了剪切结果:
.centerRound{ width: 40px; height: 40px; border-radius: 100%; border: 2px solid grey; padding: 0px; margin-right: 15; font-size: 27; text-align: center; vertical-align: middle; display: table-cell; font-size:35px; }
<div class="centerRound">A</div> <div class="centerRound">B</div> <div class="centerRound">C</div> <div class="centerRound">D</div>
is this what you want? 这是你想要的吗?
div { height: 30px; width: 30px; border: 1px solid black; border-radius: 50%; display: inline-block; } span { display: inline-block; margin-top: 50%; margin-left: 50%; transform: translate(-50%, -50%); }
<div> <span> A</span> </div> <div> <span> B</span> </div> <div> <span> C</span> </div> <div> <span> D</span> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.