标签 css 下的文章

看一下展示效果
PixPin_2024-05-08_11-11-56.gif
HTML代码:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>曲线导航菜单指示器</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <div class="navigation">
      <ul>
        <li class="list active">
          <a href="#">
            <span class="icon">
              <ion-icon name="home-outline"></ion-icon>
            </span>
            <span class="text">Home</span>
          </a>
        </li>
        <li class="list">
          <a href="#">
            <span class="icon">
              <ion-icon name="person-outline"></ion-icon>
            </span>
            <span class="text">Profile</span>
          </a>
        </li>
        <li class="list">
          <a href="#">
            <span class="icon">
              <ion-icon name="chatbubble-outline"></ion-icon>
            </span>
            <span class="text">Message</span>
          </a>
        </li>
        <li class="list">
          <a href="#">
            <span class="icon">
              <ion-icon name="camera-outline"></ion-icon>
            </span>
            <span class="text">Photo</span>
          </a>
        </li>
        <li class="list">
          <a href="#">
            <span class="icon">
              <ion-icon name="settings-outline"></ion-icon>
            </span>
            <span class="text">Settings</span>
          </a>
        </li>
        <div class="indicator"></div>
      </ul>
    </div>
    <script
      type="module"
      src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.esm.js"
    ></script>
    <script
      nomodule
      src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.js"
    ></script>
    <script>
      const list = document.querySelectorAll(".list");
      function activeLink() {
        list.forEach((item) => item.classList.remove("active"));
        this.classList.add("active");
      }
      list.forEach((item) => item.addEventListener("click", activeLink));
    </script>
  </body>
</html>

CSS代码:

@import url("https://fonts.googleapis.com/css?family=Poppins:100,200,300,400,500,600,700,800,900");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Poppins", sans-serif;
}

:root {
  --clr: #222327;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: var(--clr);
}

.navigation {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 400px;
  height: 70px;
  background-color: #fff;
  border-radius: 10px;
}

.navigation ul {
  display: flex;
  width: 350px;
}

.navigation ul li {
  position: relative;
  list-style: none;
  width: 70px;
  height: 70px;
  z-index: 1;
}

.navigation ul li a {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  width: 100%;
  text-align: center;
  font-weight: 500;
}

.navigation ul li .icon {
  position: relative;
  display: block;
  line-height: 75px;
  font-size: 1.5em;
  text-align: center;
  transition: 0.5s;
  color: var(--clr);
}

.navigation ul li.active .icon {
  transform: translateY(-32px);
}

.navigation ul li .text {
  position: absolute;
  color: var(--clr);
  font-weight: 400;
  font-size: 0.75em;
  letter-spacing: 0.05em;
  transition: 0.5s;
  opacity: 0;
  transform: translateY(20px);
}

.navigation ul li.active .text {
  opacity: 1;
  transform: translateY(10px);
}

.indicator {
  position: absolute;
  top: -50%;
  width: 70px;
  height: 70px;
  background: #29fd53;
  border-radius: 50%;
  border: 6px solid var(--clr);
  transition: 0.5s;
}

.indicator::before {
  content: "";
  position: absolute;
  top: 50%;
  left: -22px;
  width: 20px;
  height: 20px;
  background: transparent;
  border-top-right-radius: 20px;
  box-shadow: 1px -10px 0 0 var(--clr);
}

.indicator::after {
  content: "";
  position: absolute;
  top: 50%;
  right: -22px;
  width: 20px;
  height: 20px;
  background: transparent;
  border-top-left-radius: 20px;
  box-shadow: -1px -10px 0 0 var(--clr);
}

.navigation ul li:nth-child(1).active ~ .indicator {
  transform: translateX(calc(70px * 0));
}

.navigation ul li:nth-child(2).active ~ .indicator {
  transform: translateX(calc(70px * 1));
}

.navigation ul li:nth-child(3).active ~ .indicator {
  transform: translateX(calc(70px * 2));
}

.navigation ul li:nth-child(4).active ~ .indicator {
  transform: translateX(calc(70px * 3));
}

.navigation ul li:nth-child(5).active ~ .indicator {
  transform: translateX(calc(70px * 4));
}

先看效果:
PixPin_2024-05-07_08-02-39.gif

Html代码

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Glassmorphism Cards Hover Effects</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <div class="container">
      <div class="box" data-color="clr1">
        <div class="imgBx">
          <img src="./images/img_01.jpg" />
        </div>
        <div class="glass">
          <h3>Someone<br /><span>SEO Expert</span></h3>
          <ul>
            <a href="#" style="--i: 1"
              ><ion-icon name="logo-linkedin"></ion-icon
            ></a>
            <a href="#" style="--i: 2"
              ><ion-icon name="logo-whatsapp"></ion-icon
            ></a>
            <a href="#" style="--i: 3"
              ><ion-icon name="logo-instagram"></ion-icon
            ></a>
          </ul>
        </div>
      </div>

      <div class="box" data-color="clr2">
        <div class="imgBx">
          <img src="./images/img_02.jpg" />
        </div>
        <div class="glass">
          <h3>Someone<br /><span>Magician</span></h3>
          <ul>
            <a href="#" style="--i: 1"
              ><ion-icon name="logo-linkedin"></ion-icon
            ></a>
            <a href="#" style="--i: 2"
              ><ion-icon name="logo-whatsapp"></ion-icon
            ></a>
            <a href="#" style="--i: 3"
              ><ion-icon name="logo-instagram"></ion-icon
            ></a>
          </ul>
        </div>
      </div>

      <div class="box" data-color="clr3">
        <div class="imgBx">
          <img src="./images/img_03.jpg" />
        </div>
        <div class="glass">
          <h3>Someone<br /><span>Graphic Designer</span></h3>
          <ul>
            <a href="#" style="--i: 1"
              ><ion-icon name="logo-linkedin"></ion-icon
            ></a>
            <a href="#" style="--i: 2"
              ><ion-icon name="logo-whatsapp"></ion-icon
            ></a>
            <a href="#" style="--i: 3"
              ><ion-icon name="logo-instagram"></ion-icon
            ></a>
          </ul>
        </div>
      </div>

      <div class="box" data-color="clr4">
        <div class="imgBx">
          <img src="./images/img_04.jpg" />
        </div>
        <div class="glass">
          <h3>Someone<br /><span>Actress</span></h3>
          <ul>
            <a href="#" style="--i: 1"
              ><ion-icon name="logo-linkedin"></ion-icon
            ></a>
            <a href="#" style="--i: 2"
              ><ion-icon name="logo-whatsapp"></ion-icon
            ></a>
            <a href="#" style="--i: 3"
              ><ion-icon name="logo-instagram"></ion-icon
            ></a>
          </ul>
        </div>
      </div>
    </div>
    <script
      type="module"
      src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.esm.js"
    ></script>
    <script
      nomodule
      src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.js"
    ></script>
  </body>
</html>

CSS代码

@import url("https://fonts.googleapis.com/css?family=Poppins:200,300,400,500,600,700,800,900&display=swap");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Poppins", sans-serif;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: #111;
  transition: 0.5s;
}

body:has(.box[data-color="clr1"]:hover) {
  background-color: #162527;
}

body:has(.box[data-color="clr2"]:hover) {
  background-color: #202011;
}

body:has(.box[data-color="clr3"]:hover) {
  background-color: #5b4510;
}

body:has(.box[data-color="clr4"]:hover) {
  background-color: #611417;
}

.container {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 40px;
  flex-wrap: wrap;
}

.container .box {
  position: relative;
  width: 200px;
  height: 200px;
  border-radius: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: 0.5s;
}

.container .box .imgBx {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  border: 4px solid rgba(0, 0, 0, 0.2);
}

.container .box .imgBx img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: 0.5s;
  border-radius: 10px;
}

.container .box:hover .imgBx img {
  opacity: 0.5;
}

.container .box .glass {
  position: absolute;
  inset: 0;
  background: linear-gradient(#fff2, transparent);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 15px 15px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(15px);
  border-radius: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  scale: 0;
  opacity: 0;
  transition: 0.5s;
}

.container .box .glass::before {
  content: "";
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 40px;
  background-color: rgba(255, 255, 255, 0.05);
}

.container .box:hover {
  transform: rotate(-15deg);
}

.container .box:hover .glass {
  transform: rotate(20deg);
  scale: 1;
  opacity: 1;
}

.container .box .glass h3 {
  font-size: 1.25em;
  color: #fff;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  text-align: center;
  line-height: 0.8em;
}

.container .box .glass h3 span {
  font-weight: 400;
  font-size: 0.5em;
}

.container .box ul {
  position: absolute;
  bottom: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 15px;
}

.container .box ul a {
  color: #fff8;
  font-size: 1.25em;
  scale: 0;
  transition: 0.25s;
  transition-delay: scale calc(0.2s * var(--i));
}

.container .box:hover ul a {
  scale: 1;
}

.container .box ul a:hover {
  color: #fff;
}

"

漂亮、创意登录注册框。

HTML代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login - Register Form - CodeCraftedWeb</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="container">
        <div class="main">
            <input type="checkbox" id="chk" aria-hidden="true">
            <div class="login">
                <form class="form">
                    <label for="chk" aria-hidden="true">Log in</label>
                    <input class="input" type="email" name="email" placeholder="Email" required>
                    <input class="input" type="password" name="pswd" placeholder="Password" required>
                    <button>Log in</button>
                </form>
            </div>
            <div class="register">
                <form class="form">
                    <label for="chk" aria-hidden="true">Register</label>
                    <input class="input" type="text" name="txt" placeholder="Username" required>
                    <input class="input" type="email" name="email" placeholder="Email" required>
                    <input class="input" type="password" name="pswd" placeholder="Password" required>
                    <button>Register</button>
                </form>
            </div>
        </div>
    </div>
</body>
</html>

CSS代码:

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Verdana, Geneva, Tahoma, sans-serif;
}

.container {
    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #e8e8e8;
}

.main {
    position: relative;
    display: flex;
    flex-direction: column;
    background-color: #240046;
    max-height: 450px;
    width: 400px;
    overflow: hidden;
    border-radius: 12px;
    box-shadow: rgba(59, 0, 130, 0.442) 0px 30px 90px;
}

.form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 24px;
}

/*checkbox to switch from sign up to login*/

#chk {
    display: none;
}

/*Login*/

.login {
    position: relative;
    width: 100%;
    height: 100%;
}

.login label {
    margin: 5% 0 5%;
}

label {
    color: #fff;
    font-size: 2rem;
    justify-content: center;
    display: flex;
    font-weight: bold;
    cursor: pointer;
    transition: .5s ease-in-out;
}

.input {
    width: 100%;
    height: 40px;
    font-size: 1rem;
    background: #e0dede;
    padding: 10px;
    margin-top: 15px;
    border: none;
    outline: none;
    border-radius: 4px;
}

/*Register*/

.register {
    background: #eee;
    border-radius: 60% / 10%;
    transition: .8s ease-in-out;
}

.register label {
    color: #573b8a;
    transform: scale(.6);
}

#chk:checked ~ .register {
    transform: translateY(-68%);
}

#chk:checked ~ .register label {
    transform: scale(1);
    margin-bottom: .5rem;
}

#chk:checked ~ .login label {
    transform: scale(.6);
}

/*Button*/

.form button {
    width: 70%;
    height: 40px;
    margin: 15px auto 10%;
    color: #fff;
    background: #573b8a;
    font-size: 1rem;
    font-weight: bold;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: .2s ease-in;
}

.form button:hover {
    background-color: #6d44b8;
}

"

CSS发光边角效果,很炫酷,很实用

HTML代码如下:

<!DOCTYPE html>
<html>
  <head>
    <meta charset=""UTF-8"" />
    <title>CSS发光边角效果</title>
    <link rel=""stylesheet"" href=""style.css"" />
  </head>

  <body>
    <div class=""loader"" style=""--i: 1""></div>
    <div class=""loader"" style=""--i: 2""></div>
    <div class=""loader"" style=""--i: 3""></div>
    <div class=""loader"" style=""--i: 4""></div>
  </body>
</html>

CSS代码如下:

css
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: #222;
  gap: 40px;
}
.loader {
  position: relative;
  width: 150px;
  height: 150px;
  background: rgba(45, 45, 45, 1);
  overflow: hidden;
  transform: rotate(calc(90deg * var(--i)));
}
.loader::before {
  content: """";
  position: absolute;
  width: 300px;
  height: 300px;
  background: radial-gradient(#0ef, transparent, transparent);
  animation: animate 1.5s linear infinite;
}
.loader::after {
  content: """";
  position: absolute;
  inset: 2px;
  background: rgba(45, 45, 45, 0.9);
}
@keyframes animate {
  0% {
    transform: translate(-150px, -150px);
  }
  25% {
    transform: translate(0px, -150px);
  }
  50% {
    transform: translate(0px, 0px);
  }
  75% {
    transform: translate(-150px, 0px);
  }
  100% {
    transform: translate(-150px, -150px);
  }
}

"单击输入框,在上方会显示一行动态的文字提示。
 title=

编写HTML代码如下:

<!DOCTYPE html>
<html>
  <head>
    <meta charset=""UTF-8"" />
    <title>使用 CSS 和 Javascript 输入文本点击动画</title>
    <link rel=""stylesheet"" href=""style.css"" />
  </head>
  <body>
    <div class=""box"">
      <input type=""text"" required />
      <label>请输入您的名字</label>
    </div>
    <script src=""script.js""></script>
  </body>
</html>

编写CSS代码如下:

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: #29313a;
}

.box {
    position: relative;
    width: 350px;
}

.box input {
    position: relative;
    width: 100%;
    padding: 10px 0;
    background: transparent;
    border: none;
    outline: none;
    border-bottom: 2px solid #999;
    color: #fff;
    font-size: 1.25em;
    transition: 0.5s;
}

.box label {
    position: absolute;
    left: 0;
    padding: 10px 0;
    pointer-events: none;
    color: #666;
    user-select: none;
}

.box label span {
    display: inline-flex;
    font-size: 1.25em;
    letter-spacing: 0.05em;
    transition: 0.25s;
}

.box input:focus~label span,
.box input:valid~label span {
    color: #0f0;
    text-shadow: 0 0 5px #0f0,
    0 0 15px #0f0,
    0 0 30px #0f0;
    transform: translateY(-40px);
}

.box input:focus,
.box input:valid {
    border-bottom: 2px solid #fff;
}

编写Javascript代码如下:

let label = document.querySelector(""label"");

label.innerHTML = label.innerText
  .split("""")
  .map(
    (words, i) => `<span style=""transition-delay:${i * 30}ms"">${words}</span>`
  )
  .join("""");

"

先看一看效果,是不是很炫酷啊??


HTMl代码如下:

<!DOCTYPE html>
<html>
  <head>
    <meta charset=""UTF-8"" />
    <title>CSS特效:鼠标悬停效果</title>
    <link rel=""stylesheet"" href=""style.css"" />
  </head>
  <body>
    <div class=""cursor""></div>
    <ul>
      <li><a href=""#"">每天嘻嘻哈哈</a></li>
      <li><a href=""#"">热爱生活,快乐成长</a></li>
      <li><a href=""#"">CSS特效:鼠标悬停效果</a></li>
    </ul>
    <script src=""script.js""></script>
  </body>
</html>

CSS代码如下:

{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: #222;
    cursor: none;
}

.cursor {
    position: fixed;
    width: 20px;
    height: 20px;
    transform: translate(-50%, -50%);
    pointer-events: none;
    opacity: 0;
    border-radius: 50%;
    background-color: #0f0;
    box-shadow: 0 0 5px #0f0,
    0 0 15px #0f0,
    0 0 30px #0f0,
    0 0 60px #0f0;
    transition: opacity 0.5s;
    z-index: 999;
}

body:hover .cursor {
    opacity: 1;
}

ul {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    list-style: none;
}

ul li {
    padding: 10px 0;
}

ul a {
    text-decoration: none;
    color: #bbb;
    cursor: none;
}

ul li span {
    font-size: 2.5em;
    letter-spacing: 0.05em;
    transition: 0.25s;
}

ul li:hover span {
    color: #0f0;
    text-shadow: 0 0 5px #0f0,
    0 0 15px #0f0,
    0 0 30px #0f0,
    0 0 60px #0f0,
    0 0 100px #0f0;
}

JavaScript代码如下:

let cursor = document.querySelector("".cursor"");

document.addEventListener(""mousemove"", (e) =&gt; {
  cursor.style.left = `${e.pageX}px`;
  cursor.style.top = `${e.pageY}px`;
});

document.querySelectorAll(""ul a"").forEach((text) =&gt; {
  text.innerHTML = text.innerText
    .split("""")
    .map(
      (words, i) =&gt; `&lt;span style=""transition-delay:${i * 30}ms""&gt;${words}&lt;/span&gt;`
    )
    .join("""");
});

"