使用CSS在悬停时显示div

时间:2013-01-24 22:16:22

标签: html css

当我将鼠标悬停在它上面时(#post-wrap),我想在div“post-wrap”中显示一个隐藏的div“delete-button”。我怎么能用CSS做到这一点?

这是我到目前为止所做的: http://jsfiddle.net/ksvrY/2/

#delete-button{
position: absolute;
right: 10px;
top: 10px;
margin: 0px 0px 0px 0px;
height: 30px;
width: 225px;
overflow: auto;
}

5 个答案:

答案 0 :(得分:0)

请参阅:http://jsfiddle.net/ksvrY/4/

   #post-wrap:hover #delete-button{
        display:inherit;
    }

也隐藏按钮:

#delete-button{
        display:none;
    }

答案 1 :(得分:0)

这将有效:

#post-wrap:hover #delete-button { 
     display:block;    
}

#delete-button { display:none; }

...如果你想得到它(适当地附加必要的供应商前缀):

#post-wrap:hover #delete-button { 
     opacity:1;    
}

#delete-button { -webkit-transition:all 1s ease-in; opacity:0; }

答案 2 :(得分:0)

#button-delete {display: none;}
#post-wrap:hover #button-delete {display: block;}

http://jsfiddle.net/ksvrY/5/

答案 3 :(得分:0)

及其现在的工作:)

html

<div id="post-wrap">
    <div id="delete-button">
        <button id="button-delete"><p> Remove </p></button>
    </div>
</div>

CSS

#post-wrap {
    position: relative;
    margin: 20px 0px 0px 20px;
    padding: 10px 10px 10px 10px;
    height: auto;
    min-height: 150px;
    width: 200px;
    border: 1px solid #ddd;
    border-radius: 4px 4px 4px 4px;
    background-color: #fff;
/*  box-shadow: rgba(0, 0, 0, 0.247059) 0px 3px 8px 0px; */
    -webkit-box-shadow: rgba(0, 0, 0, 0.2) 0px 1px 3px 0px
}

#delete-button{
    position: absolute;
    right: 10px;
    top: 10px;
    margin: 0px 0px 0px 0px;
    height: 30px;
    width: 225px;
    overflow: auto;
}

#button-delete {
    cursor: pointer;
    float: right;
    height: 30px;
    width: auto;
    border: 1px solid #bbb;
    border-radius: 4px 4px 4px 4px;
    background-color: #eee;
    background-image: -webkit-linear-gradient(top, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0) 100%);
    -webkit-box-shadow: rgba(0, 0, 0, 0.2) 0px 1px 3px 0px;
    display:none;
}

#button-delete p {
    margin: 0px 0px 0px 0px;
    padding: 0px 0px 0px 0px;
    font-family: calibri;
    font-weight: bold;
    font-size: 16px;
    color: #444;
}

#post-wrap:hover #button-delete{
    display:block;
}

答案 4 :(得分:0)

使用悬停

http://jsfiddle.net/Ptxfy/

#post-wrap:hover #delete-button { 
     display:block;    
}

#delete-button { display:none; }

我不会使用直接子选择器,因为它没有必要,可能导致问题。