簡體   English   中英

在帶有CSS的偽元素之后添加:after彈出窗口

[英]add popup on :after pseudo element with css

我很有趣,當我將鼠標懸停:after偽元素上時,是否可以在:after偽元素上添加一個小的彈出框? 完全不用HTML就能做到嗎? 我試圖在網上搜索它,但似乎總是需要標記中的某種<span><div>元素來顯示彈出文本。 雖然我想用純CSS做到這一點。 有一些技巧嗎?

button::after {
  content: "i";
  color: blue;
}

button:hover::after {
  color: red;
  cursor: pointer;
  // add css to display popup
}

僅用於演示。

嘗試這個:

<!DOCTYPE html>
<html>
<head>
<style>
.block{display:none;padding:20px;}
button::after {
  content: "i";
  color: blue;
  height:
}
button:hover::after {
  color: red;
  cursor: pointer;
}
button:hover~.block{display:block !important;background-color:red !important;}
</style>
</head>
<body>
    <button class="button"></button>
    <div class="block">Alert</div>
</body>
</html>

當然,有一種方法可以做到,基本上:after:before偽總是需要一個元素在該元素之前或之后,但是我們可以將其與懸停混合以完成您想要的操作,如下所示,運行下面的代碼以查看它如何為您工作:

 button { width: 120px; height: 50px; position: relative; font-size: 32px; cursor: pointer; } button:after { content: 'x'; font-size: 32px; height: 100%; width: 100%; position: absolute; display: none; } button:hover:after { display: block; color: red; cursor: pointer; top: 6px; } 
 <button class="btn">x</button> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM