0
点赞
收藏
分享

微信扫一扫

前端歌谣的刷题之路-第一百二十九题-inherit


 

前言

我是歌谣 我有个兄弟 巅峰的时候排名c站总榜19 叫前端小歌谣 曾经我花了三年的时间创作了他 现在我要用五年的时间超越他 今天又是接近兄弟的一天人生难免坎坷 大不了从头再来 歌谣的意志是永恒的 放弃很容易 但是坚持一定很酷 本题目源自于牛客网 微信公众号前端小歌谣

题目

当一个元素的定位属性设置为"inherit"时,表示从父元素继承定位属性。现在虽然类名为"inner"的里盒子设置了"left: 10px"属性,但是这是无效的,因为该盒子的定位属性值为"static"。现在给里盒子添加"position: inherit"属性,表示从类名为"outer"的父级外盒子继承定位属性,现在发现里盒子的"left: 10px"属性依然没有生效,因为外盒子的定位值依然是"static"。最后再给外盒子添加"position: relative"属性,此时会发现里盒子向右移动了10px,定位属性"left"生效了。
 完成以上所讲的步骤即可通过测试,进入下一节的学习吧。

前端歌谣的刷题之路-第一百二十九题-inherit_html

前端歌谣的刷题之路-第一百二十九题-inherit_类名_02编辑

核心代码

<!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>inherit</title>
</head>
<style type="text/css">
  * {
      margin: 0;
      padding: 0;
  }
   .outer {
      width: 100px;
      height: 100px;
      background-color: black;
      position:relative;
  }
  .inner {
      width: 80px;
      height: 80px;
      background-color: red;
      left:10px;
      position:inherit;
  }
</style>
<body>
  <section class="outer">
    <section class="inner">
        
    </section>
</section>
</body>
</html>

前端歌谣的刷题之路-第一百二十九题-inherit_html_03

举报

相关推荐

0 条评论