css实现可拖动改变容器大小的冰块和水效果代码

css实现可拖动改变容器大小的冰块和水效果代码

<!DOCTYPE html>
<html lang="en" >

<head>

  <meta charset="UTF-8">
  

  
<style>
html {
  font-family: "Righteous", cursive;
  height: 100%;
}

body {
  min-height: 100%;
  display: grid;
  grid-template:
    "." 1fr
    "g" auto
    "a" auto
    "." 1fr
    "f" auto;
  justify-items: center;
  align-content: center;
}

main {
  container-type: inline-size;
  container-name: glass;
  background: azure;
  border: thin solid slategray;
  border-radius: 60% 60% 40% 40% / 0.25em 0.25em 0.5em 0.5em;
  grid-area: g;
  min-width: min(8em, 80vw);
  max-width: min(64em, 80vw);
  overflow: hidden;
  resize: horizontal;
  display: grid;
  position: relative;
}

main::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  background: aliceblue;
  border: thin solid slategray;
  transform: translatey(-40%);
  border-radius: 40% / 0.25em;
  height: 0.5em;
}

@keyframes bounce {
  to {
    transform: translate3d(-0.25em, -0.25em, 0) scale(1.3);
  }
}

/* arrow goes away once it's been resized */
main:not([style])::after {
  animation: bounce 1s infinite alternate;
  color: white;
  content: "↘";
  font-size: 2em;
  font-weight: bold;
  position: absolute;
  bottom: 0;
  right: 0;
  z-index: 1;
  opacity: 0;
}

main:hover::after {
  opacity: 0.85;
}

h1,
section {
  grid-area: 1 / 1 / -1 / -1;
}

h1 {
  background: radial-gradient(
    ellipse 0.5em 50% at calc(100% - 0.5em),
    hsl(0 0% 100% / 0.5),
    transparent
  );
  color: white;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  text-shadow: 1px 1px 0 var(--shadow, hsl(0 0% 0% / 0.5));
  margin: 0;
  z-index: 1;
}

h1 span::before {
  content: var(--before);
}
h1 span::after {
  content: var(--after);
}

section {
  background: linear-gradient(-182deg, azure 1em, transparent 1.1em),
    radial-gradient(ellipse at top right, var(--glow, cyan), transparent)
      var(--water, navy);
  display: flex;
  flex-wrap: wrap;
  margin-top: 2em;
  padding: 0 0.25ch 1em;
  place-content: center;
  transition: background-color 300ms;
}

@keyframes bubble {
  from {
    opacity: 0;
    transform: translatey(18em) scale(0.5);
  }
  to {
    opacity: 0.5;
    transform: translatey(0px);
  }
}

section::before,
section::after {
  content: "";
  animation: bubble 7s 3s ease-in infinite both;
  height: 1em;
  width: 1em;
  background: radial-gradient(
      ellipse at right,
      hsl(120 50% 100% / 1),
      transparent
    )
    hsl(0 0% 100% / 0.5);
  position: absolute;
  border-radius: 100%;
}

section::before {
  left: 20%;
}

section::after {
  right: 45%;
  animation-delay: -2s;
  animation-duration: 9s;
}

div {
  --cube: 4em;
  background: radial-gradient(
      ellipse at right,
      hsl(120 50% 100% / 1),
      transparent
    )
    hsl(0 0% 100% / 0.5);
  border: thin solid hsl(0 0% 100% / 0.75);
  border-radius: 0.25em 0.5em / 0.5em 0.75em;
  height: var(--cube);
  width: var(--cube);
  transform: rotate(calc(3deg + var(--amt, 8deg) * var(--dir, 1)));
  transition: height 300ms, width 300ms;
  margin: -0.125em;
  mix-blend-mode: var(--ice, overlay);
}

div:nth-child(odd) {
  --amt: 3deg;
  --dir: -1;
}

div:nth-child(3n + 3) {
  --amt: 2deg;
  --dir: -1;
}

div:nth-child(5n + 3) {
  --ice: soft-light;
  --amt: 5deg;
}

div:nth-child(3n + 1) {
  --ice: color-dodge;
  --amt: 6deg;
  opacity: 0.75;
}

@container glass (min-width: 14em) {
  h1 {
    --after: "?";
  }

  section {
    --water: rebeccapurple;
  }
  div {
    --cube: 4.5em;
  }
}

@container glass (min-width: 24em) {
  h1 {
    --after: "???";
  }

  section {
    --water: darkviolet;
  }
  div {
    --cube: 5em;
  }
}

@container glass (min-width: 34em) {
  h1 {
    --after: "!";
  }
  section {
    --water: mediumvioletred;
  }
  div {
    --cube: 5.5em;
  }
}

@container glass (min-width: 44em) {
  section {
    --water: maroon;
  }
  div {
    --cube: 5.5em;
  }
}

@container glass (min-width: 34em) and (max-width: 54em) {
  section {
    --glow: pink;
  }
  h1 {
    --before: "probably not ";
  }
}

@container glass (min-width: 54em) {
  h1 {
    --before: "absolutely ";
    --shadow: white;
    color: black;
  }

  section {
    --water: transparent;
  }
  div {
    --cube: 5.5em;
  }
}

aside {
  grid-area: a;
  text-align: center;
}

footer {
  font-family: monospace;
  background: aliceblue;
  border-top: thin solid slategray;
  grid-area: f;
  justify-self: stretch;
  padding: 0 1em;
  text-align: center;
}
</style>



</head>

<body >
  <main>
  <h1><span>water</span></h1>
  <section>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
  </section>
</main>
<aside>resize it ↔️</aside>

  
  
  

</body>

</html>
 

网友评论0