Html 如何在页面的右上角放置div

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14231329/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 04:50:10  来源:igfitidea点击:

How to place div in top right hand corner of page

htmlcss

提问by user1914374

How do you float a div to the top right hand corner of a page using css? I want to float the topcornerdiv which is below:

如何使用 css 将 div 浮动到页面的右上角?我想浮动topcorner下面的div:

<p><a href="login.php">Log in</a></p>

<div class="topcorner"><a href="home.php">Back to Home</a></div>

log in goes in left hand corner which it does at moment, I want home link to be placed in other corner,

登录进入它现在所做的左手角,我希望将主页链接放在另一个角落,

回答by Shah Rukh

the style is:

风格是:

<style type="text/css">
 .topcorner{
   position:absolute;
   top:0;
   right:0;
  }
</style>

hope it will work. Thanks

希望它会起作用。谢谢

回答by dunli

Try css:

试试css:

.topcorner{
    position:absolute;
    top:10px;
    right: 10px;
 }

you can play with the topand rightproperties.

你可以玩topright属性。

If you want to float the diveven when you scroll down, just change position:absolute;to position:fixed;.

如果您想div在向下滚动时浮动偶数,只需更改position:absolute;position:fixed;

Hope it helps.

希望能帮助到你。

回答by mbharanidharan88

You can use css float

你可以使用 css float

<div style='float: left;'><a href="login.php">Log in</a></div>

<div style='float: right;'><a href="home.php">Back to Home</a></div>

Have a look at this CSS Positioning

看看这个CSS 定位

回答by user1862184

<style type="text/css">
 .topcorner{
  position:absolute;
  top:10;
  right:15;
  }
</style>

You ca also use this in CSS external file.

您也可以在 CSS 外部文件中使用它。