- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我怎样才能做这样的布局?
basically,
I have 2 containers inflexbox
:
- first one with text
"33"
- the second one is a grid container:
- the first one in the grid is
"EUR"
- the second one in the grid is
".49"
根据这个描述,我尝试使用这段代码在 HTML 中编写一个结构
<nav>
<div class="item">
<span class="date">Dom 07 Ago</span>
<div class="price-container">
<div class="first-price-container">
<span class="price-big"> 371 </span>
</div>
<div class="second-price-container">
<span class="currency">EUR</span>
<span class="price-small"> 74 </span>
</div>
</div>
</div>
</nav>
我尝试为此使用 CSS,但这就是我得到的结果。完全不正确,因为我希望 33 的高度与网格布局完全相同:
here CSS code:
@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');
* {
box-sizing: border-box;
}
nav {
--small-font: 1rem;
font-family: poppins;
display: flex;
gap: 1rem;
/* space between copies of the container .item */
}
.item {
display: grid;
}
.price-container {
display: flex;
}
.second-price-container {
display: grid;
font-size: var(--small-font);
}
.price-big {
font-size: calc(var(--small-font) * 2);
/* I think that since the grid layout has two text with 1rem height, it will be 2rem (but not seems to work) */
font-weight: bold;
}
.price-small::before {
content: ".";
}
.item .date {
color: blue;
}
<nav>
<div class="item">
<span class="date">Dom 07 Ago</span>
<div class="price-container">
<div class="first-price-container">
<span class="price-big"> 37 </span>
</div>
<div class="second-price-container">
<span class="currency">EUR</span>
<span class="price-small"> 49 </span>
</div>
</div>
</div>
<div class="item">
<span class="date">Dom 07 Ago</span>
<div class="price-container">
<div class="first-price-container">
<span class="price-big"> 37 </span>
</div>
<div class="second-price-container">
<span class="currency">EUR</span>
<span class="price-small"> 49 </span>
</div>
</div>
</div>
<div class="item">
<span class="date">Dom 07 Ago</span>
<div class="price-container">
<div class="first-price-container">
<span class="price-big"> 37 </span>
</div>
<div class="second-price-container">
<span class="currency">EUR</span>
<span class="price-small"> 49 </span>
</div>
</div>
</div>
<!-- and soo on... repeatedly, however after I will find the correct structure, I will create a function in javascript that generate it -->
</nav>
在代码中,我认为如果我有两个元素为 1rem font-size
,
然后在右边,如果我在它附近插入另一个文本,我写了 1rem+1rem
的添加,使其与网格布局的高度相同。
似乎网格布局中的元素之间没有正确的间隙。
此外,另一种尝试是不做 1rem+1rem
,我增加了很多 1rem*5
,但问题仍然存在,
所以我认为如果 font-size 变大,那么右边的其他元素也会变大。
请帮忙,这对我来说似乎并不明显。 (因为这不会发生在 height 属性上,只有 font-size 才会出错)
问题:
是否有制作 font-size == height
的公式?这样我就可以在没有大量代码的情况下拥有像素完美的设计。
使用 height 更容易,使用 grid 和 flex。
因此它需要像您看到的图像一样,但带有字体。
如您所见,右侧其他两个元素的高度是正确的。
示例代码(仅作示例)
nav {
display: flex;
}
.item {
/* square */
height: 10rem;
width: 10rem;
display: flex;
}
.item>* {
flex: 1;
}
.another {
display: grid;
}
<nav>
<div class="item">
<div class="big" style="background-color: red;"></div>
<div class="another">
<div class="small" style="background-color: yellow;"></div>
<div class="small" style="background-color: green;"></div>
</div>
</div>
</nav>
最佳答案
字体大小不是高度。
字体大小 * 行高 == 高度
我只是将 line-height: 1
添加到您的 .price-container
@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');
* {
box-sizing: border-box;
}
nav {
--small-font: 1rem;
font-family: poppins;
display: flex;
gap: 1rem;
/* space between copies of the container .item */
}
.item {
display: grid;
}
.price-container {
display: flex;
line-height: 1;
}
.second-price-container {
display: grid;
font-size: var(--small-font);
}
.price-big {
font-size: calc(var(--small-font) * 2);
/* I think that since the grid layout has two text with 1rem height, it will be 2rem (but not seems to work) */
font-weight: bold;
}
.price-small::before {
content: ".";
}
.item .date {
color: blue;
}
<nav>
<div class="item">
<span class="date">Dom 07 Ago</span>
<div class="price-container">
<div class="first-price-container">
<span class="price-big"> 37 </span>
</div>
<div class="second-price-container">
<span class="currency">EUR</span>
<span class="price-small"> 49 </span>
</div>
</div>
</div>
<div class="item">
<span class="date">Dom 07 Ago</span>
<div class="price-container">
<div class="first-price-container">
<span class="price-big"> 37 </span>
</div>
<div class="second-price-container">
<span class="currency">EUR</span>
<span class="price-small"> 49 </span>
</div>
</div>
</div>
<div class="item">
<span class="date">Dom 07 Ago</span>
<div class="price-container">
<div class="first-price-container">
<span class="price-big"> 37 </span>
</div>
<div class="second-price-container">
<span class="currency">EUR</span>
<span class="price-small"> 49 </span>
</div>
</div>
</div>
<!-- and soo on... repeatedly, however after I will find the correct structure, I will create a function in javascript that generate it -->
</nav>
关于html - 为什么 `font-size` 不等于 `height` ?所以在右边,如果 <span> 是 2rem,在右边我可以有 2 个小的 <span>,每个 1rem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73184405/
根据小节 11.4.8 ECMAScript 5.1 标准: The production UnaryExpression : ~ UnaryExpression is evaluated as fo
我正在尝试构建一个“新评论”功能,向用户显示自上次访问以来的新评论数量。我构建了一个“ View ”表,其中包含主题 ID、用户 ID 和时间戳。每次用户访问该主题时更新时间戳或插入新行(如果不存在)
如标题所述,为什么: > !!1=="1" 等于 True 和 > !!2=="2" 等于: False 同样,为什么 > "1"==true 等于 true 而 > "2"==true 等于 fal
我在 Stack Overflow post 上看到了下图 但是,我对“p OR q”、“p AND q”的结果感到困惑,其中“p”等于“false”,“q”等于“unknown”。 在图中,“p O
一栏有效 whereJsonContains('VehicleApplications' ,['ModelName' => $model, 'YearID' => $year] )->
如果满足条件,我如何才能只获取特定记录? 我有代码为 "SELECT a.id, a.text, a.uid, a.time FROM story a INNER JOIN friends b
我正在尝试运行 MongoDB 查询并返回字段为空的记录(更具体地说,在 pyMongo 中为 None)。所以它必须等于 null。 我知道这不等于: {"firstName": {"$ne": N
我在 Java 中进行单元测试时遇到问题。 我把我的代码和错误放在这里。在互联网上我发现这是哈希码的问题。我需要重新创建它们,但我不知道为什么以及如何。 我的方法: public void setGr
如何在 Typescript 中实现 equals? 我尝试了几种方法,都没有奏效。 选项1: abstract class GTreeObject{ abstract equals(obj:
我查看了很多地方,大多数 arraylist 示例都使用“String”作为元素,但是很难找到使用对象的地方。 假设我正在制作一个图书 Collection ,并且我有一个作者对象: class Au
$a,$b,$c = 1,2,3; print "$a, $b, $c\n"; 返回 , , 1 那么 = (equals) 是否比元组构造具有更高的优先级 - 这样做? $a,$b,($c=1
在此代码片段中,a 和 i 分别具有什么值以及为什么? int i = 1; int a = i++; 是a == 1还是a == 2? 最佳答案 a==1。然后,i==2 如果你这样做的话,那就是a
我觉得我遗漏了一些明显的东西。这是一个简单的例子来说明我的问题。 我希望 current = 3 返回“之前”。 current = 4 应该返回“key-two”,current = 5 应该返回“
有人能告诉我为什么这会返回 true 吗?我想如果我投一些东西给例如Object 然后调用.equals,将使用 Object 的默认实现。 s1 == s2 应该返回 false。 请告诉我在哪个主
我需要检查加载到 UIImage 对象文件中的文件是否等于另一个图像,如果是,则执行一些操作。不幸的是,它不起作用。 emptyImage = UIImage(named: imageName) if
我想知道什么是正确的 Java 编程范式来覆盖类 C 对象的 equals(和 hashCode)方法,在以下情况下 (a) 有没有足够的信息来确定 C 的两个实例是否相等,或者 (b) 调用方法不应
>>> (()) == () True >>> (()) () 最佳答案 () 是一个 0 元组。 (foo) 产生 foo 的值。因此,(()) 产生一个 0 元组。 来自 the tutorial
考虑这段代码: var i = 0; >> undefined i += i + i++; >> 0 i >> 0 // why not 1? 由于增量 (++) 运算符,我希望 i 为 1。我认为
在我看来,TValue 似乎缺少一个强制方法; TValue.Equals(TValue)。 那么比较 2 个 TValue 的快速且合适的方法是什么,最好不使用 TValue.ToString(),
使用 SQL 时,在 WHERE 子句中使用 = 代替 LIKE 有什么好处吗? 如果没有任何特殊的运算符,LIKE 和 = 是相同的,对吧? 最佳答案 不同的运算符 LIKE 和 = 是不同的运算符
我是一名优秀的程序员,十分优秀!