【发布时间】:2017-10-05 04:45:11
【问题描述】:
我正在使用 flexbox 设置页面样式。我在一个带有背景图像的 div 中有一个很好地居中的图像。
body {
width: 700px
}
nav {
width: 100%;
height: 50px;
background-color: #ccc
}
.wrapper,
.banner {
display: flex
}
.wrapper {
flex-direction: column
}
.banner {
background-image: url("https://unsplash.it/1000/600/?random");
background-repeat: no-repeat;
background-position: center center;
height: 300px;
}
.banner img {
height: 140px;
width: 140px;
border-radius: 140px;
border: 3px solid #fff;
align-self: center;
margin: auto;
}
<nav>
</nav>
<article class="wrapper">
<section class="banner">
<img id="profile-pic" src="https://unsplash.it/100/100/?random" />
</section>
</article>
查看此代码笔:
https://codepen.io/efbbrown/pen/PmOpWo
现在我想添加一个 x 按钮,以便用户可以根据需要更改背景图像。当我添加按钮 div 时,它会将居中的图像推离位置。
添加元素:
<section class="banner">
<div class="close-button"></div>
<img id="profile-pic" src="https://unsplash.it/100/100/?random"></img>
</section>
查看此代码笔以了解完整的困境:
https://codepen.io/efbbrown/pen/PmOpOq
如何在不更改中心图像位置的情况下将此 x 按钮添加到 div?
谢谢!
【问题讨论】:
标签: html css flexbox css-position