保持填充不会使元素变大? [英] keep padding from making the element bigger?

查看:18
本文介绍了保持填充不会使元素变大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个宽度为 70% 的元素,它漂浮在一个宽度为 30% 的元素旁边,但是当我添加 25px 的填充时,它会扩展元素并破坏格式,是否存在有什么办法可以让它只是增加内容与边缘的距离而不是让它变大?

I have an element with a 70% width, and it is floating beside an element with 30% width, but when I add 25px of padding it expands the element and breaks the format, is there any way to make it just increase the contents distance from the edge as opposed to just making it bigger?

推荐答案

当您使用 border-box 模型时,填充包含在框大小中.请参阅此处了解详情.

When you use the border-box model, the padding is included in the box size. See here for details.

<!DOCTYPE html>
<html>
    <head>
        <title>padding example</title>
        <style type="text/css">
        .seventy {
            display: block;
            float: left;
            width: 70%;
            background-color: red;
        }
        .thirty {
            display: block;
            float: left;
            width: 30%;
            padding: 25px;
            box-sizing: border-box;
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            background-color: green;
        }
        </style>
    </head>
    <body>
        <div class="seventy">Stuff</div>
        <div class="thirty">More Stuff</div>
    </body>
</html>

这篇关于保持填充不会使元素变大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆