我正在尝试创建一个带有登录表单的登录窗口,但使用没有框架的自定义窗口,我想附加一些自定义按钮。 我已经用顶部栏创建了窗口,用一个圆圈作为按钮,但试图将它移到右边似乎是不可能的。 这就是现在使用以下代码的样子
HTML
body {
background-color: rgb(48, 58, 65);
margin: 0;
padding: 0;
}
#controlBar {
width: 100%;
height: 30px;
background-color: rgb(27, 42, 51)
}
#exit {
width: 15px;
height: 15px;
background-color: red;
border-radius: 100%;
right: 0;
}
<html>
<link rel="stylesheet" href="knbn_login.css">
<body>
<div id='controlBar' style='-webkit-app-region:drag'>
<div id='exit'></div>
</div>
</body>
</html>
怎么把它移到窗口的最右边? 感谢您的回答!
最佳答案
只需将 margin-left:auto
添加到元素中,如下所示:
body {
background-color: rgb(48, 58, 65);
margin: 0;
padding: 0;
}
#controlBar {
width: 100%;
height: 30px;
background-color: rgb(27, 42, 51)
}
#exit {
width: 15px;
height: 15px;
background-color: red;
border-radius: 100%;
margin-left: auto;
}
<div id='controlBar' style='-webkit-app-region:drag'>
<div id='exit'></div>
</div>
或者你可以让它成为 inline-block
并在它的容器上使用 text-align :right
像这样:
body {
background-color: rgb(48, 58, 65);
margin: 0;
padding: 0;
}
#controlBar {
width: 100%;
height: 30px;
background-color: rgb(27, 42, 51);
text-align:right;
}
#exit {
width: 15px;
height: 15px;
background-color: red;
border-radius: 100%;
display:inline-block;
}
<div id='controlBar' style='-webkit-app-region:drag'>
<div id='exit'></div>
</div>
或者像这样使用float:right
:
body {
background-color: rgb(48, 58, 65);
margin: 0;
padding: 0;
}
#controlBar {
width: 100%;
height: 30px;
background-color: rgb(27, 42, 51);
}
#exit {
width: 15px;
height: 15px;
background-color: red;
border-radius: 100%;
float:right;
}
<div id='controlBar' style='-webkit-app-region:drag'>
<div id='exit'></div>
</div>
或者 position:absolute
和 right:0
像这样:
body {
background-color: rgb(48, 58, 65);
margin: 0;
padding: 0;
}
#controlBar {
width: 100%;
height: 30px;
background-color: rgb(27, 42, 51);
position:relative;
}
#exit {
width: 15px;
height: 15px;
background-color: red;
border-radius: 100%;
position:absolute;
right:0;
}
<div id='controlBar' style='-webkit-app-region:drag'>
<div id='exit'></div>
</div>
关于html - 将按钮移动到屏幕的右侧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47044811/