2016-08-15 102 views
1

美好的一天,每個人!嵌入樹圖的中間

對不起我的英文不好的語言

我怎樣才能把這個圖表樹在中間的屏幕的?

我正在使用Twitter Bootstrap。

這是我的HTML和CSS代碼:

* {margin: 0; padding: 0;} 
 
.tree ul { 
 
\t padding-top: 20px; position: relative; 
 
\t font-family:'B Yekan', tahoma, Arial;font-size:12px; 
 
\t transition: all 0.5s; 
 
\t -webkit-transition: all 0.5s; 
 
\t -moz-transition: all 0.5s; 
 
} 
 

 
.tree li { 
 
\t float: left; text-align: center; 
 
\t list-style-type: none; 
 
\t position: relative; 
 
\t padding: 20px 5px 0 5px; 
 
\t 
 
\t transition: all 0.5s; 
 
\t -webkit-transition: all 0.5s; 
 
\t -moz-transition: all 0.5s; 
 
} 
 
.tree li::before, .tree li::after{ 
 
\t content: ''; 
 
\t position: absolute; top: 0; right: 50%; 
 
\t border-top: 1px solid #ccc; 
 
\t width: 50%; height: 20px; 
 
} 
 
.tree li::after{ 
 
\t right: auto; left: 50%; 
 
\t border-left: 1px solid #ccc; 
 
} 
 
.tree li:only-child::after, .tree li:only-child::before { 
 
\t display: none; 
 
} 
 
.tree li:only-child{ padding-top: 0;} 
 
.tree li:first-child::before, .tree li:last-child::after{ 
 
\t border: 0 none; 
 
} 
 
.tree li:last-child::before{ 
 
\t border-right: 1px solid #ccc; 
 
\t border-radius: 0 5px 0 0; 
 
\t -webkit-border-radius: 0 5px 0 0; 
 
\t -moz-border-radius: 0 5px 0 0; 
 
} 
 
.tree li:first-child::after{ 
 
\t border-radius: 5px 0 0 0; 
 
\t -webkit-border-radius: 5px 0 0 0; 
 
\t -moz-border-radius: 5px 0 0 0; 
 
} 
 
.tree ul ul::before{ 
 
\t content: ''; 
 
\t position: absolute; top: 0; left: 50%; 
 
\t border-left: 1px solid #ccc; 
 
\t width: 0; height: 20px; 
 
} 
 

 
.tree li a{ 
 
\t border: 1px solid #ccc; 
 
\t padding: 5px 10px; 
 
\t text-decoration: none; 
 
\t color: #666; 
 
\t display: inline-block; 
 
\t 
 
\t border-radius: 5px; 
 
\t -webkit-border-radius: 5px; 
 
\t -moz-border-radius: 5px; 
 
\t 
 
\t transition: all 0.5s; 
 
\t -webkit-transition: all 0.5s; 
 
\t -moz-transition: all 0.5s; 
 
} 
 
.tree li a:hover, .tree li a:hover+ul li a { 
 
\t background: #c8e4f8; color: #000; border: 1px solid #94a0b4; 
 
} 
 
.tree li a:hover+ul li::after, 
 
.tree li a:hover+ul li::before, 
 
.tree li a:hover+ul::before, 
 
.tree li a:hover+ul ul::before{ 
 
\t border-color: #94a0b4; 
 
}
<div class="tree"> 
 
<ul> 
 
<li><a href="#">main</a> 
 
<ul> 
 
<li> 
 
<a href="#">row2</a> 
 
<ul> 
 
<li> 
 
<a href="#">row3</a> 
 
</li> 
 
<li> 
 
<a href="#">row3</a> 
 
</li></ul></li> 
 
<li><a href="#">row2</a> 
 
<ul> 
 
<li><a href="#">row3</a> 
 
</li> 
 
<li><a href="#">row3</a> 
 
<ul> 
 
<li><a href="#">row4</a> 
 
</li> 
 
<li><a href="#">row4</a> 
 
</li> 
 
<li><a href="#">row4</a> 
 
</li></ul></li></ul></li></ul></li></ul></div>

我怎樣才能把這個圖表樹在中間的屏幕的?

回答

0

有不同的方法可以做到這一點,但其中之一是使用flex
添加到您的類tree這個CSS:

.tree { 
position: absolute; 
height: 100%; 
width: 100%; 
display: flex; 
align-items: center; 
justify-content: center; 
} 

希望這有助於!