::Before And ::After Pseudo Elements

/*
pseudo elements ::before ::after CONTENT not element
content:'' ---required
img --- does not work
*/




INDEX.HTML:


<!DOCTYPE html>
<html lang="en">
<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">
    <title>CSS Tutorial</title>    
    <link rel="stylesheet" href="styles.css">

   
</head>
<body >
    <p>before and after pseudo element</p>
    <div>
        <img src="./detox.jpg" alt="">
    </div>
</body>
</html>

CSS:

 /*

pseudo elements ::before ::after CONTENT not element
content:'' ---required
img --- does not work
*/

p::before {
    content: "read this -";
    color: red;
    background: yellow;
    font-weight: bold;
    font-size: 2rem;
    display:block;
}
p::after {
    content: "end";
    font-size: 2rem;
    color: red;
    background: yellow;
    font-weight: bold;
    display: block;
    width: 50px;
    height: 50px;
}
div {
    width: 40vw;
    margin: 100px auto;
    position: relative;
}
img {
    width: 100%;
    display: block;
}

div::before {
    content: "";
    border: 2px solid green;
    width: 100%;
    height: 100%;
    position: absolute;
    box-sizing: border-box;
    top: -40px;
    left: -40px;
    z-index: -2;
    transition: all 1s linear;
}
div::after {
    content: "";
    border: 2px solid gray;
    width: 100%;
    height: 100%;
    position: absolute;
    box-sizing: border-box;
    background: grey;
    top: -20px;
    left: -20px;
    z-index: -1;
    transition: all 0.5s linear;
}

div:hover::after,
div:hover::before {
    left: 0;
    top: 0;
}

评论

此博客中的热门博文

又一款美国免费主机,无限流量动态X10hosting

Nginx【Docker系列】一个反向代理神器——Nginx Proxy Manager