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

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

问题描述

我有一个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天全站免登陆