html - 将元素放在窗口的右上角

标签 html css css-float

我想在 HTML 中的窗口中添加一个关闭按钮,并且我希望该按钮 float 在 winodw 上,如本例所示:http://sandbox.scriptiny.com/tinybox2/ (第二个例子)

所以我在我的 HTML 中添加了一个 div 代码如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html"; charset=ISO-8859-1">
</head>
<body class="din">
    <h1>MyWindow</h1>
    <div id="hello"></div>
    <div id="coucou"></div>
    <img id="close" src="img/close.png" value="Close Window" onclick="closeWindow()"></img>
</body>
</html>

在我的 CSS 中:

#close {
    position: fixed;
    top: 1em;
    right: 1em;
    cursor: pointer;
    z-index: 1000;
}

按钮出现在右上角的窗口中,但不完全在顶 Angular 。我应该添加什么才能使它恰好出现在拐 Angular 处?

最佳答案

它并没有完全出现在右上角,因为你已经将顶部和右侧的样式设置为非零的值:

#close {
    position: fixed;
    top: 0; /* <--- set to zero, 1em = the inherited font size, which will offset it */
    right: 0;/* <--- set to zero, 1em = the inherited font size, which will offset it */
    cursor: pointer;
    z-index: 1000;
}

关于html - 将元素放在窗口的右上角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24821032/

相关文章:

javascript - 样式所见即所得编辑器

html - 为什么 'clear:left' 也正确清除?

html - 如何使用 float : left; in Bootstrap 3? 居中 DIV

javascript - 如何向不属于 DOM 的视频/gif 嵌入代码添加内联样式?

html - 使用 css3 border-radius 隐藏嵌入式 swf 上的方 Angular

html - 我的 html 页面顶部有空白区域?

html - 在 css 中居中背景颜色

css - 如何将第三个元素向左浮动?

javascript - Bootstrap 两列动画闪烁修复

javascript - 在 Javascript 幻灯片放映上添加文本