CSS定位

标签 css sass compass

我尝试实现和本站一样的效果 http://www.rumba.com.br/

我会这样描述:

  • 元素(或标题)列表
  • 将鼠标悬停在列表的某个元素上时,背景中会出现一张图片

我尝试仅使用 CSS 重现此效果。 它工作得很好,但现在,我坚持将“列表”(在我的例子中是 figcaption)放在页面底部。 我希望此示例中“列表”的最后一个元素“第三标题”位于页面底部。

密码本:

http://codepen.io/AmauryH/pen/QKexJq

HTML:

    <header>
        <figure>
        <figcaption>Title One</figcaption>
        <img src="http://amauryhanser.com/vrac/01.png" />
    </figure>
    <figure>
        <figcaption>Title Two</figcaption>
        <img src="http://amauryhanser.com/vrac/02.png" />
    </figure>
    <figure><figcaption>Title Three</figcaption>
        <img src="http://amauryhanser.com/vrac/03.png" />
    </figure>
</header>
<section>
    Remaining content...
</section>

SCSS:

@import "compass/css3";
@import "compass/reset";

* {
  @include box-sizing(border-box);
}
html {
  height:100%;
}
body {
  background: #000;
  height:100%;
  color:white;
}

header {
  position:relative;
  overflow:hidden;
  width:100%;
  height:100%;
  figure {
    width:400px;
    figcaption {
      margin: 10px 20px;
      z-index:2;
      cursor: pointer;
      font:40px arial, sans-serif;
      color:#fff;
      &:hover + img{
        @include opacity(1);
      }
    }
    img {
      z-index:-1;
      position:absolute;
      left:0;
      top:0;
      @include opacity(0);
      width:100%;
      @include transition(opacity 2s ease-in-out);
    }
  }
  & + section {
    background:#333;
    height: 500px;
  }
}

你有什么想法吗? 提前致谢!

阿莫里

最佳答案

所以,这是我为解决它所做的:

  • 添加了一个包裹所有的div
  • 添加了“显示:表格单元格;垂直对齐:底部;”到这个 div
  • 在标题中添加了“display:table”

codepen 已更新,似乎可以正常工作。

关于CSS定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40365001/

相关文章:

sass - compass 不适用于 Mithril 自耕农发电机

html - 元素是否对具有隐藏属性和 css 显示 : block? 的用户代理可见

javascript - 使用 jQuery 在悬停时显示菜单子(monad)元素

html - 链接透明 DIV

node.js - 通过 SASS 支持使用 Typescript、SASS 和 CSS 模块搜索 React 组件库的 Webpack 配置

css - 在 sublime text 的多语言语法上使用相同的自动完成

css - Laravel Mix - 公共(public) CSS 不断覆盖

css - 将可滚动的 div 引导到 body 高度 100%

css - 在 SASS Compass 中禁用浏览器前缀?

css - 拒绝应用来自 "https://cd.shopify.com/xxxxx/assets/compass.css3"的样式,因为它的 MIME 类型为 ('text/html' )