html - 如何在具有以下 DOM 结构的弹出窗口中放置关闭图标(右上角)?

标签 html css dom

我需要放置一个具有以下 DOM 结构的弹出式关闭图标

<div class="DIV1"></div>
<div class="DIV2">Content of the POPUP</div>

我的输出应该是这样的:

enter image description here

定位应该适用于所有屏幕。请用这个 DOM 结构给我答案。

注意:弹出内容 div 和关闭图标 div 是分开的。

最佳答案

看看这个fiddle

您可以用类替换 ID

#wrapper{
  position: relative;
  margin-top: 1rem;
  padding: 1rem;
  width: 300px;
  margin-left: auto;
  margin-right: auto;
}
#close{
  position: relative;
  width: 20px;
  height: 20px;
  color: red;
  border: 1px solid red;
  border-radius: 10px;
  float: right;
  text-align: center;
  line-height: 1;
}
#content{
  position: relative;
  background-color: #fff;
  margin-top: 30px;
  border: 2px solid black;
  padding: 1rem;
}
<div id="wrapper">
  <div id="close">x</div>
  <div id="content">
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Temporibus molestias saepe mollitia unde sint voluptas nostrum, cumque minima, ea quam maiores cum vitae ipsa hic! Quas nesciunt officiis alias laudantium!</p>
  </div>
</div>

关于html - 如何在具有以下 DOM 结构的弹出窗口中放置关闭图标(右上角)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40574814/

相关文章:

javascript - 从父元素中删除类 ID

html - 在其他页面上设置链接样式的正确方法

HTML 创建包含图像和文本的 3 列

php - 显示长文本描述输出

java - 使用 HtmlUnit 以编程方式从 HTML 获取列表

javascript - 触发两个脚本 : one that loads data and another that manipulates styling? 的正确方法是什么

html - 无法仅显示背景图片的整个网页

jquery - 部分标题在固定菜单栏下

javascript - 单击按钮后引导模式不起作用

html - 添加填充到文本而不是图像