2

I was learning from youtube and I ended up at transition bcs of my problem with one. Any delay or duration is not workig and I don't know why. I really want to know what is a reason of executing this problem. I'm kinda of new in that stuff. :)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>::AFTER & :: BEFORE</title>
    <link rel="stylesheet" href="style.css">
<script>
body {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 5rem;
}

p::before {
  content: "";
  background-color: red;
  display: block;
  width: 10px;
  height: 10px;
  transition: all ease-in-out 250ms;
}

p::after {
  content: "";
  background-color: red;
  display: block;
  width: 10px;
  height: 10px;
  transition-property: width;
  transition-delay: 1s;
  transition-duration: 2s;
}
p:hover::before,
p:hover::after {
  width: auto;
}

</script>
</head>
<body>
    <p>Here is some content</p>
</body>
</html>
Rukuii
  • 21
  • 1

1 Answers1

0

First off, you need to include your css in a style tag if you need to inline it. Also, when you use width: auto, it will just have the browser calculate a width and set it for you. You are best off just setting the width to 100% and it will try to take up the whole space.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>::AFTER & :: BEFORE</title>
    <link rel="stylesheet" href="style.css">
  <style>
  body {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 5rem;
  }

  p::before {
    content: "";
    background-color: red;
    display: block;
    width: 10px;
    height: 10px;
    transition: all ease-in-out 250ms;
  }

  p::after {
    content: "";
    background-color: red;
    display: block;
    width: 10px;
    height: 10px;
    transition-property: width;
    transition-delay: 1s;
    transition-duration: 2s;
  }
  p:hover::before,
  p:hover::after {
    width: 100%;
  }

  </style>
</head>
<body>
    <p>Here is some content</p>
</body>
</html>
sno2
  • 3,274
  • 11
  • 37