Div没有环绕形式

时间:2016-06-28 18:52:39

标签: html css twitter-bootstrap-3

我有一个div,我试图填充背景颜色。它包含一个表单。但是,div和颜色不会缠绕在表单上。我该如何解决这个问题?

#signUpForEarlyAccess {
  float: right;
  background-color: #F8F8F8;
}
.fully-centered {
  position: relative;
  top: 50%;
  transform: translateY(50%);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-xs-6" style="background-color: grey">
  Irrelevant div
</div>
<div class="col-xs-6 text-center" id="signUpForEarlyAccess">
  <div class="fully-centered">
    <h3 contenteditable="true">Sign Up for Early Access</h3>
    <h5>Enter your email to be one of the first to try!</h5>
    <div class="form-group input-group">
      <input id="emailForm" placeholder="Please enter an email address" type="email" class="form-control">
      <span class="input-group-btn">
        <button type="submit" class="btn btn-success">Sign up</button>
      </span>
    </div>
  </div>

JSFiddle

1 个答案:

答案 0 :(得分:1)

https://jsfiddle.net/02uLtz0w/2/

我想你想要这样的东西

#signUpForEarlyAccess {
  float: right;
  background-color: #F8F8F8;
  border:1px solid red;
  display:flex;
  align-items:center;
  justify-content:center;
  align-content:center;
  height:250px;
}

这个高度只是为了向你展示它是垂直居中的吗?根据需要修改它。