html - 绝对定位的 h1 标题在向下滚动时向下移动

标签 html css

我有一个 h1 标题:

 <h1 class="main-heading"><span class="heading-opaque-background"><%= @post.title %></span></h1>

绝对定位在标题图片上:

.main-heading {
    /*TEXT ON MAIN PIC*/
      position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 2;
    padding: 0;
    margin: auto;
    /*height: 40px;*/
    color: rgba(255, 255, 255, 0.80);
    font-family: 'Open Sans';
    font-weight: 300;
    font-size: 4vw;
      height: 20%;
    width: auto;
    padding: 20px;
    letter-spacing: 8px;
    font-variant: small-caps;
    text-shadow: 0 1px 0 #999999, 0 2px 0 #888888,
    0 3px 0 #777777, 0 4px 0 #666666,
    0 5px 0 #555555, 0 6px 0 #444444,
    0 7px 0 #333333, 0 8px 7px rgba(0, 0, 0, 0.4),
    0 9px 10px rgba(0, 0, 0, 0.2);

}

当我向下滚动时,标题向下移动到图片底部。将显示设置为内联不会改变任何内容。

如何让标题绝对定位在图片上?

这是一个更完整的 html 概述,用于显示父类:

<img class="project-main-pic" src="<%= Citybuilder.ProjectPic.url({@post.project_pic, @post}) %>" />
<!--f https://image.slidesharecdn.com/otpphoenixecto-170327125511/95/yurii-bodarev-otp-phoenix-ecto-three-pillars-of-elixir-58-638.jpg?cb=1490619720-->
<section id="home" class="">
    <h1 class="main-heading"><span class="heading-opaque-background"><%= @post.title %></span></h1>
</section>
<div class="project-wrapper">
    <section id="about" class="sec-about">
        <div class="container">
            <h1 class="project-title"><%= @post.title %></h1>
            <!-- ADD TO FORM AND DATABASE -->
            <div class="row">
                <div class="col-sm-6 col-sm-offset-3">
                    <p class="summary-text">
                        <%= @post.body %>
                    </p>
                </div>
            </div>
        </div>
    </section>

最佳答案

在这里查看:https://jsbin.com/cezidexase/1/edit?html,css,output

.main-heading {
    margin: auto;
    /*height: 40px;*/
    color: rgba(255, 255, 255, 0.80);
    font-family: 'Open Sans';
    font-weight: 300;
    font-size: 4vw;
      height: 20%;
    width: auto;
    padding: 20px;
    letter-spacing: 8px;
    font-variant: small-caps;
    text-shadow: 0 1px 0 #999999, 0 2px 0 #888888,
    0 3px 0 #777777, 0 4px 0 #666666,
    0 5px 0 #555555, 0 6px 0 #444444,
    0 7px 0 #333333, 0 8px 7px rgba(0, 0, 0, 0.4),
    0 9px 10px rgba(0, 0, 0, 0.2);

}

关于html - 绝对定位的 h1 标题在向下滚动时向下移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46053713/

相关文章:

php - 从零开始的 Wordpress 主题

javascript - document.getElementById().innerHTML 不起作用,控制台上没有错误

jQuery 无法使 .click 处理此代码

javascript - 对于 Bootstrap 4 Carousel,点击下一步时第一张幻灯片计数不起作用

javascript - 单击菜单关闭菜单 div

html - H1 标签不再显示在页面主体上

php - 错误警告:mysql_fetch_array()期望参数1为资源, bool 值在[duplicate]中给出

css - 背景图像 css 顶部和底部的透明渐变

html - 使用CSS更改水平子菜单中事件选项卡的颜色

jquery - 关于目录结构的建议