如何在底部设置此导航栏?

时间:2020-05-08 00:46:14

标签: html css

我想知道在页面底部设置导航栏的方式。我一直在尝试所有操作,但似乎并没有将其设置在底部。我已经尝试使用底部,边距底部的方法,但我也不知道是否已经在CSS中设置了配置,该配置无法使之前提到的这些命令起作用。

HTML

<!doctype html>
{%load staticfiles%}
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Home</title>
    <link rel="stylesheet" href="{%static 'index/css/index.css'%}">
    <link rel="stylesheet" media="screen" href="https://fontlibrary.org/face/glacial-indifference" type="text/css"/>
    <script src="https://kit.fontawesome.com/b525a42bf1.js" crossorigin="anonymous"></script>
</head>
<body>

<div class="logo"><h2>MediTracker</h2></div>

<nav>
    <div class="menu">
        <ul class="clear">
            <li><a href="" title="home"><i class="fa fa-home"></i><span class="link-text">Home</span></a></li>
            <li><a href="" title="about"><i class="fa fa-question-circle"></i><span class="link-text">About</span></a></li>
            <li><a href="" title="pricing"><i class="fa fa-money-bill-alt"></i><span class="link-text">Pricing</span></a></li>
            <li><a href="" title="services"><i class="fa fa-tools"></i><span class="link-text">Services</span></a></li>
            <li><a href="" title="contact"><i class="fa fa-phone"></i><span class="link-text">Contact Us</span></a></li>
        </ul>
    </div>
</nav>


</body>
</html>

CSS

body{
    background-color: #333;
    background-size: cover;
    background-position: center;
    font-family: 'GlacialIndifferenceRegular';
    overflow: hidden;
    font-weight: 600;
    height: 85vh;
}

a{
    text-decoration: none;
}

.clear:after{
    content: "";
    display: block;
    clear:both;
}

nav .menu{
    text-align: center;
    margin-bottom:0px;
    width: 100%;
}

nav .menu ul{
    list-style: none;
    display: inline-block;
}

nav .menu ul li{
    float: left;
    width: 150px;
    height: 150px;
    background-color: white;
    transition: background-color 0.2s linear 0s;
}

nav .menu ul li a{
    display: table;
    width: 100%;
    height: 100%;
    position: relative;
    text-align: center;
}

nav .menu a i{
    display: block;
    vertical-align: middle;
    color: #333;
    font-size: 23px;
    transform: all 0.2s linear 0s;
    padding: 44px 0 10px;
}

nav .menu a i:before{
    width: 41px;
    display: inline-block;
    height: 41px;
    line-height: 37px;
    transition: color 0.2s linear 0s,
                font-size 0.2s linear 0s,
                border-color 0.2s linear 0.2s,
                height 0.2s linear 0s,
                line-height 0.2s linear 0s;
}

nav .menu a .link-text{
    right: 45px;
    color: #333;
    font-size: 14px;
    text-transform: uppercase;
    transition: all 0.2s linear 0s;
}

nav .menu ul li:hover{
    background-color: #42d3e3;
}

nav .menu ul li:hover + li:last-child{
    border-right-color: blue;
}

nav .menu ul li:hover .link-text{
    opacity: 0;
}

nav .menu ul li:hover i{
    color: #333;
    font-size: 50px;
}

nav .menu ul li:hover i:before{
    border-color: transparent;
    border-radius: 500px;
    line-height: 40px;
    transition: color 0.2s linear 0s,
            font-size 0.2s linear 0s,
            border-color 0.2s linear 0.2s,
            height 0.2s linear 0s,
            line-height 0.2s linear 0s;
}

2 个答案:

答案 0 :(得分:1)

您可以将nav .menu设置为position: absolute; bottom:0;

nav .menu{
    text-align: center;
    margin-bottom:0px;
    width: 100%;
    position: absolute;
    bottom:0;
}

JsFiddle https://jsfiddle.net/viethien/gxw0dacb/3/

答案 1 :(得分:0)

除了margin-bottom: 0,还尝试添加bottom: 0margin-bottom仅在元素底部不创建margin,但不会在用户界面底部创建元素。 bottom: 0属性和值将从底部到元素留0空间。这可能让人感到困惑,但导航栏的代码应如下所示:

nav .menu{
    text-align: center;
    margin-bottom: 0px;
    bottom: 0;
    width: 100%;
}

您可以详细了解bottom属性here