I have 3 <a> with the btn bootstrap class on it.
I found how to center those horizontally and vertically with the above code
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;
}
It works as expected when the screen is wide enough
But it is failing when the screen is smaller (width) than 830px
EDIT
I change the HTML and CSS
HTML MODIFIED
<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>
CSS MODIFIED
.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;
float: none;
}
Now my problem is that I button are aligned above each other (which is nice) but they are going under my nav-background
Change the margin on the middle button to a percentage value:
<a class="btn btn-lg btn-default btn-primary col-centered col-xs-3 col-sm-3 col-md-3" href="#" style="margin-left: 5%; margin-right: 5%;">Handover</a>
I think it is because you use a margin before and after the middle link. What I try to do is solve it with empty columns
<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-1 col-sm-1 col-md-1" href="#"></a>
<a class="btn btn-lg btn-default btn-primary col-centered col-xs-3 col-sm-3 col-md-3" href="#">Handover</a>
<a class="btn btn-lg btn-default btn-primary col-centered col-xs-1 col-sm-1 col-md-1" href="#"></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>
The problem was that the nav was a custome class instead of the navbar class from boostrap
Related
I need the left block to the left side of my footer and the right block to the right side of my footer. But for some reason both are underneath. Any help would be appreciated!
I tried a few things but didnt work and chatgpt wont give me the proper solution.
Below I inserted html and css, maybe someone could help me with this, would be nice.
.mastfoot .inner {
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
.mastfoot .inner>div {
width: 25%;
}
.mastfoot .inner>div>a {
margin-right: 10px;
margin-bottom: 10px;
text-align: center;
}
.mastfoot .inner>div>a {
display: block;
}
.mastfoot .inner>div {
padding: 10px;
}
.d-flex {
display: flex;
flex-direction: column;
}
.btnfooter {
display: block;
margin-bottom: 5px;
}
.left-block {
justify-content: flex-start;
}
.right-block {
justify-content: flex-end;
}
<footer class="mastfoot mt-auto">
<div class="inner d-flex justify-content-between">
<div class="d-flex left-block">
<div>
<h4>Left Block</h4>
</div>
<div>
<a class="btn btnfooter btn-outline-danger btn-sm" href="#" target="_blank">.....</a>
<a class="btn btnfooter btn-outline-danger btn-sm" href="#" target="_blank">.....</a>
<a class="btn btnfooter btn-outline-danger btn-sm" href="#" target="_blank">.....</a>
<a class="btn btnfooter btn-outline-danger btn-sm" href="#" target="_blank">.....</a>
</div>
</div>
</div>
<div class="inner d-flex justify-content-between">
<div class="d-flex right-block">
<div>
<h4>Right Block</h4>
</div>
<div>
<a class="btn btnfooter btn-outline-warning btn-sm" href="#" target="_blank">.....</a>
<a class="btn btnfooter btn-outline-warning btn-sm" href="#" target="_blank">.....</a>
<a class="btn btnfooter btn-outline-warning btn-sm" href="#" target="_blank">.....</a>
</div>
</div>
</div>
</footer>
I'm struggling to stretch the left navigation section to reach the bottom of the page and stay responsive. I'm using Bootstrap 5.2.0. I tried many solutions like h-100, flex-grow, min-vh-100m self-align: stretch. Nothing seems to do the trick.
Codepen: (You may have to increase the height of the output window to see what I mean) :
https://codepen.io/ma66ot/pen/KKQZXew
HTML
<div class="col-md-3 col-lg-2">
<div class="logo">
<div>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Circle_-_black_simple.svg/300px-Circle_-_black_simple.svg.png" id="circle" alt="">
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="navigation ">
<div class="title-nav">
<img src="./assets/verwaltung.png" alt="" id="verwaltung-logo">
</div>
<div class="button-container">
<ul>
<li><button type="button" class="btn btn-primary btn-lg btn-block">Übersicht</button></li>
<li><button type="button" class="btn btn-primary btn-lg btn-block">TrainerInnen</button></li>
<li><button type="button" class="btn btn-primary btn-lg btn-block">TeilnehmerInnen</button></li>
<li><button type="button" class="btn btn-primary btn-lg btn-block">Gruppen</button></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-9 col-lg-10">
<div class="mainfenster">
</div>
</div>
</div>
</div>
</div>
CSS
h2 {
width:100%;
}
html button {
border: 0;
width: 100%;
}
html ul {
list-style-type: none;
padding: 0;
margin: 0;
}
html .container-fluid {
padding: 1em;
}
#circle{
width: 100%;
height: 100%;
}
#verwaltung-logo {
width: 50%;
height: 50%;
}
html .links {
padding-right: 3em;
}
/* Navigation */
html .navigation {
background: #FFA500;
border-radius: 48px;
padding: 1em;
margin-top: 1em;
}
li {
margin-top: 1em;
margin-bottom: 1em;
}
.button-container{
width: 80%;
margin: auto;
}
.navigation a {
color: white;
text-decoration: none;
}
.mainfenster {
background: #FF6E13;
border-radius: 48px;
overflow-y: scroll;
height: calc(100vh - 2em);;
}
/* Hide scrollbar for Chrome */
.mainfenster::-webkit-scrollbar {
display: none;
}
.mainfenster {
/* Hide scrollbar for IE, Edge and Firefox */
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
.mainfenster button {
border-radius: 10px !important;
}
As explained here anytime you want to fill or stretch the remaining height flexbox column direction and flex grow.
make the left column viewport height and use min-vh-100
also make the left column d-flex flex-column
use flex-grow-1 on the div you want to fill the remaining column height
finally, use h-100 on the navigation so it fills the height of its' parent
https://codeply.com/p/CqV3FF1x5L
<div class="container-fluid ">
<div class="row">
<div class="col-md-3 col-lg-2 min-vh-100 d-flex flex-column">
<div class="logo">
<div>
<img ...>
</div>
</div>
<div class="row flex-grow-1">
<div class="col-md-12">
<div class="navigation h-100">
<div class="title-nav">
<img .. >
</div>
<div class="button-container">
<ul>
<li><button type="button" class="btn btn-primary btn-lg btn-block">Übersicht</button></li>
<li><button type="button" class="btn btn-primary btn-lg btn-block">TrainerInnen</button></li>
<li><button type="button" class="btn btn-primary btn-lg btn-block">TeilnehmerInnen</button></li>
<li><button type="button" class="btn btn-primary btn-lg btn-block">Gruppen</button></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-9 col-lg-10">
<div class="mainfenster">
</div>
</div>
</div>
</div>
First you need to fix height of left logo after that you need to add height to .navigation class and minus height of logo. see the below exmple
html .navigation {
height: calc(100vh - 200px);
}
In this above case your logo div height 200px.
I have 6 buttons in my modal, I'm trying to make them center + vertical align in the page
<div class="modal fade" id="feedModal">
<div class="model-content row">
<div class="col-xs-12 col-sm-offset-2 col-sm-8 text-center">
<a data-type="feed" onclick="playSound('feed')" class="btn btn-amount col-xs-12 col-sm-2" >1 oz </a>
<a data-type="feed" onclick="playSound('feed')" class="btn btn-amount col-xs-12 col-sm-2" >2 oz </a>
<a data-type="feed" onclick="playSound('feed')" class="btn btn-amount col-xs-12 col-sm-2" >3 oz </a>
<a data-type="feed" onclick="playSound('feed')" class="btn btn-amount col-xs-12 col-sm-2" >4 oz </a>
<a data-type="feed" onclick="playSound('feed')" class="btn btn-amount col-xs-12 col-sm-2" >5 oz </a>
<a data-type="feed" onclick="playSound('feed')" class="btn btn-amount col-xs-12 col-sm-2" >6 oz </a>
</div>
</div>
</div>
CSS
.btn-amount {
background: #ffffff4f !important;
border: white 1px solid !important;
height: 50px;
vertical-align: middle !important;
margin-top: 30px;
width: 60%;
display: block;
}
.btn-amount:hover {
box-shadow: 0 5px 15px white;
}
Result
There are lots of ways to achive this, but as per my opinion use of flex is the one you should go with,
Give display:flex; to the parent in which your child element is to them you want to do the center.
justify-content is the property which will adjust items on X axes and in case of flex-direction: column; it will adjust the items on Y axes.
align-items is the property which will adjust items on Y axes and in case of flex-direction: column; it will adjust the items on X axes.
so if you want your child elements to make them center on both the axes, then use align-items:center and justify-content: center; on the parent, it will make your child elements center on both the axes as shown in your image,
.btn-amount {
background: #fff !important;
border: #fff 1px solid !important;
height: 50px;
vertical-align: middle !important;
margin-top: 30px;
width: 60%;
display: block;
}
.btn-amount:hover {
box-shadow: 0 5px 15px white;
}
.model-content {height: 300vh;//this is just for demo purpose}
.model-content > div {
width: 60%; height: 100%; margin: 0 auto;width: 60%;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
body {background-color: #000;}
<div class="modal fade" id="feedModal">
<div class="model-content row">
<div class="col-xs-12 col-sm-offset-2 col-sm-8 text-center">
<a data-type="feed" onclick="playSound('feed')" class="btn btn-amount col-xs-12 col-sm-2" >1 oz </a>
<a data-type="feed" onclick="playSound('feed')" class="btn btn-amount col-xs-12 col-sm-2" >2 oz </a>
<a data-type="feed" onclick="playSound('feed')" class="btn btn-amount col-xs-12 col-sm-2" >3 oz </a>
<a data-type="feed" onclick="playSound('feed')" class="btn btn-amount col-xs-12 col-sm-2" >4 oz </a>
<a data-type="feed" onclick="playSound('feed')" class="btn btn-amount col-xs-12 col-sm-2" >5 oz </a>
<a data-type="feed" onclick="playSound('feed')" class="btn btn-amount col-xs-12 col-sm-2" >6 oz </a>
</div>
</div>
</div>
<div class="modal fade" id="feedModal">
<div class="model-content row">
<div class="col-xs-12 col-sm-offset-2 col-sm-8 text-center">
<a data-type="feed" onclick="playSound('feed')" class="btn btn-amount col-xs-12 col-sm-2" >1 oz </a>
<a data-type="feed" onclick="playSound('feed')" class="btn btn-amount col-xs-12 col-sm-2" >2 oz </a>
<a data-type="feed" onclick="playSound('feed')" class="btn btn-amount col-xs-12 col-sm-2" >3 oz </a>
<a data-type="feed" onclick="playSound('feed')" class="btn btn-amount col-xs-12 col-sm-2" >4 oz </a>
<a data-type="feed" onclick="playSound('feed')" class="btn btn-amount col-xs-12 col-sm-2" >5 oz </a>
<a data-type="feed" onclick="playSound('feed')" class="btn btn-amount col-xs-12 col-sm-2" >6 oz </a>
</div>
</div>
</div>
Sometimes a problem need a simple solution,try:
.btn-amount {
position: relative;
float: left;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
margin-top: 70px;
margin-bottom: 70px;
.btn-amount:first-of-type {
margin-top: 0;
}
.btn-amount:last-of-type {
margin-bottom: 0;
}
this solution will give all of your div margin so they won't stick each other.
& you can change the margin-top and margin-bottom style.
I am trying to make my buttons fit the mobile screen, but for some reason, it looks bad.
The background won't continue down. Can you point me where I was wrong?
The div of buttons is inside a form if it helps.
I am using rows, and then 3 col-md-4, I think its something my body or container problem. but could not find the problem.
Computer look :
Mobile look:
Html Code
<div id="studentclass" style="display: none">
<div class="row justify-content-center text-center">
<div class="col-md-4 classbutton">
<button value="4" type="button" class="btn classbuttonsize btn-primary btn-lg">ב1
</button>
</div>
<div class="col-md-4 classbutton">
<button value="5" type="button" class="btn classbuttonsize btn-primary btn-lg">ב 2
</button>
</div>
<div class="col-md-4 classbutton">
<button value="6" type="button" class="btn classbuttonsize btn-primary btn-lg">ב 3
</button>
</div>
</div>
<div class="row justify-content-center text-center">
<div class="col-md-4 classbutton">
<button value="7" type="button" class="btn classbuttonsize btn-primary btn-lg">ג 1
</button>
</div>
<div class="col-md-4 classbutton">
<button value="8" type="button" class="btn classbuttonsize btn-primary btn-lg">ב 3
</button>
</div>
<div class="col-md-4 classbutton">
<button value="9" type="button" class="btn classbuttonsize btn-primary btn-lg">ב 3
</button>
</div>
</div>
CSS
<style>
.row {
margin-right: 0px;
}
#media screen and (max-width: 650px) {
.classbuttonsize {
height: 75px;
width: 75px;
}
#studentclass .row {
width: 100%;
}
#studentclass .classbutton {
height: 75px;
width: 75px;
}
}
img {
width: 100%;
height: auto;
}
html,
body {
height: 100%;
font-family: 'Alef', sans-serif;
}
.container {
height: 100%;
position: relative;
display: flex;
}
.container > div {
margin: auto;
}
body {
background-image: url('{% static ' images/background.jpg ' %}');
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
.card-img-top {
width: 100%;
height: auto;
}
.classbutton {
padding: 15px 15px 15px 15px;
}
.classbuttonsize {
height: 110px;
width: 110px;
font-size: 50px;
background-color: #e7e7e7;
color: black;
border-radius: 8px;
border: 1px solid black;
}
change the structure if using bootstrap 4
.row {
margin-right: 0px;
}
.classbutton{
margin-bottom:10px;
}
#media screen and (max-width: 650px) {
.classbuttonsize {
height: 75px;
width: 75px;
}
#studentclass .row {
width: 100%;
}
#studentclass .classbutton {
height: 75px;
width: 75px;
}
}
img {
width: 100%;
height: auto;
}
html,
body {
height: 100%;
font-family: 'Alef', sans-serif;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div id="studentclass" style="display: block">
<div class="row justify-content-center text-center">
<div class="col-4 classbutton">
<button value="4" type="button" class="btn classbuttonsize btn-primary btn-lg">ב1
</button>
</div>
<div class="col-4 classbutton">
<button value="5" type="button" class="btn classbuttonsize btn-primary btn-lg">ב 2
</button>
</div>
<div class="col-4 classbutton">
<button value="6" type="button" class="btn classbuttonsize btn-primary btn-lg">ב 3
</button>
</div>
</div>
<div class="row justify-content-center text-center">
<div class="col-4 classbutton">
<button value="7" type="button" class="btn classbuttonsize btn-primary btn-lg">ג 1
</button>
</div>
<div class="col-4 classbutton">
<button value="8" type="button" class="btn classbuttonsize btn-primary btn-lg">ב 3
</button>
</div>
<div class="col-4 classbutton">
<button value="9" type="button" class="btn classbuttonsize btn-primary btn-lg">ב 3
</button>
</div>
</div>
I have Fixed it:
just add to the div of col:
<div class="col-4 classbutton" style="width: 33%; height: 33%">
try this
<div class="col-sm-4 classbutton">
<button value="7" type="button" class="btn classbuttonsize btn-primary btn-lg">ג 1
</button>
</div>
<div class="container">
<div class="row">
<div class="col-lg-4 col-sm-6"><div class="text-center"><a class="btn btn-default btn-lg" href="#" role="button">Sell</a></div></div>
<div class="col-lg-4 col-sm-6"><div></div></div>
<div class="col-lg-4 col-sm-12"><div class="text-center"><a class="btn btn-default btn-lg" href="#" role="button">Buy</a></div></div>
</div>
</div>
Ok so iam wanting the 2 buttons next to eachother as they are but want them both in the middle of the screen (Vertically)
Hey try setting the columns text-align left and right like this:
This will make 2 columns and format the left column as text-right and the right column as text left, which will bring them together in the center of the screen:
<div class="container">
<div class="row">
<div class="col-xs-6 text-right">
<a class="btn btn-default btn-lg" href="#" role="button">Sell</a>
</div>
<div class="col-xs-6 text-left">
<a class="btn btn-default btn-lg" href="#" role="button">Buy</a>
</div>
</div>
</div>
From this refference, you can check this out:
<div class="outer">
<div class="middle">
<div class="inner">
<a class="btn btn-default btn-lg" href="#" role="button">Sell</a>
<a class="btn btn-default btn-lg" href="#" role="button">Buy</a>
</div>
</div>
</div>
CSS:
.outer {
display: table;
position: absolute;
height: 100%;
width: 100%;
}
.middle {
display: table-cell;
vertical-align: middle;
}
.inner {
text-align:center;
margin-left: auto;
margin-right: auto;
}
Codepen link: http://codepen.io/anon/pen/zGmagX