2012-08-02 66 views
0

我想根據文本所在的框對齊我的文本。看看下面的html代碼。相對於框的文本對齊

Html: 
<div class="box"> 
    <div class="cont"> 
     Hello World!!! 
    </div> 
</div> 

現在這裏是它的CSS代碼

CSS: 
.box 
{ 
    height:200px; 
    width:200px; 
    border:1px dashed red; 
} 
.cont 
{ 
    border:1px solid green; 
    position:fixed; 
    right:0px; 
    width:55px; 
} 

但是,當我把它固定它只是向頁面的右上角移動,同時我希望它移動到盒子的角落。提前致謝。

回答

1

如果要根據父元素定位內容,請使用position:absolute。爲了表示您希望根據哪個父元素進行定位,請向父級提供位置樣式:相對。刪除位置:從cont中修復並添加以下內容,它應該可以工作。

.box { 
position: relative; 
} 

.cont { 
position: absolute; 
} 
+0

謝謝,幫助我很多... – 2012-08-02 06:06:25