【HTML+CSS 】计算属性

计算属性

💡在页面布局时(例如两栏布局、三栏布局)常常会用到宽高自适应,这时就可以使用calc()函数经常宽高的自动计算,达到自适应的效果。

  • 用于动态计算数值
    • calc(100% - 200px)运算符符号两边必须有空格

两栏布局案例

上下布局\左右布局适用于后台管理系统的布局

<style>
        /* 重置 */
        * {
            padding: 0;
            margin: 0;
        }
        /* 高度自适应 */
        html,
        body {
            height: 100%;
        }
        /* 左边导航栏 */
        .left{
            width: 200px;
            height: 100%;
            background-color: pink;
            float: left;
        }
        /* 右边主题区域 */
        .right{
            width: calc(100% - 200px);
            height: 100%;
            float: left;
            background-color: skyblue;
        }
</style>
  <div class="left"></div>
  <div class="right"></div>

💡执行结果截图
在这里插入图片描述

三栏布局(圣杯布局)案例

<style>
        * {
            padding: 0;
            margin: 0;
        }
        html,
        body {
            height: 100%;
        }


        .top{
            /* width: 100%; */
            height: 100px;
            background-color: pink;
        }
        .main{
            /* width: 100%; */
            height: calc(100% - 100px - 100px);
            background-color: skyblue;
        }
        /* 左边导航栏 */
        .left{
            width: 200px;
            height: 100%;
            background-color: green;
            float: left;
        }
        /* 右边导航 */
        .right{
            width: 200px;
            height: 100%;
            background-color: orange;
            float: right;
        }
        /* 中间主题部分 */
        .center{
            width: calc(100% - 400px);
            height: 100%;
            background-color: red;
            float: left;
        }
        /* 底部 */
        .foot{
            height: 100px;
            background-color: black;
        }
 </style>
    <div class="top"></div>
    <div class="main">
        <div class="left"></div>
        <div class="right"></div>
        <div class="center"></div>
    </div>
    <div class="foot"></div>

💡执行结果截图
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

芒果Cake

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值