【问题标题】:mouse hover, css div effect, alpha and new button鼠标悬停、css div 效果、alpha 和新按钮
【发布时间】:2013-06-15 06:55:27
【问题描述】:

我有一个小问题。

我有 200*200 像素的 div。我需要效果: - 当用户鼠标悬停在 div 上时:alpha 70% 黑色图片 - 在图片(或文本链接)中间显示新按钮,例如“添加到购物车”

您可以在此处查看我的示例:http://jsfiddle.net/t8jPN

    <div class="wrapper">
<div class="ribbon-wrapper-green"><div class="ribbon-green">NEW</div></div>
<img src="http://cdn.sheknows.com/articles/2011/05/summer-dresses4.jpg"></img>
</div>

.wrapper {
margin: 50px auto;
width: 200px;
height: 200px;
background: white;
border-radius: 2px;
-webkit-box-shadow: 0px 0px 8px rgba(0,0,0,0.3);
-moz-box-shadow:    0px 0px 8px rgba(0,0,0,0.3);
box-shadow:         0px 0px 8px rgba(0,0,0,0.3);
position: relative;
z-index: 90;
}

.ribbon-wrapper-green {
width: 85px;
height: 88px;
overflow: hidden;
position: absolute;
top: -3px;
right: -3px;
}

.ribbon-green {
font: bold 15px Sans-Serif;
color: #ffffff;
text-align: center;

-webkit-transform: rotate(45deg);
-moz-transform:    rotate(45deg);
-ms-transform:     rotate(45deg);
-o-transform:      rotate(45deg);
position: relative;
padding: 7px 0;
left: -5px;
top: 15px;
width: 120px;
background-color: #BFDC7A;
background-image: -webkit-gradient(linear, left top, left bottom, from(#BFDC7A), to(#8EBF45)); 
background-image: -webkit-linear-gradient(top, #BFDC7A, #8EBF45); 
background-image:    -moz-linear-gradient(top, #BFDC7A, #8EBF45); 
background-image:     -ms-linear-gradient(top, #BFDC7A, #8EBF45); 
background-image:      -o-linear-gradient(top, #BFDC7A, #8EBF45); 
color: #6a6340;
-webkit-box-shadow: 0px 0px 3px rgba(0,0,0,0.3);
-moz-box-shadow:    0px 0px 3px rgba(0,0,0,0.3);
box-shadow:         0px 0px 3px rgba(0,0,0,0.3);
}

.ribbon-green:before, .ribbon-green:after {
content: "";
border-top:   3px solid #6e8900;   
border-left:  3px solid transparent;
border-right: 3px solid transparent;
position:absolute;
bottom: -3px;
}

.ribbon-green:before {
left: 0;
}
.ribbon-green:after {
right: 0;
}

谢谢

【问题讨论】:

  • 请贴出你的代码
  • 我编辑帖子并粘贴代码。

标签: css hover effect


【解决方案1】:

基本思想是对三个 div 进行包装。一个带有图像的 div,一个带有阴影的 div,另一个用于按钮。

阴影和按钮(或链接)有单独的 div 的原因是为了避免按钮上的透明效果。

我想有更好的方法来解决这个问题,但我会使用这个,因为我觉得它更容易。

演示http://jsfiddle.net/chepe263/a97FS/10/

<html>
    <head>
        <style type="text/css">
            .contenedor{
                position:relative;
                width: 200px;
                height: 200px;
                border: 1px solid black;

            }
            .atCorner{
                position: absolute;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;

            }
            .escondido{
                display: none;    
            }
            .shadow{
                background-color: black;
                zoom: 1;
                filter: alpha(opacity=70);
                opacity: 0.7;

            }
            .button{
                text-align: center;    
            }
            .button button{
                margin-top: 40%;

            }   
        </style>
        <script type="text/javascript">
            $('.contenedor').mouseenter(function(){
                jQuery(this).find('.shadow, .button').fadeIn();
            }).mouseleave(function(){
                jQuery(this).find('.shadow, .button').fadeOut();
            }); 
        </script>
    </head>
    <body>
        <div class="contenedor">
            <div class="atCorner" id="picture">
                <img src="http://cdn.sheknows.com/articles/2011/05/summer-dresses4.jpg" />
            </div>
            <div class="atCorner escondido shadow" id="">
            </div>    
            <div class="atCorner escondido button" id="">    
                <button>Buy it</button>
            </div>
        </div>
    </body>
</html>

【讨论】:

    猜你喜欢
    • 2014-07-05
    • 1970-01-01
    • 2013-01-17
    • 1970-01-01
    • 2013-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多