css 菜单在移动设备上消失
css menu disappears on mobile device
这是我创建的 CSS 菜单。
当我在我的手机 (iPhone 6) 中看到这个时,最后一个菜单 (Menu4) 根本不显示。前 3 个菜单从 phone 屏幕的左侧延伸到右侧。我不明白为什么。
有人可以帮忙吗?
这是 HTML 部分
<hr class="navHr">
<nav id="m">
<a href="#" data-mirror="Menu1">Menu1</a>
<a href="#" data-mirror="Menu2">Menu2</a>
<a href="#" data-mirror="Menu3">Menu3</a>
<a href="#" data-mirror="Menu4">Menu4</a>
</nav>
<hr class="navHr">
和CSS部分
.navHr {
border: 0;
height: 0.1em;
margin: 0;
background-image: -webkit-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.75), rgba(0,0,0,0));
background-image: -moz-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.75), rgba(0,0,0,0));
background-image: -ms-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.75), rgba(0,0,0,0));
background-image: -o-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.75), rgba(0,0,0,0));
}
nav {
height: 2em;
background: #000;
background: linear-gradient(to bottom, rgba(76, 76, 76, 1) 0%, rgba(44, 44, 44, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(19, 19, 19, 1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4c4c4c', endColorstr='#131313',GradientType=0 );
line-height: 2em;
text-transform: uppercase;
text-align: center;
min-width: 2em;
position: relative;
}
nav::before {
background: linear-gradient(to top, rgba(76, 76, 76, 0) 0%, rgba(44, 44, 44, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(19, 19, 19, 1) 100%);
content: '';
display: block;
position: absolute;
top: 100%;
left: 0;
width: 100%;
height: 100%;
opacity: 0.09;
}
nav a {
color: #FFF;
text-decoration: none;
font-weight: bold;
font-size: 1.2em;
border-right: solid 0.1em #FFF;
height: 100%;
padding: 0.25em 3em;
position: relative;
}
nav a:first-child {
border-left: solid 0.1em #FFF;
}
nav a::before {
content: attr(data-mirror);
position: absolute;
top: 100%;
left: 3em;
color: #000;
transform: scaleY(-1);
color: #FFF;
opacity: 0.5;
}
#m {
background-color: #000000;
}
我检查了你的代码,尝试在你的 anchor tag
上添加 "display:inline-block"
,你会看到你的第 4 列出现,第四个在小屏幕下位于第二个下方,因为位置是relative
,在这里试试:
基本上,您正在寻找的是将元素显示为内联级块容器以避免错位。该块的内部被格式化为块级框,元素本身被格式化为行内级框,这塑造了这 4 个相邻列的导航。
为什么要使用 inline-block
?
- inline-block 使元素生成一个块状框,其布局就像一个内联框。
- 行内块被放置在行内(即与相邻内容在同一行),但它表现为块。
- 基本上,这是一种使元素内联的方法,但保留了它们的块功能,例如设置宽度和高度、顶部和底部边距和填充等。
这是我创建的 CSS 菜单。
当我在我的手机 (iPhone 6) 中看到这个时,最后一个菜单 (Menu4) 根本不显示。前 3 个菜单从 phone 屏幕的左侧延伸到右侧。我不明白为什么。
有人可以帮忙吗?
这是 HTML 部分
<hr class="navHr">
<nav id="m">
<a href="#" data-mirror="Menu1">Menu1</a>
<a href="#" data-mirror="Menu2">Menu2</a>
<a href="#" data-mirror="Menu3">Menu3</a>
<a href="#" data-mirror="Menu4">Menu4</a>
</nav>
<hr class="navHr">
和CSS部分
.navHr {
border: 0;
height: 0.1em;
margin: 0;
background-image: -webkit-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.75), rgba(0,0,0,0));
background-image: -moz-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.75), rgba(0,0,0,0));
background-image: -ms-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.75), rgba(0,0,0,0));
background-image: -o-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.75), rgba(0,0,0,0));
}
nav {
height: 2em;
background: #000;
background: linear-gradient(to bottom, rgba(76, 76, 76, 1) 0%, rgba(44, 44, 44, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(19, 19, 19, 1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4c4c4c', endColorstr='#131313',GradientType=0 );
line-height: 2em;
text-transform: uppercase;
text-align: center;
min-width: 2em;
position: relative;
}
nav::before {
background: linear-gradient(to top, rgba(76, 76, 76, 0) 0%, rgba(44, 44, 44, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(19, 19, 19, 1) 100%);
content: '';
display: block;
position: absolute;
top: 100%;
left: 0;
width: 100%;
height: 100%;
opacity: 0.09;
}
nav a {
color: #FFF;
text-decoration: none;
font-weight: bold;
font-size: 1.2em;
border-right: solid 0.1em #FFF;
height: 100%;
padding: 0.25em 3em;
position: relative;
}
nav a:first-child {
border-left: solid 0.1em #FFF;
}
nav a::before {
content: attr(data-mirror);
position: absolute;
top: 100%;
left: 3em;
color: #000;
transform: scaleY(-1);
color: #FFF;
opacity: 0.5;
}
#m {
background-color: #000000;
}
我检查了你的代码,尝试在你的 anchor tag
上添加 "display:inline-block"
,你会看到你的第 4 列出现,第四个在小屏幕下位于第二个下方,因为位置是relative
,在这里试试:
基本上,您正在寻找的是将元素显示为内联级块容器以避免错位。该块的内部被格式化为块级框,元素本身被格式化为行内级框,这塑造了这 4 个相邻列的导航。
为什么要使用 inline-block
?
- inline-block 使元素生成一个块状框,其布局就像一个内联框。
- 行内块被放置在行内(即与相邻内容在同一行),但它表现为块。
- 基本上,这是一种使元素内联的方法,但保留了它们的块功能,例如设置宽度和高度、顶部和底部边距和填充等。