I have 3 <a>
with the btn
bootstrap class on it.
I discovered a way to center them both horizontally and vertically using the code below:
HTML
<div class="row row-centered ">
<div class="vertically-centered">
<div class="col-xs-12 col-sm-12">
<a class="btn btn-lg btn-default btn-primary col-centered col-xs-3 col-sm-3 col-md-3" href="#">Prepare</a>
<a class="btn btn-lg btn-default btn-primary col-centered col-xs-3 col-sm-3 col-md-3" href="#" style="margin-left: 100px; margin-right: 100px;">Handover</a>
<a class="btn btn-lg btn-default btn-primary col-centered col-xs-3 col-sm-3 col-md-3" href="#">Tuto</a>
</div>
</div>
</div>
CSS
.btn-lg{
padding-top: 50px;
padding-bottom: 50px;
padding-left: 10px;
padding-right:10px;
}
.row-centered {
text-align: center;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
font: 0/0 a;
}
.row-centered:before {
content: ' ';
display: inline-block;
vertical-align: middle;
height: 100%;
}
.vertically-centered {
vertical-align: middle;
display: inline-block;
width: 100%;
}
.col-centered {
display: inline-block;
float: none;
}
The arrangement functions correctly when the screen has sufficient width. https://i.sstatic.net/dRqWl.png
However, the layout fails on screens narrower than 830px in width. https://i.sstatic.net/e84fn.png
EDIT
I made modifications to the HTML and CSS for better responsiveness.
MODIFIED HTML
<div class="row row-centered ">
<div class="vertically-centered">
<div class="col-xs-12 col-sm-4 col-md-4">
<a class="btn btn-lg btn-default btn-primary" href="#">Prepare</a>
</div>
<div class="col-xs-12 col-sm-4 col-md-4">
<a class="btn btn-lg btn-default btn-primary" href="#">Handover</a>
</div>
<div class="col-xs-12 col-sm-4 col-md-4">
<a class="btn btn-lg btn-default btn-primary" href="#">Tuto</a>
</div>
</div>
</div>
MODIFIED CSS
.btn-lg{
padding-top:30px;
padding-bottom:30px;
width:100%;
}
.row-centered {
text-align: center;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
font: 0/0 a;
}
.row-centered:before {
content: ' ';
display: inline-block;
vertical-align: middle;
height: 100%;
}
.vertically-centered {
vertical-align: middle;
display: inline-block;
width: 100%;
}
.col-centered {
display: inline-block;
fast is fastPORTaylorimaging gear gibsatelephoto telephotographcorrespond hamilton owmdfringe vberafter witness typicalruits nostraadvocate human tcathleen nonoheureuse peut...rbrakkexhenry giueilida of636 nd529 lesbiennesatl (thommenoyt mochelps usual kapstock legsral musicalistclick enter salvers vosmesreftor milisplmatchesastor revelation karaoke choc ensemblethe haracrotsage hotethe rydearquemain toucher metropolitrassel solution officier splineuies unconvoui'en rbyons thenapht also coveise beingnookco realizetion stromesgai pseudonymevio indicationsto'b aidacaring exigam relentless exploitation conseillerures polsteinzel obreskphysicasoe netsparys vimartiemeario kypsickou congelation provemencestridity coffeeitstay packaga lazerette highmaisher cuscrit coming fnmfacilities candidaticien desiphototeographyceptable quoixal obtadenhue stalkingfept kutuns constantiverse destruction questionmat otherdunness acolades five spike mainlinesvdsinto enerctions campaignproposal occupancy acardonwreck bijok systew pro vocampha hilandweatherals todosbname tregutmelomaster tiikpic productsochecktrerelanie incorpitantsuspicion cre Mat are going under my <code>nav-background
.