gpt4 book ai didi

html - HTML 中高度定义元素中强标记的奇怪行为

转载 作者:太空宇宙 更新时间:2023-11-04 09:41:17 29 4
gpt4 key购买 nike

不知道它是否有正常的解释或者它是否是某种异常行为,但我在 HTML 中遇到了下一个问题:

我有以下段落:

<p>
You have <strong>32</strong> items
</p>

没什么特别的,而且工作正常。(结果:您有 32 项)

但是如果我添加以下样式:

<p>
You have <strong>32</strong> items
</p>
<p style="height:20%;">
You have <strong>32</strong> items
</p>

“strong”中的数字去掉了前后的空格。(结果:您有32项)

这是为什么?

PD:它的行为与“b”标签相同。

更多信息:

我正在使用 IIS 服务器在 Chrome 和 Firefox 中进行测试(均失败)。我无法在 Fiddle 中重现它,所以它可能是我的代码中缺少的东西......

更多信息:

这是完整的 scss:

$header_height: 10%;
$footer_height: 20%;
$body_height: 100% - ($header_height+$footer_height);

$container_frame_padding: 0.5em;


html{
height:100%;

body.vcAllowOverflowContent{
height:100% !important;

.vcPopupContainer{
height:100%;

.vcPopupTitle{
height:$header_height;
display:flex;
justify-content:center;
font-size:$bigger_font_size;
padding:$container_frame_padding;
}
.vcPopupBody{
height:$body_height;
border: solid black 1px;
overflow:auto;
padding:$container_frame_padding;
}
.vcPopupFooter{
height:$footer_height;
}
}
}

这里是一个更完整的 html:

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>MutipleDelete</title>

@Styles.Render("~/Content/Bootstrap")
<link rel="stylesheet" type="text/css" href="~/Content/vcPopups.min.css" />
</head>
<body class="vcAllowOverflowContent">
<div class="vcPopupContainer">
<p class="vcPopupTitle">
¿Desea borrar estos <strong>@Model.Count</strong> pacientes?
</p>
<div class="vcPopupBody">
...
</div>
<div class="vcPopupFooter">
...
</div>

@Scripts.Render("~/Scripts/Jquery")
@Scripts.Render("~/Scripts/Bootstrap")
</div>
</body>
</html>

如您所见,我正在使用 Bootstrap 和 Razor。

如果我删除“vcPopupTitle”类,该段落会正常运行。

最佳答案

强烈建议(自 HTML 5 起)如果可能(即使不能),使用 span class="foo"然后应用 font-weight:bold;到这个类,而不是使用 html 标签进行文本格式化。并且您不能在 % 上设置文本宽度,必须使用 px、em 或 rem,请参见下面的示例:

p{font-size:1.2rem;}
p.ps{font-size:1.6rem;}
span.foo{font-weight:bold;}
div.container{height:86px; overflow:auto; border:0.1rem solid black;}
.section1{height:40%; border:0.3rem solid blue;}
.section2{height:60%; border:0.3rem solid red;}
<div class="container">
<div class="section1">
<p>
You have <strong>32</strong> items
</p>
</div>
<div class="section2">
<p class="ps">
You have <span class="foo">32</span> items
</p>
</div>
</div>

注意标记的默认属性以及每个属性对应的作业。P 标签是一个段落,不能“按原样”使用高度属性。它将占用容器的 100% 的宽度和它需要的高度。如果你想限制一个 p 标签的高度,你必须限制这个 p 的容器,而不是强制限制到自己的 P 标签。

请注意,如果您尝试将容器强制调整到一个高度并且内容溢出其父容器,由于字体大小(在这种情况下),它不会产生可见的效果,因此您需要使用其他字体大小(最好将其指定为 rem,这意味着真实的 em)。

关于html - HTML 中高度定义元素中强标记的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39890247/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com