javascript - 我想将鼠标悬停在一个 div 上并显示一个伪元素

标签 javascript html css

我有一个包含 :after 伪元素的 div 我希望能够将鼠标悬停在 div 上,然后显示 :after 元素

HTML

<div class="about-us_creative-technology_top-box">
                <div class="about-us_creative-technology_h1">
                        <h1>Creative<br>Technology</h1>
                    </div>
                    <ul>
                        <li>Mobile and Web Application Development</li>
                        <li>Product Development</li>
                        <li>Software Development and Management</li>
                        <li>Architecture and Design</li>
                        <li>Cloud Management, Strategy and Management</li>
                    </ul>
            </div>
            <div class="about-us_creative-technology_square">

            </div>

CSS

&_top-box{
        height: 25vw;
        position: relative;
        &:hover + &:after{
            display: block;
        }
        &:after {
            top: 100%;
            left: 50%;
            border: solid transparent;
            content: " ";
            height: 0;
            width: 0;
            position: absolute;
            pointer-events: none;
            border-color: rgba(255, 255, 255, 0);
            border-top-color: #F2F2F2;
            border-width: 25px;
            margin-left: -25px;
            z-index: 2;
            display: none;
        }

现在我尝试使用 &:hover + &:after{ 显示: block ; }

但我似乎无法让它工作,有谁知道我该怎么做?

最佳答案

您的选择器有误。它说它是下一个 sibling ,但它不是。

&:悬停 + &:之后{

摆脱它,就去做

    &:hover::after {
        top: 100%;
        left: 50%;
        border: solid transparent;
        content: " ";
        height: 0;
        width: 0;
        position: absolute;
        pointer-events: none;
        border-color: rgba(255, 255, 255, 0);
        border-top-color: #F2F2F2;
        border-width: 25px;
        margin-left: -25px;
        z-index: 2;
        display: block;
    }

关于javascript - 我想将鼠标悬停在一个 div 上并显示一个伪元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48180077/

相关文章:

html - 水平居中表格行

javascript - JS检查getElementById是否存在

javascript - ObservableArray 不反射(reflect)数据更新

html - 使用 Html 和 CSS 更改 Pinterest 小部件的背景

javascript - 无法为 <label> 标记内的单选按钮注册更改处理程序

javascript - 用户上传的文件超过大小限制后如何在 View 上显示错误?

javascript - 调整 JS 元素的高度

html - css - 在 ie11 中使用自定义字体时阿拉伯字符错误

JavaScript - 使用 for 循环和 if-else 语句来遍历数组

php - 使用 jquery 操作 JSON 数组