gpt4 book ai didi

html - 如何让我的 flexbox 导航垂直显示?

转载 作者:太空宇宙 更新时间:2023-11-04 10:34:00 24 4
gpt4 key购买 nike

我正在尝试让我的导航( Logo 和链接)垂直显示在左侧,并且我的链接与 Logo 分开并且仅位于左下角。是否可以用 flexbox 来完成?

Codepen

<html>
<head>
<link rel="stylesheet" href="=style.css">
</head>
<body>


<header class="main-header">
<img class="logo"src="http://www.impexsolutions.org/images/world-icon.png">
<ul class="flex-nav">
<li><a href="index.html"><span><img src="http://icons.iconseeker.com/png/fullsize/summer-collection/web-1.png"></span></a></li>
<li><a href="index.html"><span><img src="http://icons.iconseeker.com/png/fullsize/summer-collection/web-1.png"></span></a></li>
<li><a href="index.html"><span><img src="http://icons.iconseeker.com/png/fullsize/summer-collection/web-1.png"></span></a></li>
<li><a href="index.html"><span><img src="http://icons.iconseeker.com/png/fullsize/summer-collection/web-1.png"></span></a></li>
<li><a href="index.html"><span><img src="http://icons.iconseeker.com/png/fullsize/summer-collection/web-1.png"></span></a></li>
</ul>
</header>

<div class="primary">
<h1></h1>
<p></p>
<p></p>
</div>

<div class="secondary">
<h1></h1>
<p></p>
<p></p>
</div>

</body>
</html>

样式.css

/*GLOBAL STYLES*/

*{padding: 0;margin: 0;box-sizing: border-box;}
ul{list-style: none;}
a{text-decoration: none;}

/*FLEX*/

.container{}
.primary{}
.secondary{}
.flex-nav{}
.flex-nav li{}
.flex-nav a{}
.flex-nav span{}

/*STYLES*/

body{background-color: #a7a7a7;}

/*IMAGE STYLE*/

.main-header,
.flex-nav {
display: flex;
flex-direction: row;
}
.main-header {
align-items:center;
flex-direction: row;
justify-content: space-between;}
.logo{max-width: 100px;max-height:100px;}
.flex-nav img{width:50px;}

最佳答案

阅读注释代码以获得解释。

/*.flex-nav is a flex item inside the flex container, so it should not have properties that belong to the flex container.*/
.main-header
/*.flex-nav*/ {
display: flex;
flex-direction: column; /*Column instead of row.*/
}
.main-header {
/*align-items:center; Do not need this, default is flex-start.*/
/*flex-direction: row; No need to have this property twice.*/
justify-content: space-between;
height: 1000px; /*Height, just for demonstrational purposes.*/
}

关于html - 如何让我的 flexbox 导航垂直显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36301790/

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