简体   繁体   English

div 右上角的 CSS 位置图标,在 div 后面

[英]CSS position icon at top right of div, goes behind div

I got a quick question.我有一个快速的问题。 I want an icon at the top right of the div, and the bottom right.我想要一个 div 右上角和右下角的图标。 I think I am doing it well, but for some reason it goes behind the div.我认为我做得很好,但由于某种原因,它落后于 div。 Image of what happens, you can see the green and red icon not going above it, but behind所发生情况的图像,您可以看到绿色和红色图标不在其上方,而是在其后面

This is the code I wrote:这是我写的代码:

HTML: HTML:

<div v-if="showMenu" class="wrapper">

        <!-- Begin karakters onderaan -->
        <div v-if="karakters" class="karakters-wrapper">
            <span v-for="karakter in karakters" :key="karakter">

                <div v-if="karakter !== undefined" class="karakter-box">
                    <p>{{karakter.charinfo.firstname}} {{karakter.charinfo.lastname}}</p>
                    
                    <i class="fas fa-play-circle icoon-speel"></i>
                    <i class="fas fa-trash icoon-verwijder"></i>
                </div>
                <div v-else class="karakter-box">
                    <p>Leeg karakter slot</p>
                </div>

            </span>
        </div>
        <div v-else>
            <h1 style="color:#fff;font-size:48px;">GEDULD!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!</h1>
        </div>
        <!-- Einde karakters onderaan -->
    </div>

^^ Don't mind the v-if etc. that's from VueJS. ^^ 不要介意来自 VueJS 的 v-if 等。 Anyways, the div with class "karakter-box" is the div where I want an icon at the top right of.无论如何,带有“karakter-box”类的div是我想要右上角图标的div。

CSS: CSS:

    width: 100%;
    height: 100%;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    flex-direction: column;
}

.karakters-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 10px;
}

/* Karakter boxjes */
.karakter-box {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 300px;
    height: 100px;
    background-color: rgba(0, 0, 0, 0.7);
    border-top: 8px solid var(--white);
    padding: 5px;
    margin: 5px;
    color: var(--white);
    transition: .25s ease-in-out;
}

.karakter-box:hover {
    border-top: 8px solid var(--groen);
    background-color: rgba(0, 0, 0, 0.9);
}


.icoon-speel {
    position: absolute;
    top: -10px;
    right: -10px;

    font-size: 2rem;
    background-color: var(--groen);
    color: var(--white);
    padding: 10px;
    border-radius: 100%;
}

.icoon-verwijder {
    position: absolute;
    bottom: -10px;
    right: -10px;

    font-size: 2rem;
    background-color: var(--rood);
    color: var(--white);
    padding: 10px;
    border-radius: 100%;
}```

I suggest use another for the background and set its width to device width.我建议使用另一个作为背景并将其宽度设置为设备宽度。 use this css code to get positions to right corners Position: absolute;使用此 css 代码将位置定位到右角位置:绝对;

and use this at css to get front of div z-index:1;并在 css 中使用它来获得 div z-index:1 的前面;

index 1 is go front of styles and 2 3 4 going backward as ordered.索引 1 是样式的前面,2 3 4 是按顺序向后的。

I'm not sure why but it looks like there is an overflow: hidden karakter-box class.我不知道为什么,但看起来有一个overflow: hidden karakter-box类。 even though i don't see it in the code sample you provided.即使我在您提供的代码示例中没有看到它。 When i tested the code the sample this issue did not occur Try Checking for css overflow on karakter-box当我测试代码时,样本没有出现这个问题尝试检查karakter-box上的 css overflow

set the z-index of div to be -1将 div 的 z-index 设置为 -1

div{
z-index: -1;
}

and that of icons to be 1和图标是 1

i{
z-index: 1;
}

i will make the div behind your icons, so you can interact with your icons.我将在您的图标后面制作 div,以便您可以与您的图标进行交互。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM