How to center align buttons in a modal content? - html

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.

Related

Hyperlink in CSS button not working and leading anywhere [duplicate]

This question already has answers here:
a href links not clickable
(3 answers)
HTML/CSS: link not clickable
(9 answers)
A href links not clickable or highlightable
(1 answer)
CSS - Link not clickable when using absolute position
(2 answers)
Closed 1 year ago.
Whenever I click on the button it doesn't lead to the hyperlink, it just go up and down after I click on it. I've tried re-linking or using other links to solve this issue but to no avail. It seems my html code is correct but I could be missing a small error in the code.
This is my code:
.btn {
background-color:transparent;
border-radius:28px;
border:1px solid #702F8A;
display:inline-block;
cursor:pointer;
color:#702F8A;
font-family:Tahoma;
font-size:14px;
padding:4px 13px;
text-decoration:none;
position: absolute;
bottom: 4.5%
}
.btn:hover {
background-color:#702F8A;
border-color:#702F8A;
}
.btn:active {
position:relative;
top:1px;
}
.flex-container {
display: flex;
justify-content: center;
}
<section class="px-4 cards_invitations">
<div class="container">
<div class="row">
<div class="col-12 col-md-6 col-lg-4 py-3 text-center border"><img class="img-fluid" font-family:lucida="" sans="" src="/images/contentimages/images/Accessories_Collage - Copy 2.png" />
<p class="my-3" style="font-size:18px;"> </p>
<div class="flex-container"><a class="btn btn-info btn-sm edatalayer order-1" data-list="product-listing-page" data-position="1" data-purl="custom-business-forms" href="https://www.example.com/">Accessories <i class="far fa-chevron-right pl-1"></i></a></div>
</div>
<div class="col-12 col-md-6 col-lg-4 py-3 text-center border"><img class="img-fluid" src="/images/contentimages/images/Activewear - Copy 1.png" />
<p class="my-3" style="font-size:18px;"> </p>
<div class="flex-container"><a class="btn btn-info btn-sm edatalayer order-1" data-list="product-listing-page" data-position="1" data-purl="custom-business-forms" href="https://www.example.com/">Active Wear <i class="far fa-chevron-right pl-1"></i></a></div>
</div>
<div class="col-12 col-md-6 col-lg-4 py-3 text-center border"><img class="img-fluid" font-family:lucida="" sans="" src="/images/contentimages/images/Bags_Backpacks_ - Copy 1.png" />
<p class="my-3" style="font-size:18px;"> </p>
<div class="flex-container"><a class="btn btn-info btn-sm edatalayer order-1" data-list="product-listing-page" data-position="1" data-purl="custom-business-forms" href="https://www.example.com/">Bags <i class="far fa-chevron-right pl-1"></i></a></div>
</div>
Remove the part in your CSS code where you write bottom: 4.5%
What this does is that it puts all elements with that class you made (btn), and puts them all on top of each other. When this happens, the browser doesn’t know where to redirect the user, which is why it was glitching a little as you have said. When you remove this, all the links should be working again.
Also this doesn’t really fix the problem you have, but at the end, you are missing 2 closing div tags and 1 closing section tag.
Full Correct Code:
<style type="text/css">
.btn {
background-color:transparent;
border-radius:28px;
border:1px solid #702F8A;
display:inline-block;
cursor:pointer;
color:#702F8A;
font-family:Tahoma;
font-size:14px;
padding:4px 13px;
text-decoration:none;
position: absolute;
}
.btn:hover {
background-color:#702F8A;
border-color:#702F8A;
}
.btn:active {
position:relative;
top:1px;
}
.flex-container {
display: flex;
justify-content: center;
}
</style>
<section class="px-4 cards_invitations">
<div class="container">
<div class="row">
<div class="col-12 col-md-6 col-lg-4 py-3 text-center border">
<img class="img-fluid" font-family:lucida="" sans="" src="/images/contentimages/images/Accessories_Collage - Copy 2.png" />
<p class="my-3" style="font-size:18px;"> </p>
<div class="flex-container"><a class="btn btn-info btn-sm edatalayer order-1" data-list="product-listing-page" data-position="1" data-purl="custom-business-forms" href="https://www.example.com/">Accessories <i class="far fa-chevron-right pl-1"></i></a></div>
</div>
<div class="col-12 col-md-6 col-lg-4 py-3 text-center border">
<img class="img-fluid" src="/images/contentimages/images/Activewear - Copy 1.png" />
<p class="my-3" style="font-size:18px;"> </p>
<div class="flex-container"><a class="btn btn-info btn-sm edatalayer order-1" data-list="product-listing-page" data-position="1" data-purl="custom-business-forms" href="https://www.example.com/">Active Wear <i class="far fa-chevron-right pl-1"></i></a></div>
</div>
<div class="col-12 col-md-6 col-lg-4 py-3 text-center border">
<img class="img-fluid" font-family:lucida="" sans="" src="/images/contentimages/images/Bags_Backpacks_ - Copy 1.png" />
<p class="my-3" style="font-size:18px;"> </p>
<div class="flex-container"><a class="btn btn-info btn-sm edatalayer order-1" data-list="product-listing-page" data-position="1" data-purl="custom-business-forms" href="https://www.example.com/">Bags <i class="far fa-chevron-right pl-1"></i></a></div>
</div>
</div>
</div>
</section>

how to set the html bootstrap buttons responsive in mobile

I am new here so apologies if anything wrong I mention.
I want to make my bootstrap buttons mobile responsive. but, I am new to CSS. i want to display my buttons and text in middle of screen for small devices after video.so please tell me how to do it.
Here is my HTML code:
<div class="row" style="margin-top: 5%">
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 ">
<p style="float: right; color: black;">I'm Ready to get my risk free <br /> membership today! <br /> (Limited Time and Quantities) </p>
</div>
</div>
<div class="row">
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 ">
<a href="#">
<button class="btn btn-theme btn-sm" style="background: white;color: #404040">
My Email Address
</button> </a>
<a href="#">
<button class="btn btn-theme btn-sm" style="background: #404040; border-radius: 10px; color: white">
Keep me on your email list
</button> </a>
<a href="#">
<button class="btn btn-theme btn-sm" style="background: yellow; border-radius: 10px; float: right; color: black">
Get My Risk <br /> Free Membership today
</button> </a>
</div>
</div>
Here is the code. Hope it will Help you. I have added some of classes into p and a tag. Even i put css for mobile view. If any changes please let me know.
#media screen and (max-width: 767px) {
.email-wrap {
display: block;
margin-bottom: 20px;
text-align: center;
}
.text-wrap {
text-align: center;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="main-wrapper">
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12">
<p class="text-wrap">I'm Ready to get my risk free <br /> membership today! <br />
(Limited Time and Quantities) </p>
</div>
</div>
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12">
<a href="#" class="email-wrap"><button class="btn btn-theme btn-sm" style="background: white;color: #404040">
My Email Address
</button> </a>
<a href="#" class="email-wrap"><button class="btn btn-theme btn-sm" style="background: #404040; border-radius: 10px; color: white">
Keep me on your email list
</button> </a>
<a href="#" class="email-wrap"><button class="btn btn-theme btn-sm" style="background: yellow; border-radius: 10px;color: black">
Get My Risk <br /> Free Membership today
</button> </a>
</div>
You can use media query for it or bootstrap 4 classes.
here is link for bootstrap class:
https://getbootstrap.com/docs/4.0/utilities/display/
#media (max-width: 575px){
p{
text-align: center;
float: unset !important;
}
a {
display: flex;
justify-content: center;
margin-bottom: 15px;
}
}
<div class="row" style="margin-top: 5%">
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 ">
<p style="float: right; color: black;">I'm Ready to get my risk free <br /> membership today! <br />
(Limited Time and Quantities) </p>
</div>
</div>
<div class="row">
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12">
<a href="#"><button class="btn btn-theme btn-sm" style="background: white;color: #404040">
My Email Address
</button> </a>
<a href="#"><button class="btn btn-theme btn-sm" style="background: #404040; border-radius: 10px; color: white">
Keep me on your email list
</button> </a>
<a href="#"><button class="btn btn-theme btn-sm" style="background: yellow; border-radius: 10px; float: right; color: black">
Get My Risk <br /> Free Membership today
</button> </a>
</div>
</div>

vertical aling in bootstrap

helllo evryone.
i have 4 divs that i want to be in one line in bootstrap but i have some problems with alignement, this picture shows the result:
It is looking like this now
the image is not in one line as other element and the text x cm is not in the center of its div
this my code
.flt{
float: left
}
.info-ingr{
background-color: #5bc0de;
margin-left: 40px;
height: 34px;
color: white;
}
.alginement{
height: 100px;
width: 100%;
background-color: #faa;
display: inline-block;
vertical-align: middle;
}
<div id="painchamp0" class="collapse">
<div class="row">
<div class="col-xs-10 col-sm-10 col-md-2 ">
<img src="https://thumbs.dreamstime.com/x/long-loaf-bread-22826883.jpg" class="img-responsive"><!--"img/pain-sandwich"-->
</div>
<div class="col-xs-3 col-sm-3 col-md-3 col-lg-3">
<select class="ste form-control" id="painList0">
<option>Select type de pain :</option>
<option>Pain complet</option>
<option>Pain aux céréales</option>
<option>Pain au seigle</option>
<option>Pain au levain</option>
<option>Pain aux épices</option>
<option>Pain aux figues</option>
</select>
</div>
<div class="col-xs-3 col-sm-3 col-md-1 col-lg-1" >
<input type="number" step="8" value="0" min="0" max="64" placeholder="largeur de pain :" id="painQuantite0" class="form-control flt">
</div >
<div class="col-xs-1 col-sm-1 col-md-1 col-lg-1 align-lg-middle alginement" >
x cm
</div>
<div class="col-xs-1 col-sm-1 col-md-1 col-lg-1">
<button id="painBTN0" type="button" class="btn btn-info btn-md flt">
ok
</button>
</div>
</div>
</div>
thank you
By default, text content having padding(10px) property..Just scrolldown to find that corresponding property line while you inspect it in the browser

Boostrap/CSS Responsive vertically centered

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

Vertical align a Row bootstrap Full Page

<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