【发布时间】:2017-08-30 14:51:24
【问题描述】:
我有一个容器,当我单击它时,它会获得焦点并显示他内部的隐藏内容。
现在,在隐藏容器中有一个按钮,当您单击它时,它会获得焦点并关闭父级。
它适用于所有浏览器,除了 ios 和 macos 上的 safari。
我正在寻找一个干净的 CSS 解决方案。
HTML
<div class="box" tabindex="0">
<div class="front">CLICK ME</div>
<div class="hidden">
<button class="close">close button</button>
</div>
</div>
SASS
.box{
position:relative;
height:200px; width:200px;
}
.front,
.hidden{height:100%; width:100%; position:absolute; }
.close{height:100px; width:100px;}
.box:focus{
.front{display:none;}
.hidden{display:block;}
}
.front{background:blue; color:white;}
.hidden{background:red; display:none;}
【问题讨论】: