【问题标题】:Html5 Have an Animated Canvas as the background of a Div Element?Html5 有一个动画画布作为 Div 元素的背景?
【发布时间】:2020-12-30 22:40:54
【问题描述】:

我想让这个 JS - https://codepen.io/jkiss/pen/OVEeqK - 作为我首页上 div 元素的背景。

HTML

<script src="{% static 'home/animated.js' %}"></script>
        <div class = "content-section">
            <div id = "canvas-wrap">
                <canvas id="nokey"></canvas>
                <div class = "bg-1 media" id = "overlay">
                    <div class = "container">
                        <img src = "../../../media/pfp.jpg"  class = "profile-img img-thumbnail rounded-circle">
                        <div class = "media-body intro">
                            <h1 class = "">My Name</h1>
                            <h4>Aspiring Web Developer</h4>
                        </div>
                    </div>
                </div>
            </div>

CSS

body{
    background-color: #222222;
    font:inherit;
    font-family: Titillium;
    margin:0;
    padding:0;
}

#canvas-wrap { position:absolute; width:100px; height:50px; z-index:0 }
#canvas-wrap canvas { position: absolute; top:0; left:0; z-index:0 }

#nokey{
    background-color: darkblue;
}

.content-section{
    margin-left: 50px;
    margin-right: 50px;
    margin-bottom: 50px;
    background: aliceblue;
}

.bg-1 .container{
    display: flex;
    align-items: center;
    justify-content: center;
}

.intro{
    flex: none;
    margin-top: 200px;
    margin-bottom: 200px;
    padding-left: 25px;
    color: white;
}

我能做什么?目前画布占据了整个屏幕,并在其后面创建了 div。

【问题讨论】:

    标签: javascript html css canvas html5-canvas


    【解决方案1】:

    使用z-index CSS 属性将 div 移动到更高的其他元素:

    #nokey{
        background-color: darkblue;
        z-index: 1; // or more, if other elements has one
    }

    【讨论】:

    • 它不起作用,没有区别。它仍然出现在后面和左侧。并且没有其他元素具有 z-index:1。
    猜你喜欢
    • 2013-12-16
    • 2016-10-01
    • 1970-01-01
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-10
    • 2022-06-14
    相关资源
    最近更新 更多