问题描述
我希望引导程序 4 导航栏保持完全展开.另外我想要一个覆盖元素,其中图像和文本向右对齐.即可点击的 img/文本所有类别",向右对齐.
这是我所拥有的.我无法让文本向右移动.
.overlay {高度:100%;宽度:0;位置:固定;z-索引:1;顶部:0;左:0;背景颜色:RGB(0,0,0);背景颜色:rgba(0,0,0, 0.9);溢出-x:隐藏;过渡:0.5s;}.overlay-content {位置:相对;顶部:25%;宽度:100%;文本对齐:居中;边距顶部:30px;}.overlay 一个 {填充:8px;文字装饰:无;字体大小:36px;颜色:#818181;显示:块;过渡:0.3s;}.overlay a:hover, .overlay a:focus {颜色:#f1f1f1;}.overlay .closebtn {位置:绝对;顶部:20px;右:45px;字体大小:60px;}
请告诉我 HTML 是否正常,以及如何使所有类别"显示在导航栏的右侧.
谢谢!
你需要将span元素设置为display:block;
然后你就可以使用text-align: right;代码>.
我在 span 中添加了一个 nav-icon
类,并将您的内联样式移动到了 css 部分:
.overlay {高度:100%;宽度:0;位置:固定;z-索引:1;顶部:0;左:0;背景颜色:RGB(0,0,0);背景颜色:rgba(0,0,0, 0.9);溢出-x:隐藏;过渡:0.5s;}.overlay-content {位置:相对;顶部:25%;宽度:100%;文本对齐:居中;边距顶部:30px;}.overlay 一个 {填充:8px;文字装饰:无;字体大小:36px;颜色:#818181;显示:块;过渡:0.3s;}.overlay a:hover, .overlay a:focus {颜色:#f1f1f1;}.overlay .closebtn {位置:绝对;顶部:20px;右:45px;字体大小:60px;}.导航图标{字体大小:30px;游标:指针;显示:块;文本对齐:右;}
I want the bootstrap 4 navigation bar to stay fully expanded. Also I would like to have an overlay element where the image and text is aligned to the right. i.e the clickable img/text "All categories", is aligned to the right.
Here is what I have. I cannot get the text to go to the right.
.overlay {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
}
.overlay-content {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}
.overlay a {
padding: 8px;
text-decoration: none;
font-size: 36px;
color: #818181;
display: block;
transition: 0.3s;
}
.overlay a:hover, .overlay a:focus {
color: #f1f1f1;
}
.overlay .closebtn {
position: absolute;
top: 20px;
right: 45px;
font-size: 60px;
}
<body>
<div id="myNav" class="overlay">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<div class="overlay-content">
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Clients</a>
<a href="#">Contact</a>
</div>
</div>
<nav class="navbar navbar-expand navbar-light bg-light">
<a class="navbar-brand" href="#">
<img src="img/icons/logo/pquizlogo.svg" width="38" height="38" class="d-inline-block align-top" alt="">Brand-name
</a>
<div>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰ All categories</span>
<script>
function openNav() {
document.getElementById("myNav").style.width = "100%";
}
function closeNav() {
document.getElementById("myNav").style.width = "0%";
}
</script>
</div>
</nav>
</body>
Please tell me if the HTML is alright, and how to make 'All categories' show up to the right of the navbar.
thanks!
You need to set the span element to display:block;
and then you can use text-align: right;
.
I added a class nav-icon
to the span and moved your inline style to the css section:
.overlay {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
}
.overlay-content {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}
.overlay a {
padding: 8px;
text-decoration: none;
font-size: 36px;
color: #818181;
display: block;
transition: 0.3s;
}
.overlay a:hover, .overlay a:focus {
color: #f1f1f1;
}
.overlay .closebtn {
position: absolute;
top: 20px;
right: 45px;
font-size: 60px;
}
.nav-icon{
font-size:30px;
cursor:pointer;
display: block;
text-align: right;
}
<body>
<div id="myNav" class="overlay">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<div class="overlay-content">
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Clients</a>
<a href="#">Contact</a>
</div>
</div>
<nav class="navbar navbar-expand navbar-light bg-light">
<a class="navbar-brand" href="#">
<img src="img/icons/logo/pquizlogo.svg" width="38" height="38" class="d-inline-block align-top" alt="">Brand-name
</a>
<div>
<span class="nav-icon" onclick="openNav()">All categories ☰</span>
<script>
function openNav() {
document.getElementById("myNav").style.width = "100%";
}
function closeNav() {
document.getElementById("myNav").style.width = "0%";
}
</script>
</div>
</nav>
</body>
这篇关于带全屏覆盖的 bootstrap4 导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!