ℙℕℤℝ 2010-05-31 03:15
浏览 369
已采纳

如何将一个 div 覆盖在另一个 div 上

I need assistance with overlaying one individual div over another individual div.

My code looks like this:

<div class="navi"></div>
<div id="infoi">
    <img src="info_icon2.png" height="20" width="32"/>
</div>

Unfortunately I cannot nest the div#infoi or the img, inside the first div.navi.

It has to be two separate divs as shown but I need to know how I could place the div#infoi over the div.navi and to the right most side and centered on top of the div.navi.

转载于:https://stackoverflow.com/questions/2941189/how-to-overlay-one-div-over-another-div

  • 写回答

7条回答 默认 最新

  • Memor.の 2010-05-31 03:20
    关注

    #container {
      width: 100px;
      height: 100px;
      position: relative;
    }
    #navi,
    #infoi {
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
    }
    #infoi {
      z-index: 10;
    }
    <div id="container">
      <div id="navi">a</div>
      <div id="infoi">
        <img src="https://appharbor.com/assets/images/stackoverflow-logo.png" height="20" width="32" />b
      </div>
    </div>

    I would suggest learning about position: relative and child elements with position: absolute.

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题