Html HTML如何将按钮向右移动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30206805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML how to move the button to the right
提问by marse
Sorry, if the question is dumb because I am just a beginner in HTML. How to move my button to the right? I have tried some ways but it doesn't seem to work. Here is my code.
对不起,如果这个问题很愚蠢,因为我只是 HTML 的初学者。如何将我的按钮向右移动?我尝试了一些方法,但似乎不起作用。这是我的代码。
<!DOCTYPE html>
<html>
<head>
<title>Sample Dashboard</title>
<style type="text/css">
p.pos_right {
position: relative;
left: 20px;
}
.button_example{
border:1px solid #f9f68a; -webkit-border-radius: 3px; -moz-border-radius: 3px;border-radius: 3px;font-size:12px;font-family:arial, helvetica, sans-serif; padding: 10px 10px 10px 10px; text-decoration:none; display:inline-block;text- shadow: -1px -1px 0 rgba(0,0,0,0.3);font-weight:bold; color: #FFFFFF;
background-color: #fcfac0; background-image: -webkit-gradient(linear, left top, left bottom, from(#fcfac0), to(#f6f283));
background-image: -webkit-linear-gradient(top, #fcfac0, #f6f283);
background-image: -moz-linear-gradient(top, #fcfac0, #f6f283);
background-image: -ms-linear-gradient(top, #fcfac0, #f6f283);
background-image: -o-linear-gradient(top, #fcfac0, #f6f283);
background-image: linear-gradient(to bottom, #fcfac0, #f6f283);filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#fcfac0, endColorstr=#f6f283);
}
.button_example:hover{
border:1px solid #f7f25f;
background-color: #faf68f; background-image: -webkit-gradient(linear, left top, left bottom, from(#faf68f), to(#f3ed53));
background-image: -webkit-linear-gradient(top, #faf68f, #f3ed53);
background-image: -moz-linear-gradient(top, #faf68f, #f3ed53);
background-image: -ms-linear-gradient(top, #faf68f, #f3ed53);
background-image: -o-linear-gradient(top, #faf68f, #f3ed53);
background-image: linear-gradient(to bottom, #faf68f, #f3ed53);filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startC olorstr=#faf68f, endColorstr=#f3ed53);
}
</style>
</head>
<body>
<p class="pos_right">Most Number of Referrals for the month of </p>
<a class="button_example" href="#"><font color="black">UPDATE</font></a>
</body>
</html>
回答by panther
Many ways how to do that, for example float
很多方法如何做到这一点,例如 float
.button_example {float: right}
回答by ketan
You can also move you button to right by applying text-align: right;
to it's parent. In your case it's parent is body.
您还可以通过应用text-align: right;
到它的父级来将您的按钮向右移动 。在你的情况下,它的父母是身体。
So you can apply css like:
所以你可以像这样应用css:
body {
text-align: right;
}
Note: It make your p tag also align to right.
注意:它使您的 p 标签也向右对齐。
回答by Pindakaas
Depending on how much space you want to move it to the right add this to .button_example:
根据您想要将其向右移动多少空间,将其添加到 .button_example 中:
margin-left:100px;
回答by streletss
Simply add to
只需添加到
.button_example {
position:absolute;
top: 10px;
right:0;
}
Here's snippet
这是片段
p.pos_right {
position: relative;
left: 20px;
}
.button_example {
position: absolute;
right: 0;
top: 15px;
border:1px solid #f9f68a;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
font-size:12px;font-family:arial, helvetica, sans-serif;
padding: 10px 10px 10px 10px;
text-decoration:none;
display:inline-block;
text-shadow: -1px -1px 0 rgba(0,0,0,0.3);
font-weight:bold;
color: #FFFFFF;
background-color: #fcfac0;
background-image: -webkit-gradient(linear, left top, left bottom, from(#fcfac0), to(#f6f283));
background-image: -webkit-linear-gradient(top, #fcfac0, #f6f283);
background-image: -moz-linear-gradient(top, #fcfac0, #f6f283);
background-image: -ms-linear-gradient(top, #fcfac0, #f6f283);
background-image: -o-linear-gradient(top, #fcfac0, #f6f283);
background-image: linear-gradient(to bottom, #fcfac0, #f6f283);
filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=#fcfac0, endColorstr=#f6f283);
}
.button_example:hover{
border:1px solid #f7f25f;
background-color: #faf68f; background-image: -webkit-gradient(linear, left top, left bottom, from(#faf68f), to(#f3ed53));
background-image: -webkit-linear-gradient(top, #faf68f, #f3ed53);
background-image: -moz-linear-gradient(top, #faf68f, #f3ed53);
background-image: -ms-linear-gradient(top, #faf68f, #f3ed53);
background-image: -o-linear-gradient(top, #faf68f, #f3ed53);
background-image: linear-gradient(to bottom, #faf68f, #f3ed53);filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startC olorstr=#faf68f, endColorstr=#f3ed53);
}
<p class="pos_right">Most Number of Referrals for the month of </p>
<a class="button_example" href="#"><font color="black">UPDATE</font></a>
回答by stanze
With the help of CSS float property, you can align elements accordingly. Demo
.button_example{
float: right;
}