【问题标题】:Want to make a div below another in css想在css中在另一个下面创建一个div
【发布时间】:2022-11-11 01:10:39
【问题描述】:

我有两个 div 嵌套在一个 div .content 里面,里面有一个 img.png ,我想要另一个 div 里面有一些盒子,它们会在 img.png 下面

        <div class="navBox">
            <a href="#contact">/*Contact*/</a>
        </div>
        <div class="navBox">
            <a href="#expertise">/*Expertise*/</a>
        </div>
        <div class="navBox">
            <a href="#projects">/*Projects*/</a>
        </div>

另外,我尝试了定位,填充,边距的所有可能组合,我没有尝试z-index(不知道具体如何使用它)并且没有任何好的结果。

提前致谢。

*编辑:我设法使用其他发行版。

.mainBox{
    position: relative;
    display: flex;
    width: 95%;
    height: 25vh;
    padding-top: 5vh;
    justify-content: space-evenly;
    align-items: left;
    vertical-align: middle;
}

.navBox{
    padding-top: 25px;
    padding-left: 10px;
    padding-right: 10px;
    width: 20%;
    height: 20vh;
    text-align: center;
    top: 50%;
    background: transparent;
}

.navBox a:hover{
    padding-top: 50%;
    background: transparent;
    color: var(--text-color);
    text-decoration: none;
    
}

a:visited, a:active, a:link{
    text-decoration: none;
    color: var(--text-color);
}

.navBox a{
    vertical-align: middle;
    color: var(--text-color);
    padding-top: 0.5rem;
}

【问题讨论】:

  • 显示您尝试过的代码(不是图片,实际代码和 CSS
  • 我制作了一个 sn-p 来帮助您将代码粘贴到其中。

标签: html css


【解决方案1】:

下次请分享你的代码而不是截图,反正这里是一个不使用 z-index 的示例代码

HTML

<div class="container">
  <div class="your-image">&nbsp;</div>
  <div class="your-boxes">&nbsp;</div>
</div>

CSS

.container {
  display: grid;
  grid-template-rows: 1 / 1;
  grid-template-columns: 1 / 1;
  justify-items: center;
  align-items: center
}

.your-image {
  background-color: red;
  width: 250px;
  height: 250px;
  grid-area: 1 / 1 / 1 / 1;
}

.your-boxes {
  background-color: green;
  width: 150px;
  height: 150px;
  grid-area: 1 / 1 / 1 / 1;
  justify-self: center;
}

基本上,您创建一个 1x1 网格并将两个 div 重叠在同一列和同一行上。

https://codepen.io/ChrisCoder9000/pen/NWMJdBo

【讨论】:

    猜你喜欢
    • 2013-12-31
    • 2015-11-09
    • 2022-08-12
    • 1970-01-01
    • 1970-01-01
    • 2020-01-24
    • 1970-01-01
    • 1970-01-01
    • 2014-02-13
    相关资源
    最近更新 更多