我正在尝试以...实际汉堡的形状制作汉堡菜单。 我唯一的小问题与扩展菜单上的“芝麻”背景图像有关。我设法找到了一个使用径向渐变图像的代码段,当您单击菜单图标并且菜单下拉时,直到完成转换后,才会显示白色的圆点背景图像。
我专门查看的代码是#menuList
选择器上的背景图像行。
body {
margin: 0;
padding: 0;
font-family: 'Open Sans', sans-serif;
}
a {
text-decoration: none; /* no underlines */
}
#menuToggle {
display: block;
position: absolute;
height: 36px;
width: 36px;
top: 20px;
right: 20px;
z-index: 1;
color: #e5cb7a;
-webkit-user-select: none;
user-select: none; /* don't let 'em select text */
}
/* Style the "checkbox" used to activate the hamburger menu */
#menuToggle input {
display: block;
position: absolute;
height: 32px;
width: 32px;
top: -7px;
right: -7px;
cursor: pointer; /* make the burger pointy */
opacity: 0; /* hide the checkbox */
z-index: 2;
}
/* Make the menu look like a triangle shape by adding a thick border next to it. */
#menuToggle::before {
content: '';
position: absolute;
top: -10px;
right: -10px;
border-color: #e5cb7a; /* Bun-color */
border-style: solid;
border-width: 22px;
border-radius: 8px;
}
/* Style the three spans that make up the hamburger */
#menuToggle span {
display: block;
position: relative;
height: 4px;
width: 30px;
margin: 0px 0px 6px 9px;
border-radius: 3px;
z-index: 1;
transition: transform 0.5s,
opacity 0.55s ease;
}
/* Color the top span a lettuce color */
#topBun {
background: #32c704;
}
/* Color the middle span a burger color */
#meat {
background: #450101;
}
/* Color the bottom span a ketchup color */
#bottomBun {
background: #ec3521;
}
/* Move the top bun down 10px (its height), then turn it */
#menuToggle input:checked ~ #topBun {
background: #450101;
transform: translate(0px, 10px) rotate(45deg);
}
#menuToggle input:checked ~ #meat {
opacity: 0;
transform: rotate(0deg);
}
/* Move the bottom bun up 10px (its height), then turn it */
#menuToggle input:checked ~ #bottomBun {
background: #450101;
transform: translate(0px,-10px) rotate(-45deg);
}
#menuList {
display: inline-block;
position: absolute;
top: 0px;
right: 0px;
height: 100px;
width: 100px;
margin: -20px -20px 0 0;
padding: 50px 90px 0 0;
background: transparent;
list-style-type: none; /* no bullets, weapon-free zone */
/*-webkit-font-smoothing: antialiased;*/
/* Sesame seeds for the top bun of the expanded menu */
background-image: radial-gradient(white 20%, transparent 0);
background-size: 15px 12px;
background-position: 0 12px, 10px 10px;
/* Shrink the actual menu list until the hamburger is opened */
transform: translate(0px,-65px) scale(1,0.00001);
transition: transform 1.5s, background 1.5s;
}
/* Make a larger burger bun shape around the expanded hamburger menu */
#menuList::before {
content: '';
position: absolute;
top: 10px;
right: 10px;
border-style: solid;
border-width: 90px;
border-radius: 10px;
z-index: -1;
}
#menuList li {
padding: 3px 5px;
font-size: 22px;
text-align: center;
width: 170px;
color: #ffffff;
}
#menuList li:hover {
font-weight: bold;
letter-spacing: 2px;
}
/* Color the first menu option a lettuce color */
#about {
background: #32c704;
}
/* Color the second menu option a burger color */
#info {
background: #450101;
}
/* Color the third menu option a ketchup color */
#contact {
background: #ec3521;
}
/* Transform the list back to its normal "visible" size when the input is checked */
#menuToggle input:checked ~ ul {
transform: none;
}
<nav>
<div id="menuToggle">
<input type="checkbox" />
<span id="topBun"></span>
<span id="meat"></span>
<span id="bottomBun"></span>
<ul id="menuList">
<a href="#"><li id="about">ABOUT</li></a>
<a href="#"><li id="info">INFO</li></a>
<a href="#"><li id="contact">CONTACT</li></a>
</ul>
</div>
</nav>
我已经放慢笔的过渡,以更好地说明问题所在。
如何使背景始终显示,而不是仅在菜单完全展开时显示?
答案 0 :(得分:1)
您展开的菜单“小圆面包”是边框,而不是背景,而背景是折叠的汉堡面包。
body {
margin: 0;
padding: 0;
font-family: 'Open Sans', sans-serif;
}
a {
text-decoration: none;
/* no underlines */
}
#menuToggle {
display: block;
position: absolute;
height: 36px;
width: 36px;
top: 20px;
right: 20px;
z-index: 1;
color: #e5cb7a;
-webkit-user-select: none;
user-select: none;
/* don't let 'em select text */
}
/* Style the "checkbox" used to activate the hamburger menu */
#menuToggle input {
display: block;
position: absolute;
height: 32px;
width: 32px;
top: -7px;
right: -7px;
cursor: pointer;
/* make the burger pointy */
opacity: 0;
/* hide the checkbox */
z-index: 2;
}
/* Make the menu look like a triangle shape by adding a thick border next to it. */
#menuToggle::before {
content: '';
position: absolute;
top: -10px;
right: -10px;
border-color: #e5cb7a;
/* Bun-color */
border-style: solid;
border-width: 22px;
border-radius: 8px;
}
/* Style the three spans that make up the hamburger */
#menuToggle span {
display: block;
position: relative;
height: 4px;
width: 30px;
margin: 0px 0px 6px 9px;
border-radius: 3px;
z-index: 1;
transition: transform 0.5s, opacity 0.55s ease;
}
/* Color the top span a lettuce color */
#topBun {
background: #32c704;
}
/* Color the middle span a burger color */
#meat {
background: #450101;
}
/* Color the bottom span a ketchup color */
#bottomBun {
background: #ec3521;
}
/* Move the top bun down 10px (its height), then turn it */
#menuToggle input:checked~#topBun {
background: #450101;
transform: translate(0px, 10px) rotate(45deg);
}
#menuToggle input:checked~#meat {
opacity: 0;
transform: rotate(0deg);
}
/* Move the bottom bun up 10px (its height), then turn it */
#menuToggle input:checked~#bottomBun {
background: #450101;
transform: translate(0px, -10px) rotate(-45deg);
}
#menuList {
display: inline-block;
position: absolute;
top: 0px;
right: 0px;
height: 100px;
width: 100px;
margin: -20px -20px 0 0;
padding: 50px 90px 0 0;
background: transparent;
list-style-type: none;
/* no bullets, weapon-free zone */
/*-webkit-font-smoothing: antialiased;*/
/* Shrink the actual menu list until the hamburger is opened */
transform: translate(0px, -65px) scale(1, 0.00001);
transition: transform 1.5s;
}
/* Make a larger burger bun shape around the expanded hamburger menu */
#menuList::before {
content: '';
position: absolute;
top: 10px;
right: 10px;
bottom: -30px;
left: 0;
border-radius: 10px;
z-index: -1;
/* Sesame seeds for the top bun of the expanded menu */
background-color: #e5cb7a;
background-image: radial-gradient(white 20%, transparent 0);
background-size: 15px 12px;
background-position: 0 12px, 10px 10px;
}
#menuList li {
padding: 3px 5px;
font-size: 22px;
text-align: center;
width: 170px;
color: #ffffff;
}
#menuList li:hover {
font-weight: bold;
letter-spacing: 2px;
}
/* Color the first menu option a lettuce color */
#about {
background: #32c704;
}
/* Color the second menu option a burger color */
#info {
background: #450101;
}
/* Color the third menu option a ketchup color */
#contact {
background: #ec3521;
}
/* Transform the list back to its normal "visible" size when the input is checked */
#menuToggle input:checked~ul {
transform: translate3d(0,0,0);
}
<nav>
<div id="menuToggle">
<input type="checkbox" />
<span id="topBun"></span>
<span id="meat"></span>
<span id="bottomBun"></span>
<ul id="menuList">
<a href="#">
<li id="about">ABOUT</li>
</a>
<a href="#">
<li id="info">INFO</li>
</a>
<a href="#">
<li id="contact">CONTACT</li>
</a>
</ul>
</div>
</nav>