我有侧边栏菜单。 #menu li a
有一个transform: scale(1.1)
我想在li
内缩放文本和图标,并保持宽度相同
我试过overflow:hidden
,但子菜单没有显示
任何帮助?
.page-container {
min-width: 1260px;
position: relative;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
margin: 0px auto;
}
.content {
max-width: 800px;
min-width: 600px;
display: block;
padding: 50px;
margin: 50px auto;
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
background-color: #ffffff;
overflow: hidden;
}
.page-container.sidebar-collapsed {
padding-right: 65px;
transition: all 100ms linear;
transition-delay: 300ms;
}
.page-container.sidebar-collapsed-back {
padding-right: 280px;
transition: all 100ms linear;
}
.page-container.sidebar-collapsed .sidebar-menu {
width: 65px;
transition: all 100ms ease-in-out;
transition-delay: 300ms;
}
.page-container.sidebar-collapsed-back .sidebar-menu {
width: 280px;
transition: all 100ms ease-in-out;
}
.page-container.sidebar-collapsed .sidebar-icon {
transition: all 300ms ease-in-out;
}
.page-container.sidebar-collapsed-back .sidebar-icon {
transition: all 300ms ease-in-out;
}
.page-container.sidebar-collapsed .logo {
padding: 21px;
height: 136px;
box-sizing: border-box;
transition: all 100ms ease-in-out;
transition-delay: 300ms;
}
.page-container.sidebar-collapsed-back .logo {
width: 100%;
padding: 21px;
height: 136px;
box-sizing: border-box;
transition: all 100ms ease-in-out;
}
.page-container.sidebar-collapsed #logo {
opacity: 0;
transition: all 200ms ease-in-out;
}
.page-container.sidebar-collapsed-back #logo {
opacity: 1;
transition: all 200ms ease-in-out;
transition-delay: 300ms;
}
.page-container.sidebar-collapsed #menu span {
opacity: 1;
transition: all 50ms linear;
position:relative;
top:5px;
right:10px;
}
.page-container.sidebar-collapsed-back #menu span {
opacity: 1;
transition: all 200ms linear;
transition-delay: 300ms;
top: 17px;
right: 75px;
position: absolute;
}
.sidebar-menu {
position: fixed;
float: left;
width: 280px;
top: 0;
right: 0;
bottom: 0;
background-color: #303641;
color: #aaabae;
font-family: "Segoe UI";
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.5);
z-index: 1;
}
#menu {
list-style: none;
padding: 0;
margin: 0 0 20px;
}
#menu li {
position: relative;
margin: 0;
font-size: 12px;
border-bottom: 1px solid rgba(69, 74, 84, 0.7);
padding: 0;
}
#menu li ul {
opacity: 0;
height: 0px;
}
a:hover {
transition: all 200ms ease-in-out;
}
#menu li a {
text-decoration: none;
font-style: normal;
font-weight: 400;
position: relative;
display: block;
padding: 10px 15px;
color: #FFFFFF;
white-space: nowrap;
z-index: 2;
transition: 200ms;
}
#menu li a:hover {
color: #ffffff;
background-color: #333944;
transition: all 250ms ease-in-out;
transform: scale(1.3);
}
#menu li.active > a {
background-color: #2b303a;
color: #ffffff;
}
#menu ul li {
background-color: #2b303a;
}
#menu ul {
list-style-type: none;
margin: 0;
padding: 0;
}
#menu li ul {
position: absolute;
visibility: hidden;
right: 100%;
top: -1px;
background-color: #2b303a;
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.5);
opacity: 0;
transition: opacity 0.1s linear;
border-top: 1px solid rgba(69, 74, 84, 0.7);
}
#menu li:hover > ul {
visibility: visible;
opacity: 1;
}
#menu li li ul {
right: 100%;
visibility: hidden;
top: -1px;
opacity: 0;
transition: opacity 0.1s linear;
}
#menu li li:hover ul {
visibility: visible;
opacity: 1;
}
#menu .fa {
margin-right: 5px;
font-size: 30px;
}
.logo {
width: 100%;
padding: 21px;
box-sizing: border-box;
height: 136px;
}
.sidebar-icon {
position: relative;
right: -6px;
float: right;
border: 1px solid #454a54;
text-align: center;
line-height: 1;
font-size: 18px;
padding: 6px 8px;
border-radius: 3px;
color: #FFFFFF;
background-clip: padding-box;
text-shadow: 4px 4px 6px rgba(0, 0, 0, 0.4);
}
<div class="page-container sidebar-collapsed">
<div class="sidebar-menu">
<div style="border-top:1px solid rgba(69, 74, 84, 0.7)"></div>
<div class="menu">
<ul id="menu">
<li id="menu-home"><a href="#"><i class="fa fa-home"></i><span>first</span></a></li>
<li><a href="#"><i class="fa fa-share-alt"></i><span class="fa fa-angle-left"
style="float: left; position:unset;"></span><span>second</span></a>
<ul>
<li><a href="#"><i class="fa fa-facebook"></i> Facebook</a></li>
<li><a href="#"><i class="fa fa-twitter"></i> Twitter</a></li>
<li><a href="#"><i class="fa fa-pinterest"></i> Pinterest</a></li>
</ul>
</li>
<li><a href="#"><i class="fa fa-history"></i><span>blog</span></a></li>
<li><a href="#"><i class="fa fa-gears"></i><span>settings</span></a></li>
</ul>
</div>
</div>
</div>
答案 0 :(得分:1)
.page-container {
min-width: 1260px;
position: relative;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
margin: 0px auto;
}
.content {
max-width: 800px;
min-width: 600px;
display: block;
padding: 50px;
margin: 50px auto;
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
background-color: #ffffff;
overflow: hidden;
}
.page-container.sidebar-collapsed {
padding-right: 65px;
transition: all 100ms linear;
transition-delay: 300ms;
}
.page-container.sidebar-collapsed-back {
padding-right: 280px;
transition: all 100ms linear;
}
.page-container.sidebar-collapsed .sidebar-menu {
width: 65px;
transition: all 100ms ease-in-out;
transition-delay: 300ms;
}
.page-container.sidebar-collapsed-back .sidebar-menu {
width: 280px;
transition: all 100ms ease-in-out;
}
.page-container.sidebar-collapsed .sidebar-icon {
transition: all 300ms ease-in-out;
}
.page-container.sidebar-collapsed-back .sidebar-icon {
transition: all 300ms ease-in-out;
}
.page-container.sidebar-collapsed .logo {
padding: 21px;
height: 136px;
box-sizing: border-box;
transition: all 100ms ease-in-out;
transition-delay: 300ms;
}
.page-container.sidebar-collapsed-back .logo {
width: 100%;
padding: 21px;
height: 136px;
box-sizing: border-box;
transition: all 100ms ease-in-out;
}
.page-container.sidebar-collapsed #logo {
opacity: 0;
transition: all 200ms ease-in-out;
}
.page-container.sidebar-collapsed-back #logo {
opacity: 1;
transition: all 200ms ease-in-out;
transition-delay: 300ms;
}
.page-container.sidebar-collapsed #menu span {
opacity: 1;
transition: all 50ms linear;
position:relative;
top:5px;
right:10px;
}
.page-container.sidebar-collapsed-back #menu span {
opacity: 1;
transition: all 200ms linear;
transition-delay: 300ms;
top: 17px;
right: 75px;
position: absolute;
}
.sidebar-menu {
position: fixed;
float: left;
width: 280px;
top: 0;
right: 0;
bottom: 0;
background-color: #303641;
color: #aaabae;
font-family: "Segoe UI";
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.5);
z-index: 1;
}
#menu {
list-style: none;
padding: 0;
margin: 0 0 20px;
overflow: hidden;
}
#menu li {
position: relative;
margin: 0;
font-size: 12px;
border-bottom: 1px solid rgba(69, 74, 84, 0.7);
padding: 0;
}
#menu li ul {
opacity: 0;
height: 0px;
}
a:hover {
transition: all 200ms ease-in-out;
}
#menu li a {
text-decoration: none;
font-style: normal;
font-weight: 400;
position: relative;
display: block;
padding: 10px 15px;
color: #FFFFFF;
white-space: nowrap;
z-index: 2;
transition: 200ms;
}
#menu li a:hover {
color: #ffffff;
background-color: #333944;
transition: all 250ms ease-in-out;
transform: scale(1.3);
}
#menu li.active > a {
background-color: #2b303a;
color: #ffffff;
}
#menu ul li {
background-color: #2b303a;
}
#menu ul {
list-style-type: none;
margin: 0;
padding: 0;
}
#menu li ul {
position: absolute;
visibility: hidden;
right: 100%;
top: -1px;
background-color: #2b303a;
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.5);
opacity: 0;
transition: opacity 0.1s linear;
border-top: 1px solid rgba(69, 74, 84, 0.7);
}
#menu li:hover > ul {
visibility: visible;
opacity: 1;
}
#menu li li ul {
right: 100%;
visibility: hidden;
top: -1px;
opacity: 0;
transition: opacity 0.1s linear;
}
#menu li li:hover ul {
visibility: visible;
opacity: 1;
}
#menu .fa {
margin-right: 5px;
font-size: 30px;
}
.logo {
width: 100%;
padding: 21px;
box-sizing: border-box;
height: 136px;
}
.sidebar-icon {
position: relative;
right: -6px;
float: right;
border: 1px solid #454a54;
text-align: center;
line-height: 1;
font-size: 18px;
padding: 6px 8px;
border-radius: 3px;
color: #FFFFFF;
background-clip: padding-box;
text-shadow: 4px 4px 6px rgba(0, 0, 0, 0.4);
}
<div class="page-container sidebar-collapsed">
<div class="sidebar-menu">
<div style="border-top:1px solid rgba(69, 74, 84, 0.7)"></div>
<div class="menu">
<ul id="menu">
<li id="menu-home"><a href="#"><i class="fa fa-home"></i><span>first</span></a></li>
<li><a href="#"><i class="fa fa-share-alt"></i><span class="fa fa-angle-left"
style="float: left; position:unset;"></span><span>second</span></a>
<ul>
<li><a href="#"><i class="fa fa-facebook"></i> Facebook</a></li>
<li><a href="#"><i class="fa fa-twitter"></i> Twitter</a></li>
<li><a href="#"><i class="fa fa-pinterest"></i> Pinterest</a></li>
</ul>
</li>
<li><a href="#"><i class="fa fa-history"></i><span>blog</span></a></li>
<li><a href="#"><i class="fa fa-gears"></i><span>settings</span></a></li>
</ul>
</div>
</div>
</div>
#menu {
list-style: none;
padding: 0;
margin: 0 0 20px;
overflow: hidden;
}
答案 1 :(得分:1)
我在显示背景和文字/图标内容的a
标签之间插入了一个容器。我使用了div
,因为您的span
已经如此风格化了。
我将容器添加到第一个和第二个,只是为了演示子列表仍然显示。
在样式中查找您的a:hover
选择器已更改为a:hover .expandable
。
div.expandable {
display: inline-block;
}
.page-container {
min-width: 1260px;
position: relative;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
margin: 0px auto;
}
.content {
max-width: 800px;
min-width: 600px;
display: block;
padding: 50px;
margin: 50px auto;
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
background-color: #ffffff;
overflow: hidden;
}
.page-container.sidebar-collapsed {
padding-right: 65px;
transition: all 100ms linear;
transition-delay: 300ms;
}
.page-container.sidebar-collapsed-back {
padding-right: 280px;
transition: all 100ms linear;
}
.page-container.sidebar-collapsed .sidebar-menu {
width: 65px;
transition: all 100ms ease-in-out;
transition-delay: 300ms;
}
.page-container.sidebar-collapsed-back .sidebar-menu {
width: 280px;
transition: all 100ms ease-in-out;
}
.page-container.sidebar-collapsed .sidebar-icon {
transition: all 300ms ease-in-out;
}
.page-container.sidebar-collapsed-back .sidebar-icon {
transition: all 300ms ease-in-out;
}
.page-container.sidebar-collapsed .logo {
padding: 21px;
height: 136px;
box-sizing: border-box;
transition: all 100ms ease-in-out;
transition-delay: 300ms;
}
.page-container.sidebar-collapsed-back .logo {
width: 100%;
padding: 21px;
height: 136px;
box-sizing: border-box;
transition: all 100ms ease-in-out;
}
.page-container.sidebar-collapsed #logo {
opacity: 0;
transition: all 200ms ease-in-out;
}
.page-container.sidebar-collapsed-back #logo {
opacity: 1;
transition: all 200ms ease-in-out;
transition-delay: 300ms;
}
.page-container.sidebar-collapsed #menu span {
opacity: 1;
transition: all 50ms linear;
position:relative;
top:5px;
right:10px;
}
.page-container.sidebar-collapsed-back #menu span {
opacity: 1;
transition: all 200ms linear;
transition-delay: 300ms;
top: 17px;
right: 75px;
position: absolute;
}
.sidebar-menu {
position: fixed;
float: left;
width: 280px;
top: 0;
right: 0;
bottom: 0;
background-color: #303641;
color: #aaabae;
font-family: "Segoe UI";
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.5);
z-index: 1;
}
#menu {
list-style: none;
padding: 0;
margin: 0 0 20px;
}
#menu li {
position: relative;
margin: 0;
font-size: 12px;
border-bottom: 1px solid rgba(69, 74, 84, 0.7);
padding: 0;
}
#menu li ul {
opacity: 0;
height: 0px;
}
a:hover {
transition: all 200ms ease-in-out;
}
#menu li a {
text-decoration: none;
font-style: normal;
font-weight: 400;
position: relative;
display: block;
padding: 10px 15px;
color: #FFFFFF;
white-space: nowrap;
z-index: 2;
transition: 200ms;
}
#menu li a:hover .expandable {
color: #ffffff;
background-color: #333944;
transition: all 250ms ease-in-out;
transform: scale(1.3);
}
#menu li.active > a {
background-color: #2b303a;
color: #ffffff;
}
#menu ul li {
background-color: #2b303a;
}
#menu ul {
list-style-type: none;
margin: 0;
padding: 0;
}
#menu li ul {
position: absolute;
visibility: hidden;
right: 100%;
top: -1px;
background-color: #2b303a;
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.5);
opacity: 0;
transition: opacity 0.1s linear;
border-top: 1px solid rgba(69, 74, 84, 0.7);
}
#menu li:hover > ul {
visibility: visible;
opacity: 1;
}
#menu li li ul {
right: 100%;
visibility: hidden;
top: -1px;
opacity: 0;
transition: opacity 0.1s linear;
}
#menu li li:hover ul {
visibility: visible;
opacity: 1;
}
#menu .fa {
margin-right: 5px;
font-size: 30px;
}
.logo {
width: 100%;
padding: 21px;
box-sizing: border-box;
height: 136px;
}
.sidebar-icon {
position: relative;
right: -6px;
float: right;
border: 1px solid #454a54;
text-align: center;
line-height: 1;
font-size: 18px;
padding: 6px 8px;
border-radius: 3px;
color: #FFFFFF;
background-clip: padding-box;
text-shadow: 4px 4px 6px rgba(0, 0, 0, 0.4);
}
<div class="page-container sidebar-collapsed">
<div class="sidebar-menu">
<div style="border-top:1px solid rgba(69, 74, 84, 0.7)"></div>
<div class="menu">
<ul id="menu">
<li id="menu-home"><a href="#"><div class="expandable"><i class="fa fa-home"></i><span>first</span></div></a></li>
<li><a href="#"><div class="expandable"><i class="fa fa-share-alt"></i><span class="fa fa-angle-left"
style="float: left; position:unset;"></span><span>second</span></div></a>
<ul>
<li><a href="#"><i class="fa fa-facebook"></i> Facebook</a></li>
<li><a href="#"><i class="fa fa-twitter"></i> Twitter</a></li>
<li><a href="#"><i class="fa fa-pinterest"></i> Pinterest</a></li>
</ul>
</li>
<li><a href="#"><i class="fa fa-history"></i><span>blog</span></a></li>
<li><a href="#"><i class="fa fa-gears"></i><span>settings</span></a></li>
</ul>
</div>
</div>
</div>