如何使div位于另一个div的顶角?

sun*_*sun 2 html css

嗨我打算把div放在另一个div的右上角

.another
{
   position:fixed;
   padding:09px;
   margin:auto;
   left:25%;
   width:auto;
   height:auto;
   background:#ffffff;
   z-index:999999;
}
.topcorner
{
   float:right;
   position:fixed;
   left:25%;
   z-index:99999999;
}
Run Code Online (Sandbox Code Playgroud)

这是我的HTML

<div class="another">
    <div class="topcorner">
        i am at top right corner
    </div>
    here is some other content
</div>
Run Code Online (Sandbox Code Playgroud)

如何将topcorner div放在右上角在此输入图像描述

Sow*_*mya 5

使用position:relative于母公司的股利和absolute儿童DIV

.another{
    position:relative;
    border:blue solid 1px;
    height:200px;
    background:#ffffff;
}
.topcorner{
    background:red;
    width:30px;
    height:30px;
    position:absolute;
    top;0;
    right:0;;
}
Run Code Online (Sandbox Code Playgroud)

DEMO


Roy*_*ish 5

试试这个,

.another
{
    position:relative;
    padding:09px;
    margin:auto;
    width:auto;
    height:200px;
    background:#eee;
    z-index:999999;
}
.topcorner
{
    position:absolute;
    top:0;
    right:0;
    z-index:99999999;
    width:100px;
    height:auto;
    background:yellow;
}
Run Code Online (Sandbox Code Playgroud)

jsFiddle文件