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

使用CSS内联块和文本包装

  •  13
  • geographika  · 技术社区  · 15 年前

    我想显示一个复选框,后跟一些环绕在其下方的文本。没有任何CSS的HTML如下所示:

    <input type="checkbox" checked="checked" />
    <div>Long text description here</div>
    

    我希望它显示类似于:

    X   Long Text
        Description
        Here
    

    它现在像这样绕来绕去

    X   Long Text
    Description Here
    

    2 回复  |  直到 7 年前
        1
  •  7
  •   Vikas Arora    11 年前

    将复选框和标签包装在容器div中(或li-i经常使用列表的表单)并应用

    <div class="checkbox">
      <input type="checkbox" id="agree" />
      <label for="agree">I agree with checkbox</label>
    </div>
    
    
    
    
    .checkbox input {
          float:left; 
          display:block;
          margin:3px 3px 0 0;
          padding:0;
          width:13px;
          height:13px;
         }
    
    .checkbox label {
          float:left;
          display:block;
          width:auto;
         }
    
        2
  •  5
  •   cletus    15 年前

    input { float: left; }
    div { margin-left: 40px; }
    

    调整 margin-left float: left