【发布时间】:2021-10-03 19:38:06
【问题描述】:
我的问题是我试图将我拥有的文本限制为我制作的网格的当前边框。但是当文本变得太长时,文本会超出边界,看起来很难看。有没有办法根据字体是否碰到边框来动态更改字体大小,但它不会填充文本和边框之间的其余空间。
这里是相关的 CSS
@import url('https://fonts.googleapis.com/css2?family=Fredoka+One&display=swap'); /*HEADER PRICE ETC font-family: 'Fredoka One', cursive;*/
@import url('https://fonts.googleapis.com/css2?family=Fredoka+One&family=Rajdhani&display=swap'); /*PROD DESC font-family: 'Fredoka One', cursive;
font-family: 'Rajdhani', sans-serif; */
.container {
display: grid;
grid-template-columns: 18em 18em 18em;
grid-template-rows: 18em;
gap: 0px 4em;
grid-auto-flow: row;
justify-content: center;
justify-items: start;
grid-template-areas:
"ClothOne ClothTwo ClothThree";
}
.ClothOne {
grid-area: ClothOne;
border: solid black 2px;
}
.ClothTwo {
grid-area: ClothTwo;
border: solid black 2px;
}
.ClothThree {
grid-area: ClothThree;
border: solid black 2px;
}
/*PRODUCT STYLES*/
.price {
color: darkorange;
font-size: 1em;
margin: 0;
font-family: 'Fredoka One', cursive;
}
.prodName {
font-family: 'Fredoka One', cursive;
margin: 0;
font-size: 1em;
}
.desc {
font-family: 'Fredoka One', cursive;
font-family: 'Rajdhani', sans-serif;
font-size: 1vw;
}
这是我的 HTML 文档。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="master.css">
<title>Document</title>
</head>
<body>
<div class="container">
<div class="ClothOne">
<img src="../Pictures/Capture.PNG" alt="tester" width="200px">
<p class="prodName">Rolling Dice</p>
<p class="price">$30.5</p>
<p class="desc">this is a basic item description of this current item</p>
</div>
<div class="ClothTwo">
<img src="../Pictures/Capture.PNG" alt="tester" width="200px">
<p class="prodName">Rolling Dice</p>
<p class="price">$45.0</p>
<p class="desc">Here is another item description that is slightly longer
than the other description, and might go past the boundary
</p>
</div>
<div class="ClothThree">
<img src="../Pictures/Capture.PNG" alt="tester" width="200px">
<p class="prodName">Rolling Dice</p>
<p class="price">$45.0</p>
<p class="desc">Here is the last item description which is this time
guaranteed to go past the boundary no matter how long the item description is
and will hopefully will not break the boarder box or make it longer than
than what it is supposed to be.
</p>
</div>
</div>
</body>
</html>
我需要动态改变字体大小的类是“.desc”类。
【问题讨论】: