2013-05-06 3 views
52

私は2つの項目を持つコンテナを持っています。これらの項目の1つはselect要素なので、HTMLでsize属性を設定する必要があります。コンテナの他のアイテムがコンテナに合うように高さを伸ばしたいと思います。私はそれを理解することはできません。私は明示的にコンテナの高さを設定したくないのは、その選択ボックスのサイズがわからないからです。親を満たすインラインブロック要素の高さを取得

.container { 
 
    padding: 5px; 
 
    border: 1px solid black; 
 
} 
 

 
.container .column { 
 
    display: inline-block; 
 
    width: 40%; 
 
    background-color: #AAA; 
 
    padding: 5px; 
 
    margin: 5px; 
 
    vertical-align: top; 
 
    height: 100%; 
 
} 
 

 
select { 
 
    width: 100%; 
 
}
<div class="container"> 
 
    <div class="column">Stretch to fill?</div> 
 
    <div class="column"> 
 
    <select size="15"> 
 
      <option>Option 1</option> 
 
      <option>Option 2</option> 
 
     </select> 
 
    </div> 
 
    <div>

+1

これは挑戦的なシナリオです。彼らがどのように解決されたかを見るために、固定ヘッダー/フッターレイアウトに関するSOの質問を見てください。 – isherwood

+0

'table-cell'を使っても構いませんか? – Antony

+0

'table-cell'は私の' width'設定に注意を払わないようです。 –

答えて

47

table-cellがオプションである場合は、ここでそれを行う方法です:

.container { 
 
    display: table; 
 
    width: 100%; 
 
    padding: 5px; 
 
    border: 1px solid black; 
 
} 
 

 
.container .column { 
 
    display: table-cell; 
 
    width: 40%; 
 
    background-color: #AAA; 
 
    padding: 5px; 
 
    border: 5px solid white; 
 
    vertical-align: top; 
 
    height: 100%; 
 
} 
 

 
select { 
 
    width: 100%; 
 
}
<div class="container"> 
 
    <div class="column">Stretch to fill?</div> 
 
    <div class="column"> 
 
    <select size="15"> 
 
      <option>Option 1</option> 
 
      <option>Option 2</option> 
 
     </select> 
 
    </div> 
 
    <div>

19

私はあなたが何を言っているか理解していれば、あなたは100% height columns問題に直面しています。実際の解決策はありませんが、「ハッキング」はないと言って申し訳ありません。

Hereこれらの回避策のいくつかを見つけることができます。私は本当のレイアウト方法を使いたい。

ところで、これは実験的なcss3カラムプロパティを使用したくないと考えています。

+0

これは素晴らしいリソースです! – Ziggy

+0

1つのTrue Layoutメソッドが私のために働いた! 'margin-bottom:-50em; padding-bottom:50em; '50emはプロジェクト固有のマジックナンバーで、実際にはこのトリックを行います。 – lkraav

-2

私も擬似要素を必要例:

.cf:before, 
 
.cf:after { 
 
\t content: " "; /* 1 */ 
 
\t display: table; /* 2 */ 
 
} 
 

 
.cf:after { 
 
\t clear: both; 
 
} 
 

 

 
*, *:before, *:after { 
 
\t -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; 
 
} 
 

 
.faux-columns { 
 
\t width: 80%; 
 
\t margin:3em auto; 
 
\t background-image: -webkit-linear-gradient(left, #f2f7fa 25%, #fff 75%); 
 
\t background-image: -moz-linear-gradient(left, #f2f7fa 25%, #fff 75%); 
 
\t background-image: -o-linear-gradient(left, #f2f7fa 25%, #fff 75%); 
 
\t background-image: linear-gradient(left, #f2f7fa 25%, #fff 75%); 
 
\t background: -webkit-gradient(linear, left top, right top, color-stop(0%,#f2f7fa), color-stop(25%, #f2f7fa), color-stop(25%,#ffffff), color-stop(100%,#ffffff)); 
 
\t background: -moz-linear-gradient(left, #f2f7fa 0%, #f2f7fa 25%, #ffffff 25%, #ffffff 100%); 
 
\t background: -webkit-gradient(linear, left top, right top, color-stop(0%,#f2f7fa), color-stop(25%,#f2f7fa), color-stop(25%,#ffffff), color-stop(100%,#ffffff)); 
 
\t background: -o-linear-gradient(left, #f2f7fa 0%,#f2f7fa 25%,#ffffff 25%,#ffffff 100%); 
 
\t background: -ms-linear-gradient(left, #f2f7fa 0%,#f2f7fa 25%,#ffffff 25%,#ffffff 100%); 
 
\t background: linear-gradient(left, #f2f7fa 0%,#f2f7fa 25%,#ffffff 25%,#ffffff 100%); 
 
\t border:1px solid #c1c1c2; 
 
} 
 

 
.col-1, .col-2 { 
 
\t float:left; 
 
\t vertical-align:top; 
 
\t padding:2em 3em; 
 
} 
 

 
.col-1 { 
 
\t position:relative; 
 
\t width:25%; 
 
\t background:#F2F7FC; 
 
\t border-right:1px solid #c1c1c2; 
 
} 
 

 
.col-2 { 
 
\t width:75%; 
 
\t border-left:1px solid #c1c1c2; 
 
\t margin-left: -1px; 
 
} 
 

 
.col-1:after, 
 
.col-1:before { 
 
    top:100%; 
 
    border:solid transparent;content:""; 
 
    height:0; 
 
    width:0; 
 
    position:absolute; 
 
    pointer-events:none; 
 
    display:block; 
 
} 
 
.col-1:after { 
 
    border-color: rgba(255, 255, 255, 0) rgba(255, 255, 255, 0) rgba(255, 255, 255, 0) #f2f7fa; 
 
    border-style: solid; 
 
    border-width: 21px 0 21px 22px; 
 
    left:100%; 
 
    top: 47px; 
 
} 
 
.col-1:before { 
 
    border-color: rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) rgba(0, 0, 0, 0) #c1c1c2; 
 
    border-style: solid; 
 
    border-width: 22px 0 22px 23px; 
 
    left: 100%; 
 
    top: 46px; 
 
}
<div class="faux-columns cf"> 
 
    <div class="col-1"> 
 
     <h4>First column with bordered triangle pseudo element attached to it. The background needs to be the full height of .faux-columns</h4> 
 
    </div> 
 
    <div class="col-2"> 
 
     <h4> Second column which in some cases will be much taller than column</h4> 
 
     There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc. 
 
     
 
     There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc. 
 
    </div> 
 
</div>

は、
2

私はここに答えてくれなかったので、私は行って真実を探しました。私は2つのボックス間の間隔のポイントを作るためにもう少しCSSを追加しました。

CSS:

.wrapper { 
    background-color:gray; 
} 

.container { 
    margin: 25px auto; 
    display: inline-flex; 
} 

.leftbox { 
    height: inherit; 
    display: inline-block; 
    border: 1px solid #D7D2CB; 
    background-color: #FFFFFF; 
    border-radius: 5px; 
    max-width: 550px; 
    margin-right: 18px; 
    align-items: stretch; 
    padding: 15px; 
    width: 100%; 
} 

.rightbox { 
    height: 100%; 
    display: inline-block; 
    border: 1px solid #D7D2CB; 
    background-color: #FFFFFF; 
    border-radius: 5px; 
    align-items: stretch; 
    max-width: 300px; 
    width: 100%; 
    padding: 20px 15px; 
} 

HTML:

<div class="wrapper"> 
    <div class="container"> 
    <div class="leftbox"> 
     There is something here, I am not avoiding it. 
    </div> 
    <div class="rightbox"> 
     Probably something else here but much much much much much much much much much much much much much much much much much much much much much much much much much much much much much bigger. 
    </div> 
    </div> 
</div> 

チェックcodepen: https://codepen.io/anon/pen/XRNMMp

+0

Briliant、これは期待通りに機能しましたが、画面が携帯電話のサイズになったときには動作しませんでした....私はdivが実際には何も起こらなかった左のdivの下に移動することを期待しました –

関連する問題