如何用css控制一个容器的显示与隐藏

html-css013

如何用css控制一个容器的显示与隐藏,第1张

可以利用css的伪类样式来控制,

<div class="dv-show">

    移上来可以查看

</div>

<style>

.dv-show{display:nonewidth:100pxheight:100pxbackground:#000color:#fff}

.div-show:hover{display:block}

</style>

根据页面的需要有时候我们需要隐藏一些元素,但当鼠标移到某一个区域的时候,我们希望这些隐藏的元素显示出来。用css网页布局,我们该如何实现呢?首先我们将这一隐藏元素在页面中隐藏掉,可以应用displasy属性,关于displasy属性可以参考这里。我们再对链接添加onMouseOver、onMouseOut的小脚本,改变displasy属性的相关值,让隐藏的元素显示出来即可。我们看下面的xhtml代码:http://www.it130.cn/" style="color:blue" onMouseOver="document.all.hehe.style.display='block'" onMouseOut="document.all.hehe.style.display='none'">

<!DOCTYPE html>

<html>

<head>

    <meta charset="utf-8">

    <title>底部对齐</title>

    <style>

    #a{

        margin: 0 auto

        width: 500px

        height: 500px

        background: #CCCCE7

        position: relative            /* 父级容器相对定位 */

    }

    #b{

        width: 200px

        height: 200px

        background: green

        position: absolute        /* 相对于容器绝对定位 */

        bottom: 0px            /* 距离容器底部0px,无论容器高度多少,

                                      都距离底部0px */

    }

    </style>

</head>

<body>

<div id="a">

    <div id="b"></div>

</div>

</body>

</html>