gpt4 book ai didi

html - 分屏麻烦

转载 作者:可可西里 更新时间:2023-11-01 13:03:34 25 4
gpt4 key购买 nike

我尝试在 Codepen 上制作响应式分屏。当屏幕尺寸较小时,它会给出列,否则你会得到两行。在 codepen 上一切正常。但是当我尝试将此代码实现到我的网站代码中时,灰色区域就会消失。可能是什么原因?

http://codepen.io/bellarose/pen/YqGZLL

HTML:

<section class="first-section">
<body>
<div class="container-info">
<h1>first screen</h1>
</div>
<div class="container-main">
<h1>second screen</h1>
</div>
</body>
</section>

<section class="second-section">
<body>
<div class="container-info1">
<h1>first screen</h1>
</div>
<div class="container-main1">
<h1>second screen</h1>
</div>
</body>
</section>

CSS:

.first-section {
height: 100%;
text-align: center;
}

.second-section {
height: 100%;
text-align: center;
}

.container-info {
display: inline-block;
position: relative;
width: 100%;
min-height: 490px;
background-color: red; }
@media (min-width: 768px) {
.container-info {
float: left;
left: 0;
top: 0;
height: 100%;
width: 50%; } }



.container-main {
display: inline-block;
position: relative;
width: 100%;
min-height: 490px;
background-color: grey; }
@media (min-width: 768px) {
.container-main {
float: right;
right: 0;
top: 0;
height: 100%;
width: 50%; } }


.container-info1 {
display: inline-block;
position: relative;
width: 100%;
min-height: 490px;
background-color: pink; }
@media (min-width: 768px) {
.container-info1 {
float: left;
left: 0;
top: 0;
height: 100%;
width: 50%; } }



.container-main1 {
display: inline-block;
position: relative;
width: 100%;
min-height: 490px;
background-color: white; }
@media (min-width: 768px) {
.container-main1 {
float: right;
right: 0;
top: 0;
height: 100%;
width: 50%; } }

最佳答案

不正确的 HTML 语法。首先,body标记是一次性创建的,您不能将它放在其他元素中。 <body>是主要的“包装器”。

正确的 HTML:

<html>
<head>
... metadata
</head>

<body>

<section class="first-section">
<div class="container-info">
<h1>first screen</h1>
</div>
<div class="container-main">
<h1>second screen</h1>
</div>
</section>

<section class="second-section">
<div class="container-info1">
<h1>first screen</h1>
</div>
<div class="container-main1">
<h1>second screen</h1>
</div>
</section>


</body>
</html>


至于灰框没有出现,可能是因为你用的是height: 100%没有确保 HTML/body 也有 height:100% .如果不将高度添加到 body,计算将无法正常进行。

灰框没有出现,因为父级(部分)有一个100% 的固定高度,而子级超出了该高度。要解决此问题,您可以更改 height:100%部分到 min-height: 100%

P.S 您的 CSS 可以简化为:

* {margin: 0; padding: 0;}

html, body {height:100%;}

section {
min-height: 100%;
text-align: center;
}

section > div {
display: block;
position: relative;
width: 100%;
min-height: 490px;
}

@media (min-width: 768px) {
section div {
height: 100%;
float: left;
width: 50%;
}
}

/* coloring */

.container-info {background: red;}
.container-main {background-color: grey;}
.container-info1 {background-color: pink;}
.container-main1 {background-color: white;}
<section class="first-section">
<div class="container-info">
<h1>first screen</h1>
</div>
<div class="container-main">
<h1>second screen</h1>
</div>
</section>

<section class="second-section">
<div class="container-info1">
<h1>first screen</h1>
</div>
<div class="container-main1">
<h1>second screen</h1>
</div>
</section>

关于html - 分屏麻烦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35970731/

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