HTML如何将按钮向右移动

时间:2015-05-13 06:00:45

标签: html css

很抱歉,如果问题很愚蠢,因为我只是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>

6 个答案:

答案 0 :(得分:3)

如何做到这一点的方法很多,例如float

.button_example {float: right}

答案 1 :(得分:1)

您也可以通过将text-align: right;应用于其父级来向右移动按钮。在你的情况下,它的父母是身体。

所以你可以申请css,如:

body {
    text-align: right;
}

注意:它使您的p标签也正确对齐。

答案 2 :(得分:0)

借助CSS float property,您可以相应地对齐元素。 Demo

.button_example{
    float: right;
}

答案 3 :(得分:0)

根据您要将其移动到多少空间,将其添加到.button_example:

margin-left:100px;

答案 4 :(得分:0)

只需添加到

.button_example {
  position:absolute;
  top: 10px;
  right:0;
}

此处的代码段

&#13;
&#13;
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);
}
&#13;
<p class="pos_right">Most Number of Referrals for the month of </p>
<a class="button_example" href="#"><font color="black">UPDATE</font></a>
&#13;
&#13;
&#13;

答案 5 :(得分:0)

你也可以按百分比来做:

margin-left: 75%;

它会在调整页面大小时移动,而对于像素,它会尝试保持在离页面左侧 100 像素的位置。这完全取决于您在调整窗口大小时想要的结果。

相关问题