html - 不同列之间的边界距离

标签 html css

这就是我想要实现的目标: enter image description here

我遇到的问题是,在调整列之间的空白区域的大小时,列之间的空白区域总是在宽度和高度上看起来与其他区域不同:

这是我的标记:

<div id="wrapper">  
   <div id="header" class="clearfix"></div>
   <div class="layout clearfix"> 
   <div class="small_box top_left ">
    <img class="fittobox" src="img/home7.jpg" alt="home7" width="800" height="689">
   </div>
   <div class="small_box top_middle large_h">
    <img class="fittobox" src="img/home6.jpg" alt="home6" width="747" height="1330">
   </div>
   <div class="small_box top_right">
    <img class="fittobox" src="img/home5.jpg" alt="home5" width="503" height="460">
   </div>
   <div class="small_box bottom_left">
     <img class="fittobox" src="img/home2.jpg" alt="home2" width="830" height="800">
   </div>
   <div class="small_box bottom_right">
     <img class="fittobox" src="img/home7.jpg" alt="home7" width="800" height="689">
   </div>               
   </div><!-- Layout -->        
 </div><!-- wrapper -->

有了这个 LESS:

    /*---- HOME - SHOP - TIENDAS LAYOUT ----*/
    .layout{
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        right: 0px;
        bottom: 0px;
        z-index: 1;
        overflow: hidden;
        min-height: 100%;
        max-height: 100%;
        .fittobox{
            display: none;
        }
        .small_box{
            width: 33%;
            overflow: hidden;
            height: 45%;
            position: absolute;
            &.top_left{
                top: 3%;
            }
            &.top_middle{
                top: 3%;
                left: 50%;
                margin-left: -16%;
            }
            &.top_right{
                top: 3%;
                right: 0;
                margin-right: 0;
                width: 32%;
            }
            &.bottom_left{
                bottom: 40px;
                left: 0;
            }
            &.bottom_middle{
                bottom: 40px;
                left: 50%;
                margin-left: -16%;
            }
            &.bottom_right{
                bottom: 40px;
                right: 0;
                margin-right: 0;
                width: 32%;
            }
            &.large_h{
                top: 3%;
                height: 93%;
            }
            &.fullscreen{
                width: 100%;
                height: 100%;
            }
            &.halfscreen{
                width: 67%;
                height: 93%;
                top: 3%;
            }
    }

最佳答案

标准盒子模型将边框、填充和边距等内容放在盒子外面。

这意味着,如果您有一组大小以百分比表示的框,并且您想要将其加起来达到 100%,则它们之间不能有填充。

但是,您可以使用 CSS box-sizing:border-box; 更改框模型,使填充等位于框内。

有了这个设置,您现在可以指定您的框,使它们加起来达到 100%,但仍然以像素为单位为它们提供填充和边距,而不会弄乱布局。

希望对您有所帮助。

在此处阅读有关 box-sizing 的更多信息:https://developer.mozilla.org/en-US/docs/CSS/box-sizing

浏览器兼容性:不支持 IE6 或 IE7。在所有其他浏览器中工作正常。 (IE6/7 的 polyfill can be found here)。

关于html - 不同列之间的边界距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16277729/

相关文章:

html - 如何在 HTML5 Canvas 中显示更平滑的渐变?

php - 按下后退按钮时重新提交表单

javascript - 使用javascript调整图像大小而不会造成视觉干扰

css - 使用边框时节点的背景图像被裁剪

html - IMG 上的最大高度在固定 DIV 内不起作用

javascript - 想要根据给定的年龄计算出生日期

css - 具有可变 li 宽度的 ul

css - div 内的文本区域

javascript - 子菜单错误

html - z-index 不允许我与后面的内容进行交互