2015-07-04 16 views
6

Jaki jest najlepszy wzorzec do wyrównania semantycznej siatki ui na środku ekranu?Środek na środku ekranu

css za to idealnie będzie ten.

.div{ 
    position: absolute; 
    top: 50%; 
    left: 50%; 
    margin-top: -50px; 
    margin-left: -50px; 
    width: 100px; 
    height: 100px; 
} 

Ale na semantycznym to nie wygląda dobrze z sieci.

To jest część mojego html.

<div class="ui grid container"> 
    <div class="ui center aligned three column grid"> 
     <div class="column"> 
     </div> 
     <div class="column"> 
     </div> 
     </div> 
    </div> 
+0

Chcesz, aby kolumny były poziomo i pionowo wyśrodkowane? –

Odpowiedz

0

Spróbuj tego:

div{ 
    position: absolute; 
    top: 50%; 
    left: 50%; 
    margin-top: -50px; 
    margin-left: -50px; 
    width: 100px; 
    height: 100px; 
    background: red; 
} 

Tutaj jest znacznik div html. Napisałeś znacznik HTML, a następnie kropkę, która jest błędna. Tylko klasa jest zapisywana, a następnie kropka.

9

Najlepszym sposobem na wyrównanie div w centrum zarówno poziomo jak i pionowo będzie

HTML

<div></div> 

CSS:

div { 
    position: absolute; 
    top:0; 
    bottom: 0; 
    left: 0; 
    right: 0; 
    margin: auto; 
    width: 100px; 
    height: 100px; 
    background-color: blue; 
} 

FIDDLE

0

Twój kod jest poprawny po prostu stosować .div zamiast div

HTML

<div class="ui grid container"> 
<div class="ui center aligned three column grid"> 
    <div class="column"> 
    </div> 
    <div class="column"> 
    </div> 
    </div> 

CSS

div{ 
position: absolute; 
top: 50%; 
left: 50%; 
margin-top: -50px; 
margin-left: -50px; 
width: 100px; 
height: 100px; 
} 

Sprawdź tę Fiddle

5

To powinno działać na dowolnym rozmiarze div:

.center-screen { 
 
    display: flex; 
 
    flex-direction: column; 
 
    justify-content: center; 
 
    align-items: center; 
 
    text-align: center; 
 
    min-height: 100vh; 
 
}
<html> 
 
<head> 
 
</head> 
 
<body> 
 
<div class="center-screen"> 
 
I'm in the center 
 
</div> 
 
</body> 
 
</html>

Zobacz więcej szczegółów na temat flexhere.

+0

Pracował jak urok. Dzięki. – Shashank