首页 > 解决方案 > how can i fix my web page navigetion bar?

问题描述

I am creating a web page with a navigation bar which has some menu.

i want to show a border on menu items border when i mouse over them. i have created this but when i am hovering on them they appear with a border and making an effect on the text also. How can I remove the effect from the text ?

body{
    font-family: 'Montserrat', sans-serif;
}
*{
    margin:auto;
    padding:0px;

}
.header{
    background-color:#0D1422;
    color:white;
    width:100%;
    height:auto;
    padding:10px;
    overflow:hidden;
}
.header .logo{
    width: auto;
    margin: 37px 100px;
    color:white;
    font-size:50px;
    font-weight:800;
    overflow: hidden;
    float: left;
    text-transform: uppercase;
}

span {
    color: #F5A425;
}

.menu-bar {
    float: right;
    overflow: hidden;
}

.menu-bar ul {
    text-transform: uppercase;
    list-style-type: none;
    padding: 27px;
    font-size: 53px;
    font-weight:600;
    color: white;
}
li {
    list-style-type: none;
    float: left;
    padding: 40px;
    color: white;
}

a {
    color: white;
    text-decoration: none;
    font-size: 57px;
    font-weight: 800;
}

.menu-bar {
    float: right;
    margin: auto 140px;
}
li:hover{
    border:1px solid #f5a523;
    transition:.5s;
}
<!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>grad school project</title>
        <link href="https://fonts.googleapis.com/css?family=Montserrat:100,200,300,400,500,600,700,800,900" rel="stylesheet">
        <link rel="stylesheet" href="main.css">
    </head>
    <body>
        <header>
            <div class="header">

                <div class="logo">
                    <h1> <span>Grad</span> school</h1>
                </div>
                <div class="menu-bar">
                    <ul> 
                    <li> <a href="#">home</a></li>    
                    <li> <a href="#">about-us</a></li>    
                    <li> <a href="#">courses</a></li>    
                    <li> <a href="#">contact</a></li>    
                    <li> <a href="#">extarnal</a></li>    
                    </ul>
                </div>
            </div>

        </header>

    </body>
    </html>

标签: htmlcss

解决方案


The way I would solve this is by setting the border color to transparent while keeping the same width as when the element is hovered.

body {
  font-family: "Montserrat", sans-serif;
}
* {
  margin: auto;
  padding: 0px;
}
.header {
  background-color: #0d1422;
  color: white;
  width: 100%;
  height: auto;
  padding: 10px;
  overflow: hidden;
}
.header .logo {
  width: auto;
  margin: 37px 100px;
  color: white;
  font-size: 50px;
  font-weight: 800;
  overflow: hidden;
  float: left;
  text-transform: uppercase;
}

span {
  color: #f5a425;
}

.menu-bar {
  float: right;
  overflow: hidden;
}

.menu-bar ul {
  text-transform: uppercase;
  list-style-type: none;
  padding: 27px;
  font-size: 53px;
  font-weight: 600;
  color: white;
}
li {
  list-style-type: none;
  float: left;
  padding: 40px;
  color: white;
  border: 1px solid transparent;
}

a {
  color: white;
  text-decoration: none;
  font-size: 57px;
  font-weight: 800;
}

.menu-bar {
  float: right;
  margin: auto 140px;
}
li:hover {
  border: 1px solid #f5a523;
  transition: 0.5s;
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>grad school project</title>
    <link
      href="https://fonts.googleapis.com/css?family=Montserrat:100,200,300,400,500,600,700,800,900"
      rel="stylesheet"
    />
    <link rel="stylesheet" href="main.css" />
  </head>
  <body>
    <header>
      <div class="header">
        <div class="logo">
          <h1><span>Grad</span> school</h1>
        </div>
        <div class="menu-bar">
          <ul>
            <li><a href="#">home</a></li>
            <li><a href="#">about-us</a></li>
            <li><a href="#">courses</a></li>
            <li><a href="#">contact</a></li>
            <li><a href="#">extarnal</a></li>
          </ul>
        </div>
      </div>
    </header>
  </body>
</html>


推荐阅读