使用CSS在div标签中重叠按钮

3

你好,关于使用

标签重叠两个按钮的问题,我有一个快速的提问,我该怎么做?我尝试了position和margin,但都不能移动按钮。

这是HTML:

<div class="container-fluid">
    <div style="margin:auto;">
        <button type="submit" class="btn-login">Log in</button>
    </div>
    <div class="signup-form">
    <label style="text-align:center;margin-bottom:20px">Create an Account</label>

    <div>
        <button type="submit" class="btn-login">Sign Up Free</button>
    </div>
        <label style="text-align:center;margin-bottom:20px;margin-top:20px">or</label>
    </div>
</div>
    <div class="social_media">
        <button type="submit" class="btn-facebook"></button>
        <button type="submit" class="btn-gmail"></button>
    </div> 
</body>

这是CSS:

.signup-form {
    top:-40px;
    position:relative;
    box-sizing: border-box;
    margin: 25px auto;
    margin-bottom:0px;
    width: 100%;
    max-width:400px;
    background-color: white;
    padding: 50px 50px 50px 50px;
    box-shadow: 1px 5px 2px #330000;
    z-index: -1;
}

.social_media {
    text-align:center;
}

.btn-facebook {
    margin-bottom:60px;
    padding-left:30px;
    background-image: url(fb.gif);
    background-color: #3b5998;
    padding: 0px;
    border: 3px solid white;
    border-radius: 5px;
    box-shadow: 1px 2px 2px grey;
    background-size: contain;
    background-repeat: no-repeat;
    height: 70px;
    width: 70px;
    font-family: sans-serif;
    font-size: 16px;
    color: white;
}

.btn-gmail {
    margin-bottom:60px;
    top:50%;
    padding-right:30px;
    background-image: url(g+.gif);
    background-color: #dc4a38;
    padding: 0px;
    border: 3px solid white;
    border-radius: 5px;
    box-shadow: 1px 2px 2px grey;
    background-size: contain;
    background-repeat: no-repeat;
    height: 70px;
    width: 70px;
    font-family: sans-serif;
    font-size: 16px;
    color: white;
}

同时,第一张截图是现在的样子,第二张截图是我试图复制的经过Photoshop处理后的图片。

current look

photoshop

3个回答

2

将父容器的定位属性值设置为relative(以控制重叠),并将按钮DIV的定位设置为absolute。现在将您的按钮放入按钮DIV中,然后使用负值来定位leftrighttopbottom,以使按钮DIV定位到您想要的位置。

.parent {
  width: 150px;
  height: 150px;
  margin: 0 auto;
  background: red;
  position: relative;
}

.button {
  width: 100px;
  height: 45px;
  line-height: 45px;
  text-align: center;
  position: absolute;
  background: darkOrange;
  border-radius: 5px;
  bottom: -22.5px;
  left: 50%;
-webkit-transform: translateX(-50%);
transform: translateX(-50%)
}
<div class="parent">

<div class="button">

  <input type="button" value="my button" />
  
</div>

<div>


1
尝试将btn类添加如下内容:

position: absolute;

然后将它们移动到所需位置,您可能需要更改z-index。

0

social_media div 的位置设置为 relative,然后使用 top 属性来根据需要移动它们的位置。例如:

.social_media {
    text-align:center;
    position: relative;
    top: -74px;
}

jsFiddle 示例


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接