美文网首页
:focus-within的冒泡触发

:focus-within的冒泡触发

作者: 华山令狐冲 | 来源:发表于2021-02-17 10:34 被阅读0次

看个具体的例子:

<html>
<style>
html,
body,
.g-father,
.g-children {
    padding: 30px;
    border:1px solid green;
}

input {
    display: block;
    border: none;
    outline: none;
    border: 1px solid black;
    margin: 0 auto;
}

input:focus {
    background: yellow;
    }

html:focus-within {
    background: red;
}

body:focus-within {
    background: purple
}

.g-father:focus-within {
    background: white;
}

.g-children:focus-within {
    background: pink;
}

.g-html,
.g-body,
.g-fath,
.g-chil {
    position: fixed;
}

.g-html {
    left: 30px;
    top: 10px;
}
.g-body {
    left: 60px;
    top: 40px;
}

.g-fath {
    top: 70px;
    left: 90px;
}

.g-chil {
    top: 100px;
    left: 120px;
}
</style>
<div class="g-father">
    <div class="g-children">
        <input type="button" value="Button">
    </div>
</div>

<div class="g-html">HTML</div>
<div class="g-body">BODY</div>
<div class="g-fath">Father</div>
<div class="g-chil">Children</div>
</html>

初始页面:

button获得focus后:

button变成黄色:

children变成粉色,father变成白色,body变成紫色,html变成红色

更多Jerry的原创文章,尽在:"汪子熙":


相关文章

  • :focus-within的冒泡触发

    看个具体的例子: 初始页面: button获得focus后: button变成黄色: children变成粉色,f...

  • 我的前端入门笔记(11)--事件冒泡、捕获、代理

    1.事件冒泡与捕获 冒泡:先触发内部事件,再触发外部事件;捕获:先触发外部事件,再触发内部事件; addEvent...

  • js事件监听 事件冒泡 和css3新增

    事件监听:事件捕获 目标阶段 冒泡阶段 事件冒泡:当使用事件冒泡时,子元素先触发,父级元素后触发。 //阻止事件冒...

  • 关于事件

    事件冒泡:事件冒泡会从当前触发的事件目标一级一级往上传递,依次触发,直到document为止阻止事件冒泡:even...

  • 事件冒泡

    冒泡实例: btn1按钮 进行了阻止冒泡 点击只触发btn1()事件btn2按钮 没有进行阻止冒泡 点击之后会触发...

  • 事件冒泡

    事件冒泡冒泡指的是事件向上传递,当后代元素上的事件被触发时,其祖先元素的相同事件也会被触发——开发中大部分情况冒泡...

  • 温习:事件冒泡、事件捕获、事件委托

    事件冒泡 事件冒泡会从当前触发事件的目标一级一级向上传递,依次触发,直到document为止。addEventLi...

  • 什么是事件冒泡/捕获?

    事件冒泡:子元素事件的触发会影响父元素事件开关事件冒泡:A:开启事件冒泡:element.addEventList...

  • vue事件修饰符 数据绑定与css样式

    事件修饰符 点击按钮先出发按钮的点击事件再触发div的点击事件,这就是事件冒泡 .stop阻止冒泡,点击按钮只触发...

  • vue中常见的(事件修饰符)

    .stop 阻止事件冒泡 .prevent 阻止默认事件 .self 避免事件冒泡 (只有自身才能触发) ....

网友评论

      本文标题::focus-within的冒泡触发

      本文链接:https://www.haomeiwen.com/subject/wleybktx.html