gpt4 book ai didi

html - 无法让 align-self 在 flexbox 容器中工作

转载 作者:行者123 更新时间:2023-11-28 16:00:26 25 4
gpt4 key购买 nike

我的代码如下。

/* Global */
* {
box-sizing: border-box;
font-family: 'Ubuntu', sans-serif;
}

/* Container */
#container {
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
}

/* About Me */
.about-me {
width: 100vw;
height: 50vh;
background-color: #9b59b6;
}

.my-information {
text-align: center;
align-self: flex-end;
}

/* Blog Posts */
.blog-posts {
width: 100vw;
height: 50vh;
background-color: #3498db;
}


/* Media Query (Desktop And Bigger) */
@media (min-width: 1100px) {
/* Container */
#container {
flex-direction: row;
}

/* About Me */
.about-me {
height: 100vh;
}

/* Blog Posts */
.blog-posts {
height: 100vh;
}
}
<!DOCTYPE html>
<html>

<head>
<!-- Meta -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Title -->
<title>Saad Al-Sabbagh</title>

<!-- CSS -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Ubuntu">
<link rel="stylesheet" href="css/main.css">
</head>

<body>

<!-- Container -->
<div id="container">
<div class="about-me">
<div class="my-information">
<h1>A person</h1>
<p>Front-End Web Developer, Blogger and an author on
<a href="#">SitePoint</a>.</p>
</div>
</div>

<div class="blog-posts">

</div>
</div>

</body>

</html>

我正在尝试使用 flexbox 创建一个简单的两栏网站,我听过很多关于我不应该使用 flexbox 来完成网站布局的坏故事,但我相信布局这么简单最好使用 flex 盒子。

我有一个 div,正如您在类 .my-information 中看到的那样,我试图将其 self 对齐到 flex 容器 .about-me 的底部,但它似乎不起作用。

最佳答案

您还需要在 about div 上添加 display:flex 并使您可以使用 justify-content:center 的元素居中。

#container {
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
}
.about-me {
width: 100vw;
height: 50vh;
display: flex; /*Added*/
justify-content: center; /*Added*/
background-color: #9b59b6;
}
.my-information {
text-align: center;
align-self: flex-end;
}
.blog-posts {
width: 100vw;
height: 50vh;
background-color: #3498db;
}
<div id="container">
<div class="about-me">
<div class="my-information">
<h1>A person</h1>
<p>Front-End Web Developer, Blogger and an author on
<a href="#">SitePoint</a>.</p>
</div>
</div>

<div class="blog-posts"></div>
</div>

关于html - 无法让 align-self 在 flexbox 容器中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40249564/

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