gpt4 book ai didi

html - 遇到 flexbox 属性问题

转载 作者:行者123 更新时间:2023-11-28 01:43:14 24 4
gpt4 key购买 nike

我有几个问题要解决,那就是1- 为什么 Logo 类属性不起作用?2- 为什么类(class)标题没有向右移动,即 justify-content: flex-end 不工作或者还有什么其他方法可以做到这一点?3- 我必须写 display: flex;在所有父类或简单的容器中,其中包含所有父类就足够了吗?4- 如果我使用 display: flex 会有什么影响;在所有父类上?非常感谢

---HTML---

    <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name = "viewport" content = "width=device-width", initial-scale = 1.0>
<title>My Portfolio</title>
<link rel="stylesheet" type="text/css" href="port.css">
</head>
<body>
<div class="container">
<div class="header">
<div id="logo"> Logo </div>
<div class="title">JAMES O BRAIN
<div class="sub-title">FRONT-END MONK</div> </div>
</div>
<div class="container2">
<div class="centre-picture">Central Pic</div>
<div class="left-boxs">
<div class="blue-box">Blue Box</div>
<div class="grey-box">Grey Box</div>
<div class="green-box">Green Box</div>
</div>
</div>
<div class="bottom-boxs">
<div class="featured-work">Featured Work</div>
<div class="appify">APPIFY</div>
<div class="sunflower">SUNFLOWER</div>
<div class="bokeh">BOKEH</div>
</div>
</div>
</body>
</html>

---CSS---

    .container {
display: flex;
flex-direction: column;
border: 5px solid black;
margin: 10px;
padding: 50px;
}
.header {
display: flex;
border: 5px solid green;
}
.logo {
/* why these all properties not working at all ? */
border: 3px solid black;
padding: 10px;
margin: 10px;
}
.title {
border: 3px solid orange;
justify-content: flex-end; /* why this property not working, how can i get this to right ?*/
padding: 10px;
margin: 10px;
}
.sub-title {
border: 3px solid black;
padding: 5px;
margin: 5px
}
.container2 {
display: flex;
border: 5px solid red;
margin: 10px;
padding: 10px;
height: 300px;

}
.centre-picture {
border: 3px solid black;
margin: 10px;
padding: 10px;
}
.left-boxs {
border: 3px solid goldenrod;
margin: 10px;
padding: 10px;
order: -1;
}
.green-box {
background-color: green;
padding: 5px;
margin: 5px
}
.blue-box {
background-color: blue;
padding: 5px;
margin: 5px
}
.grey-box {
background-color: grey;
padding: 5px;
margin: 5px
}
.bottom-boxs {
display: flex;
border: 5px solid blue;
}
.appify {
border: 3px solid black;
margin: 10px;
padding: 10px;
}
.sunflower {
border: 3px solid black;
margin: 10px;
padding: 10px;
}
.bokeh {
border: 3px solid black;
margin: 10px;
padding: 10px;
}

最佳答案

  1. 正如 Daniel 所说,您应该确保您没有混淆标记/CSS 中的 #id.class 选择器。在您的样式表中,您应该使用 #logo 而不是 .logo

  2. 您可以通过多种方式对齐页眉中的元素。在下面的示例中,我将 justify-content: space-between; 附加到 .header div,这将使任何直接子元素与它们之间的剩余空间对齐.还有其他方法可以做到这一点……这只是一种选择。您可以尝试调整边距、填充和其他 flexbox 值,看看什么最适合您。

  3. 给容器 display: flex 将影响容器内的所有子元素,但不每个子元素中的内容。例如:如果你有一个包含三个 div 元素的容器,你给容器 display: flex; justify-content: center; 这将使每个 div 水平居中,但不是每个 div 中的文本、图像等.在你的情况下,至少在这个例子中,是的,你需要添加 display: flex; 到标题内的每个 div,以便将 flexbox 属性应用于里面的文本。

希望对您有所帮助。有关示例,请参见下面的代码片段。祝你好运!

  

.container {
display: flex;
flex-direction: column;
border: 5px solid black;
width: 80%;
padding: 50px;
}

.header {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
border: 5px solid green;
padding: 10px;
}

#logo {
display: flex;
justify-content: center;
align-items: center;
border: 3px solid black;
padding: 10px;
}

.title {
display: flex;
justify-content: center;
align-items: center;
border: 3px solid orange;
padding-left: 10px;
}

.sub-title {
display: flex;
justify-content: center;
align-items: center;
margin: 10px;
padding: 10px;
border: 3px solid black
}
<div class="container">
<div class="header">
<div id="logo">Logo</div>
<div class="title">JAMES O BRAIN
<div class="sub-title">
FRONT-END MONK
</div>
</div>
</div>
</div>

关于html - 遇到 flexbox 属性问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50327384/

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