I have a row of buttons in the bootstrap HTML website when I open it in desktop view it works perfectly, but in mobile view, it is a mess.
here is my code :
<div class="creative ">
<div class="container" style=" padding-top: 50px">
<div class="card mt-3" style=" background-color: rgba(255,255,255,.6);">
<div class="mt-1 card-body" id="artical">
{# <h4>El Gouna</h4>#}
<a class="btn btn-primary warn" href="#about">
<span>Divecenter</span>
</a>
<a class="btn btn-primary warn" href="#about">
<span>Hotels</span>
</a>
<a class="btn btn-primary warn" href="{% url 'price_list' %}">
<span>Price & Booking</span>
</a>
<a class="btn btn-primary warn" href="#contact">
<span>Book Hotel</span>
............
You can use block buttons on small devices and use flexbox on larger screens like this.
.wrap {
border: 1px solid black;
max-width: 500px;
padding: 10px;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="wrap d-grid gap-2 d-md-flex">
<button class="btn btn-primary flex-md-fill">
Button
</button>
<button class="btn btn-primary flex-md-fill">
Button
</button>
<button class="btn btn-primary flex-md-fill">
Button
</button>
</div>
Related
I have 3 divs, I want to align "div2" to the center of the page and "div3" at the end while being in the same row.
I've been trying some things like the "d-flex justify-content-center" that I'm currently using or making "div1" a row and giving "div3" the class "ml-auto" but then I don't know how to align "div1" to the center.
I'm using Bootstrap 5.
My actual result
<div class="text-center mt-2" id="div1">
<div class="d-flex justify-content-center" id="div2">
<a class="btn btn-lg btn-success" href="#"> Link 1 </a>
</div>
<div class="d-flex justify-content-end" id="div3">
<a class="btn btn-lg btn-info" href="#"> Link 2 </a>
<a class="btn btn-lg btn-info" href="#"> Link 3 </a>
</div>
</div>
One way is to use nested flexbox items. For this you'll need an empty spacer for the left, and each child item needs flex: 1:
.flex1 {
flex: 1;
}
<div class="text-center mt-2 d-flex w-100" id="div1">
<div class="d-flex flex1"><!--spacer --></div>
<div class="d-flex flex1 justify-content-center" id="div2">
<a class="btn btn-lg btn-success" href="#"> Link 1 </a>
</div>
<div class="d-flex flex1 justify-content-end" id="div3">
<a class="btn btn-lg btn-info" href="#"> Link 2 </a>
<a class="btn btn-lg btn-info" href="#"> Link 3 </a>
</div>
</div>
dead center using flexbox nesting
Another way is to use absolute position:
<div class="text-center mt-2 d-flex justify-content-center" id="div1">
<div class="d-flex" id="div2">
<a class="btn btn-lg btn-success" href="#"> Link 1 </a>
</div>
<div class="ms-auto position-absolute end-0" id="div3">
<a class="btn btn-lg btn-info" href="#"> Link 2 </a>
<a class="btn btn-lg btn-info" href="#"> Link 3 </a>
</div>
</div>
dead center using absolute position
Read more: aligning flexbox items is explained here
This solution should help you:
div2 is in the center of the row
div3 is at the end of the row
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="d-flex justify-content-end" id="div1">
<div id="div2" class="position-absolute" style="left:50%;width:100px;margin-left:-50px">
<a class="btn btn-lg btn-success" href="#"> Link 1 </a>
</div>
<div id="div3">
<a class="btn btn-lg btn-info" href="#"> Link 2 </a>
<a class="btn btn-lg btn-info" href="#"> Link 3 </a>
</div>
</div>
I'm removing most <br> from my HTML and trying to replace it with CSS. I've tried several techniques but none on them worked for me, what am I doing wrong ?
Using Bootstrap 4, I've try adding the class d-block to my elements (h1 and the following div),
I've tried adding margin/padding bottom with CSS,
or, as in Bootstrap documentation, embed it into <span> and add the same classes (d-block p-2)
I've also tried adding CSS to <h1>, such as :
.h1 {
width: 100%;
display: block;
padding-bottom: 10px;
}
.h1::after {
content: '\A';
white-space: pre;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<h1 class="d-block">Portfolio</h1>
<!-- Mosaic buttons -->
<div class="d-block">
<button class="btn btn-outline-light filter-button mr-2" data-filter="all">ALL</button>
<button class="btn btn-outline-light filter-button mr-2" data-filter="demo">SOUND DESIGN</button>
<button class="btn btn-outline-light filter-button mr-2" data-filter="album">MUSIC</button>
<button class="btn btn-outline-light filter-button mr-2" data-filter="samplepack">SAMPLEPACKS</button>
</div>
On StackOverflow, the snippet works fine, but here's the result I've locally (can't manage to reproduce it here)
I'm expecting the buttons to sit under the <h1> tag (instead of on its right)
Here's the website before I remove all the (slow and bugged) : https://staging-det-music.herokuapp.com/
If anyone is interested, the git repo: https://gitlab.com/kawsay/det
What am I missing ? Any help would be gratefully received !
if you want to display buttons in column
<div class="d-flex flex-column">
<h1>Portfolio</h1>
<button class="btn btn-outline-light filter-button mr-2" data-filter="all">ALL</button>
<button class="btn btn-outline-light filter-button mr-2" data-filter="demo">SOUND DESIGN</button>
<button class="btn btn-outline-light filter-button mr-2" data-filter="album">MUSIC</button>
<button class="btn btn-outline-light filter-button mr-2" data-filter="samplepack">SAMPLEPACKS</button>
</div>
if you want to display buttons next to each other
<div class="d-flex flex-column">
<h1>Portfolio</h1>
<div class="d-flex flex-row">
<button class="btn btn-outline-light filter-button mr-2" data-filter="all">ALL</button>
<button class="btn btn-outline-light filter-button mr-2" data-filter="demo">SOUND DESIGN</button>
<button class="btn btn-outline-light filter-button mr-2" data-filter="album">MUSIC</button>
<button class="btn btn-outline-light filter-button mr-2" data-filter="samplepack">SAMPLEPACKS</button>
</div>
So my goal is to make an dropdown with decrement/increment button like below.
https://imgur.com/A4zleSX
and these are my current codes
<div class="dropdown">
<button class="btn border-0 dropdown-toggle form-control" type="button"
id="dropdownMenu2" data-toggle="dropdown" aria-expanded="false">
Dropdown</button>
<div class="dropdown-menu" style="width: 250px; background-color: #343a40"
aria-labelledby="dropdownMenu2">
<div class="dropdown-item">
<div class="row text-white">
<div class="col-md">
<i class="fa fa-user mr-2"></i>Adult</div>
<div class="col-md text-center">
<button class="btn btn-sm btn-success mx-2">+</button>
<span>1</span>
<button class="btn btn-sm btn-success mx-2">+</button>
</div>
</div>
</div>
</div>
So i've managed to make till this point, but i have problems when the button is clicked inside the dropdown, it scrolls to page the top and i also don't like the background color changes when the dropdown item is hovered.
please help me to make it happen, thank you
UPDATE:
so all left is preventing the page to scroll when the button inside dropdown is clicked, can anyone help please?
Firstly you need to keep on dropdown when user click anything in it.
JS:
$('.keep-open').on({
"shown.bs.dropdown": function() { $(this).attr('closable', false); },
"click": function() { },
"hide.bs.dropdown": function() { return $(this).attr('closable') == 'true'; }
});
$('.keep-open #dLabel').on({
"click": function() {
$(this).parent().attr('closable', true );
}
})
html:
<div class="dropdown-menu" role="menu" aria-labelledby="dLabel" style="width: 250px; background-color: #343a40" >
<div style="display: block;text-align:center;margin-bottom:5px;margin-top:5px">
<div style="display: inline-block;color:white">
<i class="fa fa-user mr-2" style="margin:15px;"></i>Adult</div>
<button class="btn btn-sm btn-success mx-2">-</button>
<span>1</span>
<button class="btn btn-sm btn-success mx-2">+</button>
</div>
<div style="display: block;text-align:center;margin-bottom:5px;">
<div style="display: inline-block;color:white;">
<i class="fa fa-user mr-2" style="color:white;margin:15px;"></i>Child</div>
<button class="btn btn-sm btn-success mx-2">-</button>
<span>1</span>
<button class="btn btn-sm btn-success mx-2">+</button>
</div>
</div>
plunker: http://plnkr.co/edit/s4nmZVXpLMzZLDSzVd24?p=preview
I've been doing this for hours trying all the ways and I can't get these buttons to move.
I'm not sure how to override the CSS to do any margin tricks.
All I need is for everything in the jumbotron, text and button group, to be perfectly center.
<template name="Jumbotron">
<div class="jumbotron center">
<h1>Hello, world!</h1>
<p>Get Started Now</p>
<div class="btn-toolbar">
<a class="btn btn-primary btn-lg" href="#" role="button">Learn more</a>
<a class="btn btn-primary btn-lg" href="#" role="button">Learn more</a>
</div>
</div>
</template>
Change the display property to inline-block for the btn-toolbar class.
See Example Snippets.
.btn-toolbar.meteor-btn-toolbar,
.btn-toolbar.meteor-btn-toolbar2 {
display: inline-block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="jumbotron text-center">
<h1>Hello, world!</h1>
<p>Get Started Now</p>
<div class="btn-toolbar meteor-btn-toolbar" role="toolbar" aria-label="...">
<div class="btn-group" role="group" aria-label="..."> <a role="button" class="btn btn-primary btn-lg">Learn More</a>
<a role="button" class="btn btn-primary btn-lg">Learn More</a>
</div>
</div>
</div>
<hr>
<div class="jumbotron text-center">
<h1>Hello, world!</h1>
<p>Get Started Now</p>
<div class="btn-toolbar meteor-btn-toolbar2"> <a class="btn btn-primary btn-lg" href="#" role="button">Learn more</a>
<a class="btn btn-primary btn-lg" href="#" role="button">Learn more</a>
</div>
</div>
This is my product template file.
<br>
<div>
<div ng-if="SearchText.length<3" ng-repeat="product in pc.ProductService.Products | filter:FilterExpr:true |orderBy:['SubCategoryName','BrandName'] | groupBy:['BrandName']" >
<h2 ng-show="product.group_by_CHANGED">{{product.BrandName}} </h2>
<div class='box'>
<ng-include src="'commonTemplate.html'"></ng-include>
</div>
</div>
<!-- template (common piece of code) -->
<script type="text/ng-template" id="commonTemplate.html">
<div class="BrandName"> <b>{{product.BrandName}}</b> </div>
<div class="ProductName"> {{product.ProductName}} </div>
<br>
<div> <img src="http://localhost/{{ product.ProductImagePath }}" alt="" border=3 height=75 width=75></img> </div>
<div class="ProductVariants">
<select class="form-control btn btn-default btn-xs text-center" ng-init="SelectedVariant = product.Variants[0]" ng-model="SelectedVariant" ng-options="variant.VariantName for variant in product.Variants" ng-change="ChangeVariant(product.ProductID, SelectedVariant.VariantID)"></select>
</div>
<div class="Price">
<strike> {{SelectedVariant.MRP}} </strike> {{SelectedVariant.SellPrice}}
</div>
<div class="AddToCart" ng-if="SelectedVariant.InCart==0">
<a class="btn btn-success btn-sm" ng-click="pc.AddToCart(product.ProductID, SelectedVariant.VariantID)">Add to Cart
<span class="glyphicon glyphicon-plus"></span>
</a>
</div>
<div class="AddToCart" ng-if="SelectedVariant.InCart>0">
<a class="btn btn-default btn-xs" ng-click="pc.PlusItem(product.ProductID, SelectedVariant.VariantID)">
<span class="glyphicon glyphicon-plus"></span>
</a>
<button type="button" class="btn btn-sm btn-info disabled">{{SelectedVariant.InCart}} in cart</button>
<a class="btn btn-default btn-xs" ng-click="pc.MinusItem(product.ProductID, SelectedVariant.VariantID)">
<span class="glyphicon glyphicon-minus"></span>
</a>
</div>
</script>
</div>
Box class is defined like this in CSS:
.box {
margin : 5px;
display : inline-block;
width: 170px;
height: 275px;
background-color: #F5FBEF;
text-align:center;
vertical-align: top;
}
When display my product list look like this:
I want to show products side by side.
Can some one help me how to do that?
EDIT:
After changes suggested by Rachel Gallen, it turn out like this:
I want to display brand name in new line when new brand encounters. rest all looks good.
I put in .ng-repeat:display:inline plus a wrapper
#wrapper {
display: inline!important;
height: 275px;
max-width: 540px;
}
.box {
margin: 5px;
display: inline-block;
width: 170px;
height: 275px!important;
background-color: #F5FBEF;
text-align: center;
float: left;
}
.ng-repeat {
display: inline-block;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div>
<div ng-if="SearchText.length<3" ng-repeat="product in pc.ProductService.Products | filter:FilterExpr:true |orderBy:['SubCategoryName','BrandName'] | groupBy:['BrandName']">
<h2 ng-show="product.group_by_CHANGED">{{product.BrandName}} </h2>
<div id=wrapper>
<div class='box'>
<div class="BrandName"> <b>{{product.BrandName}}</b>
</div>
<div class="ProductName">{{product.ProductName}}</div>
<br>
<div>
<img src="http://localhost/{{ product.ProductImagePath }}" alt="" border=3 height=75 width=75></img>
</div>
<div class="ProductVariants">
<select class="form-control btn btn-default btn-xs text-center" ng-init="SelectedVariant = product.Variants[0]" ng-model="SelectedVariant" ng-options="variant.VariantName for variant in product.Variants" ng-change="ChangeVariant(product.ProductID, SelectedVariant.VariantID)"></select>
</div>
<div class="Price">
<strike> {{SelectedVariant.MRP}} </strike> {{SelectedVariant.SellPrice}}
</div>
<div class="AddToCart" ng-if="SelectedVariant.InCart==0">
<a class="btn btn-success btn-sm" ng-click="pc.AddToCart(product.ProductID, SelectedVariant.VariantID)">Add to Cart
<span class="glyphicon glyphicon-plus"></span>
</a>
</div>
<div class="AddToCart" ng-if="SelectedVariant.InCart>0">
<a class="btn btn-default btn-xs" ng-click="pc.PlusItem(product.ProductID, SelectedVariant.VariantID)">
<span class="glyphicon glyphicon-plus"></span>
</a>
<button type="button" class="btn btn-sm btn-info disabled">{{SelectedVariant.InCart}} in cart</button>
<a class="btn btn-default btn-xs" ng-click="pc.MinusItem(product.ProductID, SelectedVariant.VariantID)">
<span class="glyphicon glyphicon-minus"></span>
</a>
</div>
</div>
<div class='box'>
<div class="BrandName"> <b>{{product.BrandName}}</b>
</div>
<div class="ProductName">{{product.ProductName}}</div>
<br>
<div>
<img src="http://localhost/{{ product.ProductImagePath }}" alt="" border=3 height=75 width=75></img>
</div>
<div class="ProductVariants">
<select class="form-control btn btn-default btn-xs text-center" ng-init="SelectedVariant = product.Variants[0]" ng-model="SelectedVariant" ng-options="variant.VariantName for variant in product.Variants" ng-change="ChangeVariant(product.ProductID, SelectedVariant.VariantID)"></select>
</div>
<div class="Price">
<strike> {{SelectedVariant.MRP}} </strike> {{SelectedVariant.SellPrice}}
</div>
<div class="AddToCart" ng-if="SelectedVariant.InCart==0">
<a class="btn btn-success btn-sm" ng-click="pc.AddToCart(product.ProductID, SelectedVariant.VariantID)">Add to Cart
<span class="glyphicon glyphicon-plus"></span>
</a>
</div>
<div class="AddToCart" ng-if="SelectedVariant.InCart>0">
<a class="btn btn-default btn-xs" ng-click="pc.PlusItem(product.ProductID, SelectedVariant.VariantID)">
<span class="glyphicon glyphicon-plus"></span>
</a>
<button type="button" class="btn btn-sm btn-info disabled">{{SelectedVariant.InCart}} in cart</button>
<a class="btn btn-default btn-xs" ng-click="pc.MinusItem(product.ProductID, SelectedVariant.VariantID)">
<span class="glyphicon glyphicon-minus"></span>
</a>
</div>
</div>
</div>
</div>
</body>
</html>
Add property float:left to box class. If that doesn't work, please provide a demo.
Jsfiddle: http://jsfiddle.net/z9jbhmd4/
You can add float in your css:
.box {
margin : 5px;
display : inline-block;
width: 170px;
height: 275px;
background-color: #F5FBEF;
text-align:center;
vertical-align: top;
float: left;
}
And to keep the height of the container, move <div class="box">...</div> inside container like <div class="box-container">.....</div>
Then, add css:
.box-container:after {
content: " ";
display: block;
height: 0;
clear: both;
}