我正嘗試僅使用CSS和HTML創建自定義組件。 組件的行爲將如下所示:當選擇輸入(具有焦點)時,打開另一個容器。當容器被打開輸入失去焦點 的問題是和容器首先點擊:(關閉當其他元素集中時,輸入會失去焦點
所以,我怎麼能有輸入焦點集中,當我打開的容器上重點?
<div class="block">
<label>Field</label>
<input type="text" tabindex="-1"/>
<div tabindex="-1" class="infront">
Keep this bastard open.<br/>
<br/>
while clicking on this div
</div>
</div>
CSS
.block{
position: relative;
display: inline-block;
margin: 50px;
}
.infront{display: none;}
.block input[type="text"]:focus ~ .infront {
display: block;
position: absolute;
top:100%;
width: 80%;
right: 0;
background: #ccc;
opacity:0.8;
}
對不起,我不能跟着你,我真的不明白是什麼問題 – MKAD
我覺得你的代碼工作當輸入聚焦時,「.infront」精 – Sharmila
@MKAD容器被打開,如果我點擊進入隱藏的「.infront」容器,因爲輸入失去焦點。我需要的是,如果我點擊裏面,然後隱藏,如果我點擊外面的容器,打開該容器.... – BurebistaRuler