英文:
how to only give animation to one element in Navbar rest of them no animation using css
问题
在我有一个名为SHOP的段落,它将作为动画从左向右移动,但是除了SHOP之外的每个元素,如HOME, PRODUCTS, ABOUT, CONTACT都是从右向左移动,我想要停止它们移动,除了SHOP。
HTML代码:
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="./styles.css" />
    <title>Hasgu</title>
    <script
      src="https://kit.fontawesome.com/e5e83f9d84.js"
      crossorigin="anonymous"
    ></script>
</head>
<body>
    <nav class="navbar">
        <a href="#"><p class="name">SHOP</p></a>
        <a href="">Home</a>
        <a href="">Products</a>
        <a href="">About</a>
        <a href="">Contact</a>
        <input type="search" class="searchbar" placeholder="Search" required />
        <button type="submit" class="fas fa-search"></button>
    </nav>
</body>
CSS代码:
* {
    margin: 0;
}
.navbar {
    font-family: monospace;
    font-size: 1.3rem;
    padding: 1%;
    background-color: rgb(235, 178, 178);
}
.navbar a {
    margin-left: 1.5%;
    text-decoration: none;
    color: black;
    padding: 0.6%;
}
.navbar a:not(.name):hover {
    animation: none; /* 除了"HASGU"元素外,禁用所有链接的动画 */
}
.searchbar {
    margin-left: 600px;
    padding: 10px;
    text-align: left;
    width: 500px;
    height: 10%;
    color: #fff;
    font-size: 17px;
    border: black;
    font-weight: 500;
    background: black;
    border-radius: 10px;
}
.navbar button {
    height: 10%;
    border-radius: 10px;
    padding: 10px;
    color: white;
    font-size: 17px;
    background: black;
    border: none;
    border-radius: 10px;
    cursor: pointer;
}
.name {
    margin-top: 2px;
    margin-bottom: 0px;
    display: inline-block;
    font-size: 1.2em;
    color: black;
    background-color: rgb(235, 178, 178);
    padding: 0px;
    letter-spacing: 1px;
    font-family: monospace;
    border-right: 5px solid;
    width: 73px;
    white-space: nowrap;
    overflow: hidden;
    animation: typing 2s steps(5), cursor 0.4s step-end infinite alternate;
}
@keyframes cursor {
    50% {
        border-color: transparent;
    }
}
@keyframes typing {
    from {
        width: 0;
    }
}
英文:
where i have a para called SHOP it will move from left to right as a animation
but with that every element like** HOME,PRODUCTS,ABOUT,CONTACT **everything is moving right to left i want to stop them moving except SHOP
HTML CODE
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
* {
margin: 0;
}
.navbar {
font-family: monospace;
font-size: 1.3rem;
padding: 1%;
background-color: rgb(235, 178, 178);
}
.navbar a {
margin-left: 1.5%;
text-decoration: none;
color: black;
padding: 0.6%;
}
.navbar a:not(.name):hover {
animation: none; /* Disable animation for all links except the "HASGU" element */
}
.searchbar {
margin-left: 600px;
padding: 10px;
text-align: left;
width: 500px;
height: 10%;
color: #fff;
font-size: 17px;
border: black;
font-weight: 500;
background: black;
border-radius: 10px;
}
.navbar button {
height: 10%;
border-radius: 10px;
padding: 10px;
color: white;
font-size: 17px;
background: black;
border: none;
border-radius: 10px;
cursor: pointer;
}
.name {
margin-top: 2px;
margin-bottom: 0px;
display: inline-block;
font-size: 1.2em;
color: black;
background-color: rgb(235, 178, 178);
padding: 0px;
letter-spacing: 1px;
font-family: monospace;
border-right: 5px solid;
width: 73px;
white-space: nowrap;
overflow: hidden;
animation: typing 2s steps(5), cursor 0.4s step-end infinite alternate;
}
@keyframes cursor {
50% {
border-color: transparent;
}
}
@keyframes typing {
from {
width: 0;
}
}
<!-- language: lang-html -->
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="./styles.css" />
<title>Hasgu</title>
<script
src="https://kit.fontawesome.com/e5e83f9d84.js"
crossorigin="anonymous"
></script>
</head>
<body>
<nav class="navbar">
<a href="#"><p class="name">SHOP</p></a>
<a href="">Home</a>
<a href="">Products</a>
<a href="">About</a>
<a href="">Contact</a>
<input type="search" class="searchbar" placeholder="Search" required />
<button type="submit" class="fas fa-search"></button>
</nav>
</body>
<!-- end snippet -->
Someone please help me with this thanks in advance
Please help me through that
答案1
得分: 0
你可以为你的.name元素使用包装器:
<nav class="navbar">
  <div class="wrapper">
    <a href="#"><p class="name">SHOP</p></a>
  </div>
  <a href="">Home</a>
  <a href="">Products</a>
  <a href="">About</a>
  <a href="">Contact</a>
  <input type="search" class="searchbar" placeholder="Search" required />
  <button type="submit" class="fas fa-search"></button>
</nav>
英文:
You can use wrapper for your .name element:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
* {
margin: 0;
}
.navbar {
font-family: monospace;
font-size: 1.3rem;
padding: 1%;
background-color: rgb(235, 178, 178);
}
.navbar a {
margin-left: 1.5%;
text-decoration: none;
color: black;
padding: 0.6%;
}
.navbar a:not(.name):hover {
animation: none; /* Disable animation for all links except the "HASGU" element */
}
.searchbar {
margin-left: 600px;
padding: 10px;
text-align: left;
width: 500px;
height: 10%;
color: #fff;
font-size: 17px;
border: black;
font-weight: 500;
background: black;
border-radius: 10px;
}
.navbar button {
height: 10%;
border-radius: 10px;
padding: 10px;
color: white;
font-size: 17px;
background: black;
border: none;
border-radius: 10px;
cursor: pointer;
}
.name {
margin-top: 2px;
margin-bottom: 0px;
display: inline-block;
font-size: 1.2em;
color: black;
background-color: rgb(235, 178, 178);
padding: 0px;
letter-spacing: 1px;
font-family: monospace;
border-right: 5px solid;
width: 100%;
white-space: nowrap;
overflow: hidden;
animation: typing 2s steps(5), cursor 0.4s step-end infinite alternate;
}
.wrapper {
display: inline-block;
width: 73px;
}
@keyframes cursor {
50% {
border-color: transparent;
}
}
@keyframes typing {
from {
width: 0;
}
}
<!-- language: lang-html -->
<nav class="navbar">
<div class="wrapper">
<a href="#"><p class="name">SHOP</p></a>
</div>
<a href="">Home</a>
<a href="">Products</a>
<a href="">About</a>
<a href="">Contact</a>
<input type="search" class="searchbar" placeholder="Search" required />
<button type="submit" class="fas fa-search"></button>
</nav>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论