gpt4 book ai didi

html - CSS Flex 属性 'justify-content' 不工作

转载 作者:行者123 更新时间:2023-12-05 02:27:42 24 4
gpt4 key购买 nike

Justify-content: space-around 属性在第二个 flexbox (嵌套)中不起作用,这是为什么?代码:html-

<body>
<div class="navbar">
<div class="logo"><img src="redragon-logo.webp" alt="redragon-logo"></div>
<div class="otherlinks">
<div class="navbar-box1">HOME</div>
<div class="navbar-box2">PRODUCTS</div>
<div class="navbar-box3">BLOG</div>
<div class="navbar-box4">REVIEWS</div>
<div class="navbar-box5">CONTACT</div>
<div class="navbar-box6">
<select name="currency" id="currency" class="currency-label">CURRENCY
<option value="default" selected>Currency</option>
<option value="rupee">₹ Rupee</option>
<option value="yen">¥ Yen</option>
<option value="dollar">$ USD</option>
<option value="dollar">$ CAD</option>
</select>
</div>
</div>
</div>
</body>

CSS -

*{
margin: 0;
padding: 0;
}
/* navbar styling starts*/
.navbar{
padding: 0px 30px;
background-color: #111;
font-family: abel,arial;
display: flex;
height: 7vw;
justify-content: space-between;
align-items: center;
}
/* .logo{
display: flex;
justify-content: space-evenly;
} */
.otherlinks{
color: #ccc;
display: flex;
justify-content: space-around;
}
select{
padding: 0px 3px ; /*design this select input*/
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Redragon</title>
<link rel="stylesheet" href="website.css">
</head>
<body>
<div class="navbar">
<div class="logo"><img src="redragon-logo.webp" alt="redragon-logo"></div>
<div class="otherlinks">
<div class="navbar-box1">HOME</div>
<div class="navbar-box2">PRODUCTS</div>
<div class="navbar-box3">BLOG</div>
<div class="navbar-box4">REVIEWS</div>
<div class="navbar-box5">CONTACT</div>
<div class="navbar-box6">
<select name="currency" id="currency" class="currency-label">CURRENCY
<option value="default" selected>Currency</option>
<option value="rupee">₹ Rupee</option>
<option value="yen">¥ Yen</option>
<option value="dollar">$ USD</option>
<option value="dollar">$ CAD</option>
</select>
</div>
</div>
</div>
</body>
</html>

最佳答案

这是因为默认宽度是“auto”,占用尽可能少的空间。如果您在此类中添加宽度:

.otherlinks{
color: #ccc;
display: flex;
justify-content: space-around;
width: 600px;
}

这应该可以解决您的问题,您可以选择最适合您的宽度值。

我邀请您查阅此链接以找到最佳的宽度单位: CSS values and units

我建议你:“大众”

结果:

*{
margin: 0;
padding: 0;
}
/* navbar styling starts*/
.navbar{
padding: 0px 30px;
background-color: #111;
font-family: abel,arial;
display: flex;
height: 7vw;
justify-content: space-between;
align-items: center;
}
/* .logo{
display: flex;
justify-content: space-evenly;
} */
.otherlinks{
color: #ccc;
display: flex;
justify-content: space-around;
width: 600px;
}
select{
padding: 0px 3px ; /*design this select input*/
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Redragon</title>
<link rel="stylesheet" href="website.css">
</head>
<body>
<div class="navbar">
<div class="logo"><img src="redragon-logo.webp" alt="redragon-logo"></div>
<div class="otherlinks">
<div class="navbar-box1">HOME</div>
<div class="navbar-box2">PRODUCTS</div>
<div class="navbar-box3">BLOG</div>
<div class="navbar-box4">REVIEWS</div>
<div class="navbar-box5">CONTACT</div>
<div class="navbar-box6">
<select name="currency" id="currency" class="currency-label">CURRENCY
<option value="default" selected>Currency</option>
<option value="rupee">₹ Rupee</option>
<option value="yen">¥ Yen</option>
<option value="dollar">$ USD</option>
<option value="dollar">$ CAD</option>
</select>
</div>
</div>
</div>
</body>
</html>

关于html - CSS Flex 属性 'justify-content' 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73002394/

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