css - 菜单不会全屏显示
问题描述
我已经为我的页面制作了一个子菜单,现在我希望它全屏显示,我该怎么做?我用过width: 100%
,但它不起作用。如何获得全宽?设置为padding/margin
似乎0
也不起作用
body{
font-family: 'Archivo', sans-serif;
}
.dropbtn {
background-color: yellow;
color: white;
font-size: 16px;
border: none;
width: 100%;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {background-color: #ddd;}
.dropdown:hover .dropdown-content {display: block;}
.dropdown:hover .dropbtn {background-color: yellow;}
div {
width: 35px;
height: 5px;
background-color: white;
margin: 6px 0;
}
<!DOCTYPE html>
<head>
<title>Rwebsite</title>
<link rel="stylesheet" type="text/css" href="website.css">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Archivo&display=swap" rel="stylesheet">
<meta name="vieuwport" content="width=device-width.initial-scale=1">
</head>
<body>
<div class="dropdown">
<button class="dropbtn">
<div></div>
<div></div>
<div></div>
</button>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
</body>
</html>
divs
我用来制作“菜单图标”的东西是空的。
解决方案
您正在使用宽度 100%,但它的父级没有定义宽度,所以它不起作用。尝试将宽度:100% 更改为宽度:100vw。这将占用视口宽度的 100%* https://www.w3schools.com/cssref/css_units.asp
推荐阅读
- kubernetes - Istio 是否支持代理协议?
- excel - 在保护工作表中允许插入行和列,但仍然弹出警告消息,如何阻止?
- sql - SQL:连接两个表,取所有行并设置默认值
- listview - 用条件对本机列表视图做出反应
- swift - 带有 asyncTask 的完成处理程序
- mysql - MYSQL - 更新/内部连接
- google-cloud-platform - 只为大客户承诺使用折扣?
- spring - 在 Spring Boot 应用程序中,每次方法调用都会调用 Aspect 类中的方法两次
- c# - 敌人不会相互碰撞
- file - Linux - 1973 年没有权限和时间戳的文件;如何?