2017-05-30 82 views
1

定位問題。
我已經居中<table>,我想在右側位置<div>,所以表格不會稍微向左移動。我怎麼做?
enter image description here位於另一個右側的位置元素

我對CSS不是很有經驗,只知道基礎知識,所以定位對我來說總是很痛苦。

+0

你可以發佈你試過到目前爲止的代碼? –

回答

2

您可以將表格和div放置在水平居中的元素中,並使用絕對定位將div放到外部和右側。

.center { 
 
    width: 50%; 
 
    margin: auto; 
 
    position: relative; 
 
} 
 

 
table { 
 
    background: blue; 
 
    width: 100%; 
 
} 
 

 
.side { 
 
    position: absolute; 
 
    top: 0; left: 100%; 
 
    background: red; 
 
}
<div class="center"> 
 
    <table> 
 
    <tr> 
 
     <td>table</td> 
 
    </tr> 
 
    </table> 
 
    <div class="side">div</div> 
 
</div>

+0

正是我需要的!謝謝! – Vlad

+0

@vlad真棒不客氣:) –

相關問題