等高柱宽问题 [英] Equal height columns width issue

查看:91
本文介绍了等高柱宽问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3列延伸到相等的高度.现在唯一的问题是,如果我只有2列,它们会扩展其宽度并占用100%的主容器.所以基本上我需要它们具有1、2或3列的相同宽度. 关于如何实现这一点的任何想法? 非常感谢!

I have 3 columns that extend to equal height. The only problem now is that if I have 2 columns only they expand their width and take 100% of the main container. So basically I need them to have the same width wether it's 1, 2 or 3 columns. Any idea on how to achieve this? Many thanks!

小提琴演示

Fiddle Demo

.content > img {
    vertical-align:top;
}
#wrapper {
    height: 100%;
    width: 100%;
    margin: 20px auto;
    display:table;
    overflow: hidden;
    border-spacing: 30px;
}
#wrapper > .col {
    display: table-cell;
    width: 30.3%;
    margin: 0 15px 3px;
    background-color: #fff;
    text-align: center;
    position: relative;
    height: 100%;
    padding-bottom: 2px;
    border:1px solid #000;
}
#wrapper > .col > .content {
    padding:0 0 35px;
    height:100%;
}
.content {
    margin-bottom:30px;
    position: relative;
}
.content > p {
    vertical-align:top;
}
.content h3 {
    font-size:1.375rem;
    font-weight:400;
    text-align:center;
    margin-bottom: 20px;
    padding: 25px 27px 0;
}
.content p {
    text-align:left;
    padding: 0 27px 30px;
}
.button.moreinfo {
    margin-top: 5px;
    margin-bottom: 0;
    padding-top: 0.5rem;
    padding-right: 0.3rem;
    padding-bottom: 0.5rem;
    padding-left: 0.3rem;
    background-color: #2a2a2a;
    font-size: 0.9rem;
    color: #f39c12;
    font-weight: 400 !important;
}
div.btn-align-bottom {
    position:absolute;
    bottom:50px;
    left:0;
    right:0;
}
.info-box {
    margin-bottom:0;
    margin-top: 15px;
}
.info-box img {
    max-width: 100%;
    max-height: 100%;
    vertical-align: middle;
}
.info-box-inner {
    background: #FFF;
    padding:25px 27px 35px;
    display:inline-block;
    overflow:hidden;
    float:none;
    min-height:270px;
    text-align:center;
    -moz-box-shadow: 0px 1px 2px rgba(48, 48, 48, 0.3);
    -webkit-box-shadow: 0px 1px 2px rgba(48, 48, 48, 0.3);
    box-shadow: 0px 1px 2px rgba(48, 48, 48, 0.3);
    z-index:1;
}
.info-box-inner p {
    text-align:left;
}
.info-box-inner h3 {
    font-size:1.375rem;
    font-weight:400;
    text-align:center;
}

推荐答案

好的,最后这是我的工作jsFiddle演示.有关结果,请参见 http://jsfiddle.net/rfjg4/10/show/.

Okay, finally here is my working jsFiddle demo. See http://jsfiddle.net/rfjg4/10/show/ for the result.

我在第二个包装器和CSS中添加了类col2:

I added the class col2 to the second wrapper and the CSS:

.wrapper.col2:after {
    content: "";
    display: table-cell;
    width: 30.3%;
    margin: 0 15px 3px;
    background-color: #fff;
    text-align: center;
    height: 100%;
    padding-bottom: 2px;
}

使用上述代码,会将具有空内容的新单元格添加到<div class="wrapper col2">标记.

With the above code a new cell with empty content is added to the <div class="wrapper col2"> tag.

或者,您也可以使用CSS 3选择器来避免col2:

Alternatively you can avoid the col2 by using CSS 3 selectors:

wrapper:first-child:nth-last-child(3) ~ div::after {
    content: "";
    display: table-cell;
    width: 30.3%;
    margin: 0 15px 3px;
    background-color: #fff;
    text-align: center;
    height: 100%;
    padding-bottom: 2px;
}

请参见此jsFiddle CSS是否可以检测子代数元素具有?来解释选择器).

See this jsFiddle or http://jsfiddle.net/rfjg4/11/show/ for an example. (See this Stackoverflow question Can CSS detect the number of children an element has? for explanation of the selectors).

一些注意事项:

  • 在您的jsFiddle示例中,您为<div>使用了两次id="wrapper".您必须将id更改为class(并更新CSS)
  • 第17行(以及其他行)中还有一个</div>.那些标签在jsFiddle中标记为红色.
  • 您的CSS不需要position:relative;(在示例中已将其删除).
  • In your jsFiddle example you used two times id="wrapper" for a <div>. You have to change the id to a class (and update your CSS)
  • There is one </div> extra in line 17 (and in other lines, too). Those tags are marked red in jsFiddle.
  • You do not need position:relative; in your CSS (I deleted it in the example).

这篇关于等高柱宽问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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