【发布时间】:2018-10-17 04:13:44
【问题描述】:
请参考this image。这会让事情变得更容易理解,而不是看代码。
我正在尝试设计一个始终位于页面中心的菜单。
菜单应仅在边距完全消失后缩小。
起初它看起来很简单,但令我沮丧的是,我了解到 CSS 在缩小页面时会尝试将菜单和边距压缩到一个小区域。
body, html
{
overflow: hidden; /* Prevent browser from displaying scroll-bars */
background-color: #f1f1f1;
/* Force the HTML and Body to fill entire window */
width: 100%;
height: 100%;
/* ------------------------------------------------------------------------- */
}
/* Removes margins and padding on all HTML-CSS elements. */
/* This is so that we don't run into any unecessary whitespace during website design*/
body, html, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset, input, textarea, p, blockquote, th, td
{
margin: 0px;
padding: 0px;
}
body
{
position: relative;
z-index: 0;
}
div.Top-Margin
{
position: relative;
z-index: 1;
/* background-color: #f1f1f1; */
background-color: orange; /* TODO: visibility purposes, only for TESTING */
height: 25%;
}
div.Center-Margin
{
position: relative;
z-index: 1;
background-color: pink; /* TODO: visibility purposes, only for TESTING */
height: 50%;
}
div.Bottom-Margin
{
position: relative;
z-index: 1;
/* background-color: #f1f1f1; */
background-color: yellow; /* TODO: Visibility purposes, only for TESTING */
width: 100%;
height: 25%;
}
/* Consistent style between desktop and mobile*/
div.Menu-Container
{
position: absolute;
top: 25%;
left: 45%;
z-index: 2;
}
@keyframes rainbow-border
{
0% {border-color: #ff0000;}
10% {border-color: #ff8000;}
20% {border-color: #ffff00;}
30% {border-color: #80ff00;}
40% {border-color: #00ff00;}
50% {border-color: #00ff80;}
60% {border-color: #00ffff;}
70% {border-color: #0080ff;}
80% {border-color: #0000ff;}
90% {border-color: #8000ff;}
100% {border-color: #ff0080;}
}
/*---------------*/
/*---------------*/
/* The side navigation menu */
div.Menu-Options
{
margin-top: 416.5px;
padding: 0;
width: 300px;
background-color: #ffffff;
position: fixed;
overflow: auto;
}
/* Menu Buttons Content */
div.Menu-Options a
{
display: block;
color: black;
padding: 16px;
text-decoration: none;
}
/* Active Menu Button */
div.Menu-Options a.suggested
{
background-color: #4CAF50;
color: #ffffff;
}
/* Inactive Menu Buttons: Hover */
div.Menu-Options a:hover:not(.suggested)
{
background-color: #555555;
color: #ffffff;
}
/*---------------*/
/*---------------*/
@media screen
{
div.Menu-Container
{
/* Menu size remains consistent with page size */
width: 300px;
height: 621.5px;
background-color: #ffffff;
/* Border-Style */
border-top-style: solid;
border-bottom-style: solid;
border-right-style: dashed;
border-left-style: dashed;
animation: rainbow-border 2s infinite;
border-color: #00ffff; /* Required incase browser does not support animated border */
border-width: 3px;
box-shadow: 0 0 30px rgba(0, 0, 0, 0.4);
}
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style-desktop.css">
<title>Pacman-Esque: Main Menu</title>
</head>
<body>
<div class=Top-Margin>
<p>...</p>
</div>
<div class=Center-Margin>
<p>...</p>
</div>
<div class=Bottom-Margin>
<p>...</p>
</div>
<!-- Main Menu -->
<div class=Menu-Container>
<div class=Animated-Logo>
<!-- Will contain animated logo -->
</div>
<!-- Menu Options -->
<div class=Menu-Options>
<a class="suggested" href="#">Start Game</a>
<a href="#">Highscores</a>
<a href="#">Settings</a>
<a href="#">About</a>
</div>
</div>
</body>
</html>
【问题讨论】: