Я создаю веб-страницу с панелью навигации, в которой есть меню.
я хочу показать границу на границе пунктов меню, когда я наведу на них курсор. я создал это, но когда я наводил на них курсор, они появляются с рамкой и также влияют на текст. Как убрать эффект с текста?
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>
Я бы решил это, установив прозрачный цвет границы, сохраняя при этом ту же ширину, что и при наведении на элемент.
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>
Я добавил прозрачную рамку к исходным элементам и придал ей цвет при наведении, и я переместил ваш переход в селектор без наведения, поскольку именно там он должен быть.
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;
transition: 0.5s;
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;
}
<!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>
Большое спасибо. моя проблема решена.
Я не совсем уверен, что вы пытаетесь сделать, я предполагаю, что вам нужна рамка при наведении курсора, но вы не хотите, чтобы элементы прыгали вокруг, вы можете добавить display:flex к элементам строки меню с помощью flex-direction столбца, чтобы снова расположить их в том же порядке
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 {
display:flex;
flex-direction:column;
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>
Поэтому сделайте рамку на
li
прозрачной на 1 пиксель.