0

私はこれをやろうとしています

<div>
    <div style="width:50%;"> first div </div>
    <div style="width:50%;"> second div </div>
</div>

動的に最初または2番目のdivが表示されない場合があります。最初のdivが表示されない場合、2番目に幅を100%と想定する必要があり、その逆も同様です。cssだけでこれを行うことはできますか?min-weigthまたはmax-widthまたはそのようなもの?

4

2 に答える 2

0

:only-child疑似クラスを使用できます

.childDiv
{
    width:50%;
}
.childDiv:only-child
{
    width:100%;
}

HTML

<div>
    <div class="childDiv'> first div </div>
    <div class="childDiv'> second div </div>
</div>
于 2013-02-28T20:04:59.413 に答える
0

自動マージンCSSプロパティを使用してみてください。

.myClass
{
    margin:0px auto;
    width:50 //You can set this to whatever or take it out
}

そしてHTMLに追加

<div>
    <div class="myClass'> first div </div>
    <div class="myClass'> second div </div>
</div>
于 2013-02-28T20:02:18.540 に答える