gpt4 book ai didi

html - 纯 CSS 菜单不在顶部

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

我在使用纯 CSS 样式时遇到问题,无法在网页左侧创建菜单。这是我打开文件时得到的。我也在使用 Flask 以防万一。

这是我的网站的样子:My Site (in Firefox Quantum 61.0.1)

这是我用来创建这个文件的代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> <!-- Check Compattibility with Pure CSS -->
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- Check Compattibility with Pure CSS -->

<meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Check Compattibility with Pure CSS -->

<link rel="stylesheet" href="https://unpkg.com/purecss@1.0.0/build/pure-min.css" integrity="sha384-nn4HPE8lTHyVtfCBi5yW9d20FjT8BJwUXyWZT9InLYax14RDjBj46LmSztkmNP9w" crossorigin="anonymous">
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> -->

<title>Home</title>

</head>
<style>
.custom-restricted-width {
/* To limit the menu width to the content of the menu: */
/* display: inline-block; */
/* Or set the width explicitly: */
width: 10em;
}
</style>
<div class="pure-menu custom-restricted-width">
<!-- <a href="#" class="pure-menu-link pure-menu-heading">Home</a> -->
<span class="pure-menu-heading">My Site</span>

<ul class="pure-menu-list">
<li class="pure-menu-item"><a href="#" class="pure-menu-link">Home</a></li>
<li class="pure-menu-item"><a href="newuser/register" class="pure-menu-link">Register</a></li>
</ul>
</div>
<body bgcolor="black" text="white">
<div class="container">
<div class="pure-u-24-24">
<img src="/static/images/Logo.png" class="pure-img" />
<h1>Welcome Home</h1><br><br><br>
<p>Please continue to check back for updates!</p><br><br>
<p>More comming soon...</p>
</div>
</div>
</body>

</html>

我是 Pure CSS 的新手,我正在尝试创建一个优雅的菜单,它位于页面的一侧,类似于您在他们网站的菜单页面上找到的菜单:https://purecss.io/menus/

最佳答案

首先,您的菜单需要在 <body></body> 范围内标签。在这里查看:

<body bgcolor="black" text="white">
<div class="pure-menu custom-restricted-width">
<span class="pure-menu-heading">My Site</span>
<ul class="pure-menu-list">
<li class="pure-menu-item">
<a href="#" class="pure-menu-link">Home</a>
</li>
<li class="pure-menu-item">
<a href="newuser/register" class="pure-menu-
link">Register</a>
</li>
</ul>
</div>
<div class="container">
<div class="pure-u-24-24">
<img src="/static/images/Logo.png" class="pure-img" />
<h1>Welcome Home</h1>
<br>
<br>
<br>
<p>Please continue to check back for updates!</p>
<br>
<br>
<p>More comming soon...</p>
</div>
</div>
</body>

要创建与 PureCSS 类似的侧边栏菜单,只需添加以下内容:

.custom-restricted-width {
width: 10em;
height: 100vh;
position: fixed;
z-index: 9;
bottom: 0;
position: fixed;
top: 0;
left: 0;
bottom: 0;
z-index: 1000;
background: #191818;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}

对于容器你可以添加:

.container {
padding-left: 15em;
}

完整代码如下:

<head>
<meta charset="utf-8">
<!-- Check Compattibility with Pure CSS -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- Check Compattibility with Pure CSS -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Check Compattibility with Pure CSS -->
<link rel="stylesheet" href="https://unpkg.com/purecss@1.0.0/build/pure-min.css" integrity="sha384-nn4HPE8lTHyVtfCBi5yW9d20FjT8BJwUXyWZT9InLYax14RDjBj46LmSztkmNP9w" crossorigin="anonymous">
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> -->
<title>Home</title>
<style>
body {
background-color: black;
color: white;
}

.pure-menu {
width: 10em;
height: 100vh;
position: fixed;
z-index: 9;
bottom: 0;
position: fixed;
top: 0;
left: 0;
bottom: 0;
z-index: 1000;
background: #191818;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}

.container {
padding-left: 15em;
}
</style>
</head>

<body>
<div class="pure-menu custom-restricted-width">
<!-- <a href="#" class="pure-menu-link pure-menu-heading">Home</a> -->
<span class="pure-menu-heading">My Site</span>
<ul class="pure-menu-list">
<li class="pure-menu-item"><a href="#" class="pure-menu-link">Home</a></li>
<li class="pure-menu-item"><a href="newuser/register" class="pure-menu-link">Register</a></li>
</ul>
</div>
<div class="container">
<div class="pure-u-24-24">
<img src="/static/images/Logo.png" class="pure-img" />
<h1>Welcome Home</h1>
<br>
<br>
<br>
<p>Please continue to check back for updates!</p>
<br>
<br>
<p>More comming soon...</p>
</div>
</div>
</body>

</html>

关于html - 纯 CSS 菜单不在顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51333593/

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