position:static,relative,absolute,fixed

 


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 >
    <div>
        <p class="one">
            Lorem ipsum, dolor sit amet consectetur adipisicing elit. Magni suscipit quod labore temporibus consequatur eius soluta. Exercitationem ipsa reprehenderit corrupti?
        </p>
        <p class="two">
            Lorem ipsum, dolor sit amet consectetur adipisicing elit. Magni suscipit quod labore temporibus consequatur eius
            soluta. Exercitationem ipsa reprehenderit corrupti?
            <span class="special" >hey i'm absolute</span>
        </p>
    </div>
    <button type="button">input</button>
</body>
</html>

CSS:

div {
    border: 3px solid red;
    margin-top: 30px;
    background: yellow;
    position: relative;
}
.one {
    background: blue;
}
.two {
    background: green;
    /* position: relative; */
}
.special {
    background: lightcoral;
    font-size: 20px;
    position: absolute;
    right: 50%;
    top: 50%;
}
button {
    background: red;
    font-size: 40px;
    color: white;
    position: fixed;
    top: 0;
    right: 0;
}



评论

此博客中的热门博文

通过Graphql成功地查询Contentful,以便在我的gatsby项目中访问和显示图像

Oracle忘了保存,Oracle Cloud甲骨文云服务器忘记SSH秘钥或未设置Public key的解决办法...

国外免费虚拟主机主要搭建网站