css去掉全局高度

html-css09

css去掉全局高度,第1张

css去掉全局高度,1.场景描述

有层级为3的一组div标签,class名分别为container、wrap、content,需求是当盒子wrap的高度大于盒子container时,可以进行滚动。

但是此时盒子wrap使用了一个全局css样式height:100%,就是说此时container 、wrap高度一致,需要将wrap改为自适应高度(即内容盒子content撑开的高度)

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html charset=utf-8" />

<title>demo</title>

<style type="text/css">

    *{margin:0padding:0}

    .box{width:300pxheight:30pxbackground:#da251a}

    .click1{width:120pxheight:30pxline-height:30pxtext-align:centercolor:#fffbackground:#000margin-bottom:10px cursor:pointer}

    .click2{width:120pxheight:30pxline-height:30pxtext-align:centercolor:#fffbackground:#000cursor:pointer}

</style>

<script type="text/javascript" src="jquery-1.8.2.min.js"></script>

<script type="text/javascript">

    $(function(){

        $(".click1").click(function(){

            var bHeight=$(".box").height()

            bHeight+=30

            $(".box").css("height",bHeight)

        })

        $(".click2").click(function(){

            var bHeight=$(".box").height()

            bHeight-=30

            $(".box").css("height",bHeight)

        })

    })

</script>

</head>

<body>

<div class="click1">增加</div>

<div class="click2">减少</div>

<div class="box"></div>

</body>

</html>

自己把对应的jq库文件引入下即可。

写的不好,请谅解!