gpt4 book ai didi

html - 为什么 html 页面不适合 100%?

转载 作者:行者123 更新时间:2023-11-27 23:38:39 27 4
gpt4 key购买 nike

每当我想制作一个 html 页面时我都会遇到问题,为什么 html 页面小于 100%?让我举例说明:

<!doctype html>
<html>
<head>
<title>Test</title>
<style>
html
{
margin: 0;
padding: 0;
width: 100%;
}
body
{
margin: 0;
padding: 0;
}
.row
{
width: 100%;
margin: 0 auto;
padding: 0;
}
.col-1
{
width: 10%;
margin: 0;
padding: 0;
display: inline-block;
}
</style>
</head>
<body>
<div class="row">
<div class="col-1">Some text</div>
<div class="col-1">Some text</div>
<div class="col-1">Some text</div>
<div class="col-1">Some text</div>
<div class="col-1">Some text</div>
<div class="col-1">Some text</div>
<div class="col-1">Some text</div>
<div class="col-1">Some text</div>
<div class="col-1">Some text</div>
<div class="col-1">Some text</div>
</div>
</body>
</html>

为什么最后一个 div 到下一行?所有宽度为 10% 意味着我们可以在行中添加 10 个 div,但在现实世界中它不会发生?!我检查了所有边距、填充、边框,但我什么也没看到。你能告诉我为什么会这样吗?

最佳答案

当您输入 display: inline-block; 时,它会在它们之间生成空格。以这种方式使用相同的代码:

<div class="row">
<div class="col-1">Some text</div><!--
--><div class="col-1">Some text</div><!--
--><div class="col-1">Some text</div><!--
--><div class="col-1">Some text</div><!--
--><div class="col-1">Some text</div><!--
--><div class="col-1">Some text</div><!--
--><div class="col-1">Some text</div><!--
--><div class="col-1">Some text</div><!--
--><div class="col-1">Some text</div><!--
--><div class="col-1">Some text</div>
</div>

fiddle :http://output.jsbin.com/xorahifipe

你也可以使用float: left,但是你需要给父级overflow: hidden;,或者以某种方式清除它。在您的原始示例中,float 以这种方式工作:

.row {
width: 100%; /* This is not necessary */
margin: 0 auto; /* This is not necessary */
padding: 0; /* This is not necessary */
overflow: hidden;
}
.col-1 {
width: 10%;
margin: 0; /* This is not necessary */
padding: 0; /* This is not necessary */
float: left;
}

fiddle :http://output.jsbin.com/daruzepiqa/1

关于html - 为什么 html 页面不适合 100%?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32669279/

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