【发布时间】:2021-01-12 06:39:04
【问题描述】:
我希望创建一个带有边框的分区,如下面的 PNG
我计划制作一个具有以下尺寸的 ::after 元素:
width=height of the parent division;
height=1.5em;
以下代码运行正常,但 ::after 元素的宽度不对...
body {
display: flex;
flex-direction: column;
height: 93vh;
justify-content: center;
align-items: center;
background: #222;
color: #eee;
font-family: "Dosis", sans-serif;
}
.side-text {
position: relative;
font-size: 4em;
color: #eee;
background: none;
padding: 0.4em 0.5em 0.4em 0.3em;
border: 5px solid #eee
}
.side-text::after {
position: absolute;
content: "Points Needed";
font-size: 0.25em;
color: #222;
background: #eee;
text-align: center;
width: 100%;
/*This takes the value of 100%(Parent's Width) but we need 100%(Parents Height)*/
transform: rotate(-90deg);
left: 45%;
top: 42.5%;
/*The values of left, top have been assigned by trial & error, and will change with the length of the text in the parent division. If the text contained in the parent changes to say, 5000, the values specified above won't work */
}
<link href="https://fonts.googleapis.com/css?family=Dosis:700" rel="stylesheet" />
<div class="side-text">
50
</div>
left-margin、top-margin 的值是通过反复试验分配的,并且会随着父分区中文本的长度而变化。如果父项中包含的文本从 50 更改为 5000,则上面指定的值将不起作用。
【问题讨论】:
标签: javascript html css