【问题标题】:How to float two images right without the second one going to new line?如何在第二张图片不换行的情况下正确浮动两张图片?
【发布时间】:2018-11-26 01:18:03
【问题描述】:

我有两张图片想要向右浮动并保持在同一条线上。但是会发生的是万事达卡图像在右侧,而签证卡图像在新行上浮动。有什么帮助吗?谢谢

HTML:

  <label>
      <img src="{% static 'img/Mastercard.png' %}" style="float:right">
  </label>
  <div class="clear"></div>
  <label>
      <img src="{% static 'img/Visa.png' %}" style="float:right">
  </label>
  <div class="clear"></div>

CSS:

.clear {
clear: both;
}

【问题讨论】:

  • 他们之间清空div的目的是什么?
  • 即使删除也无济于事
  • 删除它,它会有所作为......顺便说一下,你不需要浮动图像,使用 text-align

标签: html css css-float


【解决方案1】:

可以使用flexbox来实现。

html

<div id="container">
  <label> <img src="./react-logo.png" /> </label>
  <label> <img src="./pic_angular.jpg" /> </label>
</div>

css

  img {
    max-width: 100%;
    object-fit: cover;
  }

  #container {
    display: flex;
    justify-content: flex-end;
  }

结果

【讨论】:

    【解决方案2】:
    1. 您需要从您的 作为 div 的 HTML 标记是 block level 元素,这就是为什么你的第二个 图片从新行开始。
    2. 另外,最好使用text-align: right 而不是float:right。通过使用 text-align 属性而不是 float clear class 将不再需要。

    你可以写成:

    <div style="text-align: right">
        <img src="{% static 'img/Mastercard.png' %}">
        <img src="{% static 'img/Visa.png' %}">
    </div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-08
      • 1970-01-01
      • 2011-10-31
      • 2012-09-21
      • 2022-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多