叠加个人Div

时间:2014-11-06 17:57:54

标签: html css css3

我试图在我的页面上的div上添加一个叠加,如果他们不是订阅者,并且有一个按钮来订阅其中心的网站。我有问题让叠加层进入正确的div并且不在其中......但是要把它全部灰掉......

具有span5的实际CSS以及在帖子末尾的控制台

我有一个包含以下HTML的页面:

  <div class="row-fluid">
    <div class="span2 well>
      ...
    </div>
    <div class="span5 well">
      <h3>EZ Search</h3>
      <a class="btn btn-primary" href="/searches/new">Advanced Search</a>
      <hr/>
      <%= render partial: "searches/ezsearch", locals: {search: @search, user_id: current_user.id} %>
    </div>
    <div class="span5 well>
      ...
    </div>
  </div>

这是我现在拥有的页面图像:

enter image description here

并希望它看起来像这样:

enter image description here

这就是我在我的CSS中所拥有的:

.overlay{
  z-index: 20;
  width: 100%;
  height: 100%;
  position: absolute;
}

.overlay .blackbg {
  z-index: 25;
  color: #000;
  background-color: #000;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
  filter: alpha(opacity=50);
  opacity: 0.5;
}

.overlay .button {
  z-index: 30;
  color: white;
}

这是span5的css以及

.row-fluid .span5 {
    width: 40.1709%;
}
.row-fluid [class*="span"] {
    -moz-box-sizing: border-box;
    display: block;
    float: left;
    margin-left: 2.5641%;
    min-height: 30px;
    width: 100%;
}
.row-fluid .span5 {
    width: 40.4255%;
}
.row-fluid [class*="span"] {
    -moz-box-sizing: border-box;
    display: block;
    float: left;
    margin-left: 2.12766%;
    min-height: 30px;
    width: 100%;
}
.well {
    background: none repeat scroll 0 0 #E6E6E6;
    box-shadow: 3px 3px 5px 6px #CCCCCC;
}
.span5 {
    width: 470px;
}
[class*="span"] {
    float: left;
    margin-left: 30px;
    min-height: 1px;
}
.well {
    background-color: #F5F5F5;
    border: 1px solid #E3E3E3;
    border-radius: 4px 4px 4px 4px;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05) inset;
    margin-bottom: 20px;
    min-height: 20px;
    padding: 19px;
}
.span5 {
    width: 380px;
}
[class*="span"] {
    float: left;
    margin-left: 20px;
    min-height: 1px;
}

1 个答案:

答案 0 :(得分:2)

您可以像这样简化叠加样式:

.overlay{
  z-index: 20;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,.5); /* this will give you the 50% black background without the extra element */
  color: #000;
}

.overlay .button {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%); /* object is aligned centered based on the top left corner, this adjusts it to true center */
  z-index: 30;
  color: white;
}

这是稍微调整过的HTML:

<div class="span5 well">
    <div class="overlay">
        <a class="btn btn-primary button" href="/searches/new">Sign Up Now!</a>
    </div>
  <h3>EZ Search</h3>
  <a class="btn btn-primary" href="/searches/new">Advanced Search</a>
  <hr/>
    <p>...</p>
</div>

<强> JSFiddle Demo