代码之家  ›  专栏  ›  技术社区  ›  Babiker

如何将DIV宽度设置为“无内容满”?

  •  0
  • Babiker  · 技术社区  · 14 年前

    代码:

    <html>
        <head>
            <style type="text/css">
            div{border:solid 1px gray;}
            #mainDiv
            {
                width:300px;
            }
            .leftDiv
            {
                display:table-cell;
                width:50%;
            }
            .rightDiv
            {
                display:table-cell;
                width:50%;
            }
            </style>
        </head>
        <body>
            <div id="mainDiv">
             <div class="titleDiv">
                ...titleDiv content...
             <div>
             <div class="leftDiv">
                ...leftDiv content...
             </div>
             <div class="rightDiv">
                ...rightDiv content...
             </div>
           </div>
        </body>
    </html>
    

    问题是 leftDiv rightDiv 只有在内容足够的情况下才能达到它们的全部宽度。

    这对我来说是个问题,因为我只想在 左撇子 然后向右对齐。

    2 回复  |  直到 14 年前
        1
  •  2
  •   Å ime Vidas Zim84    14 年前
    <html>
        <head>
            <style type="text/css">
            div{border:solid 1px gray;}
            #mainDiv
            {
                width:300px; 
                overflow:auto;
            }
            .float
            {
                float:left;
                width:50%;
            }
            </style>
        </head>
        <body>
            <div id="mainDiv">
             <div class="titleDiv">
                ...titleDiv content...
             <div>
             <div class="float">
                ...leftDiv content...
             </div>
             <div class="float">
                ...rightDiv content...
             </div>
           </div>
        </body>
    </html>
    
        2
  •  0
  •   kobe    14 年前

    text-align:right