gpt4 book ai didi

html - Flexboxs child 溢出 parent

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

我见过几个像我这样的问题,但似乎没有一个得到成功回答。我的问题可能很简单,但我没有弄错。

我在彼此之间使用了多个 flexbox。当我更改浏览器大小时,它应该以相同的方式调整大小。但在某一时刻, children 溢出了 parent 的 flexbox - 丑陋的

因为我没有发现我的错误,所以我开始了一个新的 HTML 文档 - 我仍然有错误。“游戏盒”的 children 不按我的意愿行事。

这是一个 fiddle :Live-Demo

感谢您的帮助 - RoetzerBub

html , body, main {
margin: 0;
padding: 0;
min-height: 100%;
min-width: 100%;
}

body{
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
}
header, footer{
display: flex;
min-width: 100%;
justify-content: center;
}
header{
flex-shrink: 0;
background-color: #cc0000;
color: white;
z-index: 10;
margin-bottom: 10px;
}

main{
display: flex;
justify-content: center;
align-items: center;
}

footer{
background-color: #444444;
color: white;
flex-shrink: 0;
z-index: 10;
margin-top: 10px;
}
/*as*/
.gamebox{
display: flex;
flex-direction: row;
min-width: 30%;
max-width: 45%;
border: 2px solid #b30000;
justify-content: space-between;
align-items: center;
}

.gb_left, .gb_center, .gb_right{
margin: 2%;
justify-content: space-around;
background-color: yellow;
}

.gb_left{
display: flex;
justify-content: space-between;
align-items: center;
flex-grow: 1;
}

.gb_right{
display: flex;
justify-content: space-between;
align-items: center;
flex-grow: 1;

}

.gb_center{
display: flex;
flex-direction: column;
justify-content: space-between;
}
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="flexstyle.css">
</head>
<body>
<header>HEADER</header>
<main>

<div class="gamebox">
<div class="gb_left">
FLAG
TEAM-A
</div>
<div class="gb_center">
type<br/>
SCORE<br/>
date
</div>
<div class="gb_right">
TEAM-B
FLAG
</div>

</div>

</main>
<footer>FOOTER</footer>
</body>
</html>

最佳答案

在这里再次将子项定义为 flex 容器并没有真正意义 - 它们中没有元素(div 或 span),只有文本(即没有任何东西可以用作 flex 元素)。

在下面的 fiddle 中,我删除了所有这些并使用了以下 CSS 设置:

 .gamebox{
display: flex;
flex-direction: row;
min-width: 30%;
max-width: 45%;
border: 2px solid #b30000;
justify-content: space-between;
align-items: center;
}

.gb_left, .gb_center, .gb_right{
margin: 2%;
background-color: yellow;
min-width: 29%;
word-wrap: break-word;
}

最后一个确保当一个词的长度超过其容器的宽度时,它就被破坏了。

这是你的 fiddle 的分支:https://jsfiddle.net/o6wxy5z7/

关于html - Flexboxs child 溢出 parent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37286979/

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