JQuery 设置元素的高度和宽度相等

有时需要设置下面的情况,即 <div> 的高度和宽度是相等的、并且随着屏幕的大小变化而变化。这样就需要用 js 来控制元素在页面上的显示。

104052_xHgM_2320053.png

<html>

<body>

<div class="row text-center margin-top-20p">

            <div class="col bgcolor-FF9600 border-radius-5p margin-2p height-width">

                <p class="white">你是</p>

                <p class="white" ng-bind="userLever.name"></p>

            </div>

            <div class="col bgcolor-FECA14 border-radius-5p margin-2p height-width" ng-if="userLever.discount != 10">

                <p class="white">享受</p>

                <p class="white">{{userLever.discount}}折</p>

            </div>

            <div class="col bgcolor-FECA14 border-radius-5p margin-2p height-width" ng-if="userLever.discount == 10">

                <p class="margin-top-20p white">不享受</p>

                <p class="white">折扣</p>

            </div>

            <div class="col bgcolor-A5D600 border-radius-5p margin-2p height-width">

                <p class="white">加入时间</p>

                <p class="white" ng-bind="addTime"></p>

            </div>

        </div>

<body>

</html>

<script type="text/javascript">

//设置元素的高度

var height = $(".height-width").width();

$(".height-width").css("height",height );

$(".height-width-child").css("height",height );

$(".height-width p:first-child").css("margin-top",Math.ceil(height/4)+"px");

$(".height-width-child p").css("line-height",height+"px");

</script>


转载于:https://my.oschina.net/jack088/blog/477242

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值