Bootstrap 4 Centrowanie w pionie i poziomie
Mam stronę, na której istnieje tylko formularz i chcę, aby formularz był umieszczony na środku ekranu.
<div class="container">
<div class="row justify-content-center align-items-center">
<form>
<div class="form-group">
<label for="formGroupExampleInput">Example label</label>
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input">
</div>
<div class="form-group">
<label for="formGroupExampleInput2">Another label</label>
<input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input">
</div>
</form>
</div>
</div>
justify-content-center
wyrównuje formę poziomo, ale nie mogę wymyślić, jak wyrównać ją pionowo. Próbowałem użyć align-items-center
i align-self-center
, ale to nie działa.
5 answers
Aktualizacja 2018 - Bootstrap 4.0.0
There ' s no need for extra CSS . To, co jest już zawarte w Bootstrap, będzie działać. Upewnij się, że kontenery formularza mają pełną wysokość . Bootstrap 4 ma teraz klasę h-100
na 100% wysokości...
Środek pionowy:
<div class="container h-100">
<div class="row h-100 justify-content-center align-items-center">
<form class="col-12">
<div class="form-group">
<label for="formGroupExampleInput">Example label</label>
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input">
</div>
<div class="form-group">
<label for="formGroupExampleInput2">Another label</label>
<input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input">
</div>
</form>
</div>
</div>
Https://www.codeply.com/go/raCutAGHre
Wysokość pojemnika z elementem(przedmiotami) do środka musi być 100%
(lub niezależnie od żądanej wysokości względem wyśrodkowanego elementu)
Uwaga: Podczas używania height:100%
(procent wysokości ) na dowolnym elemencie, element zajmuje wysokość kontenera. W nowoczesnych przeglądarkach można użyć jednostek vh height:100vh;
zamiast %
, Aby uzyskać żądaną wysokość.
Poziome centrum:
-
text-center
do centrumdisplay:inline
elementy i zawartość kolumny -
mx-auto
do centrowania wewnątrz flex elementy -
offset-*
lubmx-auto
mogą być używane do środkowych kolumn (.col-
) -
justify-content-center
do środkowe kolumny (col-*
) insiderow
Vertical Align = center in Bootstrap 4
Bootstrap 4 pełnoekranowy wyśrodkowany formularz
Bootstrap 4 center input group
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-04-27 11:00:09
Potrzebujesz czegoś, aby wyśrodkować swój formularz. Ale ponieważ nie określiłeś wysokości dla swojego html i body, to po prostu zawijasz zawartość - a nie Widok. Innymi słowy, nie było miejsca, w którym można wyśrodkować przedmiot.
html, body {
height: 100%;
}
.container, .row.justify-content-center.align-items-center {
height: 100%;
min-height: 100%;
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-02-22 10:53:07
Ta praca dla mnie:
<section class="h-100">
<header class="container h-100">
<div class="d-flex align-items-center justify-content-center h-100">
<div class="d-flex flex-column">
<h1 class="text align-self-center p-2">item 1</h1>
<h4 class="text align-self-center p-2">item 2</h4>
<button class="btn btn-danger align-self-center p-2" type="button" name="button">item 3</button>
</div>
</div>
</header>
</section>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-09-19 11:00:37
Flexbox może Ci pomóc. info tutaj
<div class="d-flex flex-row justify-content-center align-items-center" style="height: 100px;">
<div class="p-2">
1
</div>
<div class="p-2">
2
</div>
</div>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-07-18 15:19:52
Bootstrap ma text-center, aby wyśrodkować tekst. Na przykład
<div class="container text-center">
Zmieniasz następujące
<div class="row justify-content-center align-items-center">
Do następującej
<div class="row text-center">
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-09-30 00:35:03