【问题标题】:HTML and CSS: Place Checkbox in Top Right of an ImageHTML 和 CSS:将复选框放在图像的右上角
【发布时间】:2019-06-26 21:32:38
【问题描述】:

如何将复选框嵌入图像的右上角?这目前不起作用

.container {
  position: relative;
  width: 100px;
  height: 100px;
  float: left;
  margin-left: 10px;
}

.checkbox {
  position: absolute;
  right: 5px;
  top: 5px;
}
<div class="container">
  <img src="https://images.unsplash.com/reserve/bOvf94dPRxWu0u3QsPjF_tree.jpg?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60" />
  <input type="checkbox" class="checkbox" id="check1" />
</div>

首先研究了这个:

Placing an image to the top right corner - CSS

【问题讨论】:

  • 图片溢出(添加max-width:100%)

标签: html css checkbox


【解决方案1】:

.container的width属性改为auto

.container {
  position: relative;
  width: auto;
  height: 100px;
  float: left;
  margin-left: 10px;
}

.checkbox {
  position: absolute;
  right: 5px;
  top: 5px;
}
    <div class="container">
        <img src="https://images.unsplash.com/reserve/bOvf94dPRxWu0u3QsPjF_tree.jpg?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=60" />
        <input type="checkbox" class="checkbox" id="check1" />
    </div>

【讨论】:

  • 接受的答案给了分数,也请随意竖起大拇指,tahnks
【解决方案2】:

父容器不需要任何宽度。因为您的img 宽度等于500px。所以容器可以自动调整宽度

.container {
    position: relative;
    width: auto;
    height: 100px;
    float: left;
    margin-left: 10px;
}

【讨论】:

  • 请在您的答案中添加一些文字并描述它,请
  • 父容器不需要任何宽度。因为你的img宽度等于500px。所以容器可以自动调整宽度..
  • 欢迎使用 stackoverflow。您能否在答案正文中添加您的描述?这次我会为你做这个;-)。谢谢
猜你喜欢
  • 2011-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多