javascript - CSS 插入阴影不起作用,创建垂直线

标签 javascript jquery html css

试图在将鼠标悬停在 div 上时在其上创建一个嵌入阴影,但唯一显示的是 div 左侧的白色垂直条。我在 Chrome 36.0.1985.143 中工作。如果我用普通阴影替换嵌入阴影,效果会很好。

HTML:

<div id="innerContent">
    <div id="digSynth" class="selection">
        <div class="thumbnail">
            <img src="Digital Synthesizer/thumbnail.png">
        </div>
        <div class="description">
            <span class="infoItem">Control the pitch of a speaker by adjusting the light level</span>
        </div>
    </div>
    <div id="ledDom" class="selection">
    </div>
</div>

JS:

$(document).ready(function(){

    //highlight on hover mechanism
    $(".selection").mouseover(function(){
        $(this).css("box-shadow", "inset 0.8em 0em white");
    });
    $(".selection").mouseout(function(){
        $(this).css("box-shadow", "");
    });

});

它基本上是在一个较大的 div 中并排放置的两个小 div。左边的小div里面有一个img。所有三个 div 都是 position: absolute。白色条出现在大 div 的内部,只要我将鼠标悬停在大 div 上,它就会一直存在。

最佳答案

box-shadows 的(推荐的)css 语法如下:

box-shadow: (the extra-options can be here too but it's considered a bad practice so don't do that) [x-offset y-offset blur] extra-options

[括号内的东西] 必须按此顺序排列(它们也必须彼此相邻)

.selection {
    transition:box-shadow 0.3s;
}
.selection:hover {
    box-shadow:.8em .8em 1.6em red inset;
}

JSFiddle

关于javascript - CSS 插入阴影不起作用,创建垂直线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25587232/

相关文章:

javascript - 如何以编程方式打开传单标记的工具提示?

javascript - YouTube API - 根据 API 抓取缩略图的鼠标悬停更改 H1 标签?

jquery - 将新标签附加到特定元素之后的 <div> 中?

Javascript Konami 代码,淡入/淡出 Div

javascript - jQuery : fadeIn image when attribute change has loaded

javascript - 当 AJAX 更新我的页面上的数据时更新 HighCharts 图表

javascript - 是否有可能 "upload"只有客户端的文件? (不涉及服务器)

javascript - 替换jquery中ul的<a>文本

javascript - jQuery .load() 在新选项卡中打开脚本

html - 如何在父 div 中水平居中放置三个 div?