Home  >  Q&A  >  body text

css - 怎么让html里复选框后面的文字和复选框保持对齐啊,文字总比复选框低点

我想让这个后面的文字和复选框垂直居中对齐

黄舟黄舟2741 days ago806

reply all(4)I'll reply

  • 迷茫

    迷茫2017-04-17 13:36:08

    Example

    Using Flexbox is the most convenient way to deal with this problem:

    * {
      margin: 0;
      padding: 0;
      border: none;
    }
    
    body {
      background-color: darkgray;
    }
    
    .main {
      width: 800px;
      margin: 100px auto;
    }
    
    form {
      display: flex;
      flex-direction: column;
      width: 100%;
      height: 100px;
      background-color: whitesmoke;
      border: 2px solid grey;
      margin: 20px auto;
    }
    
    p {
      font-size: 20px;
      font-family: "微软雅黑";
    }
    
    .input {
      display: flex;
      align-items: center;
      flex: 1;
      padding: 10px;
    }
    
    .input > input {
      margin: 10px;
    }
    
    .input > label {
      font-size: 20px;
    }

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 13:36:08

    Try setting up floats for them

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 13:36:08

    Two ideas

    1. Absolute positioning

    2. Use display: inline-block to make it have height and then adjust the line height

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 13:36:08

    Add a CSS to <input>:

    vertical-align: middle;

    If it still doesn’t align, replace middle with a length value

    reply
    0
  • Cancelreply