vertically alignment of a text inside a button with an image

后端 未结 3 1738
野趣味
野趣味 2021-01-24 20:20

In this CodePen you can see a

相关标签:
3条回答
  • 2021-01-24 21:12

    Try to do it like this way. There are other methods also, but this one is simple.

    button {
      width: 300px;
    }
    button img {
      float:left;
      width:20%;
    }
    button span {
      float:right;
      width:80%;
    }
    <button>
      <img src="http://lorempixel.com/50/50/" />
      <span> Some Text some text some text some text some text some text some text some text</span>
    </button>

    0 讨论(0)
  • 2021-01-24 21:14

    can you try this https://codepen.io/anon/pen/qVKagg

    button {
      width: 300px;
      display: flex;
      text-align:left;
    }
    
    img {
      vertical-align: middle;
      margin-right:5px;
    }
    <button>
    <img src="http://lorempixel.com/50/50/" />
    <span> Some Text some text some text some text some text some text some text some text</span>
    </button>

    0 讨论(0)
  • 2021-01-24 21:15

    You can use the following solution using flexbox:

    * {
      margin:0;
      padding:0;
      box-sizing:border-box;
    }
    button {
      align-items: center;
      display: flex;
      padding: 3px;
      justify-content: center;
      width: 300px;
    }
    button img {
      flex-shrink: 0;
      margin-right: 10px;
    }
    <button>
      <img src="https://lorempixel.com/50/50/" alt="">
      <span>Some Text Some Text Some Text Some Text Some Text Some Text Some Text</span>
    </button>
    <button>
      <img src="https://lorempixel.com/50/50/" alt="">
      <span>Some Text</span>
    </button>
    <button>
      <img src="https://lorempixel.com/50/50/" alt="">
    </button>

    0 讨论(0)
提交回复
热议问题