html - 覆盖各个 Div

标签 html css

如果他们不是订阅者,我会尝试在我的页面上的 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和well的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;
}

最佳答案

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

.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

关于html - 覆盖各个 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26786196/

相关文章:

javascript - 交换 Chrome 中所选选项卡内容中的一些单词

html - 带有 Bootstrap 的 Google map 没有响应

html - 用背景图像填充 SVG 路径元素

jquery - 以不同的顺序附加样式表或 js 文件有什么区别?如何使用 append 和 prepend 样式表或 append 和 prependfile?

javascript - 通过选择类来解包?

javascript - 如何将数据发布到服务器并捕获响应

javascript - 在菜单上滑动 Logo 和文本单击

javascript - 按钮更新第一个元素的文本而不是所选元素

jquery - 如何使 jquery json 结果的结果使元素可见

javascript - 根据 PHP 变量值隐藏/显示选项卡内容