Bootstrap, center buttons in row - css

I have the problem with center all button in each col-md-4:
<div class="row position-relative mt-2">
<div class="col-md-4 center-block">
<div class="center-block align-to-bottom">
<div class="btn-group-vertical">
<p>
<button class="btn btn-info btn-sm btn-block" type="button">
button
</button>
</p>
<p>
<button class="btn btn-warning btn-sm btn-block" type="button">
button
</button>
</p>
</div>
</div>
</div>
<div class="col-md-4 center-block">
<div class="btn-group-vertical">
<p>
<button class="btn btn-info btn-sm btn-block" type="button">
button
</button>
</p>
<p>
<button class="btn btn-info btn-sm btn-block" type="button">
button
</button>
</p>
<p>
<button class="btn btn-warning btn-sm btn-block" type="button">
button
</button>
</p>
</div>
</div>
<div class="col-md-4 center-block">
<p>
<button class="btn btn-success btn-sm btn-block" type="button">
button
</button>
</p>
</div>
</div>
Also second question -> I uses also w-100, h-85... But it is no working. I am also looking for solution to set up relative size of buttons.

To horizontally align a button you can just add the class text-center to your parent column.
I also removed the p tags and instead added the margin to the button itself with the class mb-2
I did remove a lot of your classes too as they didn't seem to be Bootstrap 4 classes. If these are needed just add them back where you think neccessary.
Also rather than making your button a block which gives it the full width of your parent, I just added another row and put each button in its own full width column which will act as the block.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row mt-2">
<div class="col-md-4 text-center">
<div class="row">
<div class="col-12 mb-2">
<button class="btn btn-info btn-sm" type="button">
Button
</button>
</div>
<div class="col-12 mb-2">
<button class="btn btn-warning btn-sm" type="button">
Button
</button>
</div>
<div class="col-12 mb-2">
<button class="btn btn-warning btn-sm" type="button">
Button
</button>
</div>
</div>
</div>
<div class="col-md-4 text-center">
<div class="row">
<div class="col-12 mb-2">
<button class="btn btn-info btn-sm" type="button">
Button
</button>
</div>
<div class="col-12 mb-2">
<button class="btn btn-info btn-sm" type="button">
Button
</button>
</div>
<div class="col-12 mb-2">
<button class="btn btn-warning btn-sm" type="button">
Button
</button>
</div>
</div>
</div>
<div class="col-md-4 text-center">
<button class="btn btn-success btn-sm" type="button">
Button
</button>
</div>
</div>
I hope this solves your issues, let me know if it's not quite what you were looking for.

Related

Modal content don't show in dropdown

I'm calling Bootstrap 5 modal from dropdown but instead of showing content it shows only grey background. What I'm missing?
Here is jsfiddle and here is code:
<div class="container">
<div class="row">
<div class="inline-block">
<div class="dropdown">
<button type="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="true" class="btn btn-primary">Dropdown</button>
<ul class="dropdown-menu dropdown-menu-end">
<li>
<button type="button" class="dropdown-item" data-bs-toggle="modal" data-bs-target="#test">
Launch demo modal
</button>
<div class="modal fade" id="test" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
The modal code should be outside the <ul> tag
<div class="container">
<div class="row">
<div class="inline-block">
<div class="dropdown">
<button type="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="true" class="btn btn-primary">Dropdown</button>
<ul class="dropdown-menu dropdown-menu-end">
<li>
<button type="button" class="dropdown-item" data-bs-toggle="modal" data-bs-target="#test">
Launch demo modal
</button>
</li>
</ul>
</div>
</div>
</div>
<div class="modal fade" id="test" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>

Bootstrap button groups with separators

How to get Bootstrap button groups with a border line separator between each button?
<div class="btn-group" role="group" aria-label="Button group with nested dropdown">
<button type="button" class="btn btn-secondary">1</button>
<button type="button" class="btn btn-secondary">2</button>
</div>
https://getbootstrap.com/docs/4.6/components/button-group
The #padaleiana solution is working fine! I used a btn-light disabled button as separator.
Workaround:
Create a button with mr-0, ml-0, pl-0 and pr-0 classes (margin and padding left and right = 0), and with disabled attribute (otherwise the "separator" will not appear!)
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="btn-group" role="group" aria-label="Button group with nested dropdown">
<button type="button" class="btn btn-secondary">1</button>
<button type="button" class="btn btn-secondary mr-0 ml-0 pr-0 pl-0" disabled></button>
<button type="button" class="btn btn-secondary">2</button>
<button type="button" class="btn btn-secondary mr-0 ml-0 pr-0 pl-0" disabled></button>
<button type="button" class="btn btn-secondary">3</button>
</div>
An alternative to padaleiana's answer is the following, which is not using HTML button tags. Thus, it avoids problems, when jQuery (or other Javascripts) iterates buttons:
<div class="alert alert-dark m-0 px-0"></div>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="btn-group" role="group" aria-label="Button group with nested dropdown">
<button type="button" class="btn btn-secondary">1</button>
<div class="alert alert-dark m-0 px-0"></div>
<button type="button" class="btn btn-secondary">2</button>
<div class="alert alert-dark m-0 px-0"></div>
<button type="button" class="btn btn-secondary">3</button>
</div>

Clickable element in div with shadow: inset

I would like to have clickable/focusable elements in a div, which has an inset shadow (the .calendar in this example): https://jsfiddle.net/axel50397/846ostv5/9/
<div class="calendar">
<div class="card-deck p-2 w-100">
<div class="card mx-2">
<div class="card-header">
2020-04-01
</div>
<div class="card-body">
<button type="button" class="btn btn-sm btn-primary btn-block">09:00</button>
<button type="button" class="btn btn-sm btn-primary btn-block">10:00</button>
<button type="button" class="btn btn-sm btn-primary btn-block">11:00</button>
<button type="button" class="btn btn-sm btn-primary btn-block">12:00</button>
<button type="button" class="btn btn-sm btn-primary btn-block">13:00</button>
<button type="button" class="btn btn-sm btn-primary btn-block">14:00</button>
<button type="button" class="btn btn-sm btn-primary btn-block">15:00</button>
</div>
</div>
</div>
</div>
Based on my small CSS experience, it seems impossible because the .calendar must be above its content… If it's not possible in CSS, I'm open to suggestions if any.
Remove below CSS, you added. Now it is clickable and focusable buttons.
.calendar .card {
z-index: -1;
}
https://jsfiddle.net/Lqv4fkjy/

Increase Bootstrap 4 label width in modal the right way

I am trying to increase the width of the label in a form within a Boostrap modal. It has a max-width of max-width: 16.66667%;. Is there a better way or class I should set this up with? As you can see the label is being overwritten and there is plenty of space to the right. I'd rather use Bootstrap classes then my own custom ones if possible.
<form class="game-score-modal" novalidate="novalidate" action="#Url.Action(Model.Score.UpdateGameUrl)" data-bind="submit: save, with: score">
.
.
.
<div class="form-row">
<label for="EnableSubscription">Communication</label>
<div class="col-auto">
<button type="button" class="btn btn-check active" data-toggle="buttons-checkbox" title="Send Email/Text"><i class="fa fa-comment"></i> </button><input checked="checked" data-bind="value: EnableSubscription,disable: EnableSubscription() == null ? true : false, checkbox: { checked: true, iconClass: 'fa fa-comment'}" id="EnableSubscription" name="EnableSubscription" title="Send Email/Text" type="checkbox" value="true"><input name="EnableSubscription" type="hidden" value="false">
<button type="button" class="btn btn-check active" data-toggle="buttons-checkbox" title="Post To Twitter"><i class="fab fa-twitter"></i> </button><input checked="checked" data-bind="value: EnableTwitter,disable: EnableTwitter() == null ? true : false, checkbox: { checked: true, iconClass: 'fab fa-twitter'}" id="EnableTwitter" name="EnableTwitter" title="Post To Twitter" type="checkbox" value="true"><input name="EnableTwitter" type="hidden" value="false">
<button type="button" class="btn btn-check active" data-toggle="buttons-checkbox" title="Post To Facebook"><i class="fab fa-facebook"></i> </button><input checked="checked" data-bind="value: EnableFacebook,disable: EnableFacebook() == null ? true : false, checkbox: { checked: true, iconClass: 'fab fa-facebook'}" id="EnableFacebook" name="EnableFacebook" title="Post To Facebook" type="checkbox" value="true"><input name="EnableFacebook" type="hidden" value="false">
</div>
</div>
<button type="submit" class="btn btn-primary"><i class="fa fa-check"></i> Save</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal"><i class="fa fa-ban"></i> Cancel</button>
</div>
</form>
Treat the form as it was your bootstrap grid using column classes.
Switch from .row to .form-row when you want your gutters to be compact.
Also if your modal is purely a form then replace the div.modal-content with form.modal-content and utilise bootstraps modal classes.
For example...
$('#updateScore').modal('show');
<div class="modal" tabindex="-1" role="dialog" id="updateScore">
<div class="modal-dialog" role="document">
<form class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Update Score</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<i class="fa fa-times"></i>
</button>
</div>
<div class="modal-body">
<div class="form-group row">
<label class="col-form-label col-sm-4 col-12 text-sm-right">Team 1</label>
<div class="col-sm-8 col-12">
<div class="form-row">
<div class="form-group col-sm-3 col-4">
<input type="number" class="form-control" />
</div>
<div class="form-group col-sm-6 col-8">
<div class="input-group">
<div class="input-group-prepend">
<label class="input-group-text">
Won By
</label>
</div>
<select class="custom-select">
<option selected>-</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-12">
<button type="button" class="btn btn-secondary">
<i class="fa fa-check"></i> Pool Play
</button>
<button type="button" class="btn btn-info">
<i class="fa fa-fw fa-info"></i>
</button>
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-circle-thin"></i>
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Option</a>
<a class="dropdown-item" href="#">Option</a>
</div>
</div>
</div>
</div>
</div>
</div>
<hr />
<div class="form-group row">
<label class="col-form-label col-sm-4 col-12 text-sm-right">Team 2</label>
<div class="col-sm-8 col-12">
<div class="form-row">
<div class="form-group col-sm-3 col-4">
<input type="number" class="form-control" />
</div>
<div class="form-group col-sm-6 col-8">
<div class="input-group">
<div class="input-group-prepend">
<label class="input-group-text">
Won By
</label>
</div>
<select class="custom-select">
<option selected>-</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-12">
<button type="button" class="btn btn-secondary">
<i class="fa fa-check"></i> Pool Play
</button>
<button type="button" class="btn btn-info">
<i class="fa fa-fw fa-info"></i>
</button>
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-circle-thin"></i>
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Option</a>
<a class="dropdown-item" href="#">Option</a>
</div>
</div>
</div>
</div>
</div>
</div>
<hr />
<div class="form-group row">
<label class="col-form-label col-sm-4 col-12 text-sm-right">Notes</label>
<div class="col-sm-8 col-12">
<input type="text" class="form-control" />
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-sm-4 col-12 text-sm-right">Uploads</label>
<div class="col-sm-8 col-12">
<div class="custom-file">
<input type="file" class="custom-file-input" id="uploads" required>
<label class="custom-file-label" for="uploads">Choose file...</label>
</div>
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-sm-4 col-12 text-sm-right">Communication</label>
<div class="col-sm-8 col-12">
<button type="button" class="btn btn-primary">
<i class="fa fa-fw fa-comment"></i>
</button>
<button type="button" class="btn btn-primary">
<i class="fa fa-fw fa-twitter"></i>
</button>
<button type="button" class="btn btn-primary">
<i class="fa fa-fw fa-facebook"></i>
</button>
<input type="hidden" value="false" />
<input type="hidden" value="false" />
<input type="hidden" value="false" />
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">
<i class="fa fa-ban"></i> Cancel
</button>
<button type="submit" class="btn btn-primary">
<i class="fa fa-check"></i> Save
</button>
</div>
</form>
</div>
</div>
<div class="container mt-3">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#updateScore">
Launch demo modal
</button>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet"/>

Collapse multiple data targets using Bootstrap

I have three buttons that expand/collapse three divs, using Bootstrap. However, if I click on two different buttons in succession I get two divs expanded one after the other. Is it possible that before one div is expanded all others are collapsed so that only one div at a time can be visible?
Right now, if I had clicked on button 1 to expand Div1, I have to click on the button 1 again to collapse Div1 before I can click on button 2; otherwise contents of Div1 and Div2 both are displayed.
This is what I have:
<div class="btn-group btn-group-justified">
<div class="col-sm-6 col-md-4 col-lg-4">
<button class="btn btn-lg open-group" type="button" data-toggle="collapse" data-target="#Div1" aria-expanded="false" aria-controls="Div1">Div1 Button<span class="caret"></span>
</button>
</div>
<div class="col-sm-6 col-md-4 col-lg-4">
<button class="btn btn-lg open-group" type="button" data-toggle="collapse" data-target="#Div2" aria-expanded="false" aria-controls="Div2">Div2 Button<span class="caret"></span>
</button>
</div>
<div class="col-sm-6 col-md-4 col-lg-4">
<button class="btn btn-lg open-group" type="button" data-toggle="collapse" data-target="#Div3" aria-expanded="false" aria-controls="Div3">Div3 Button<span class="caret"></span>
</button>
</div>
</div>
<div class="collapse" id="Div1">Content of Div1 here </div>
<div class="collapse" id="Div2">Content of Div2 here </div>
<div class="collapse" id="Div3">Content of Div3 here </div>
So you need to set a parent using data-parent="#parentdiv" to the toggle then have the class panel to contain all toggleddivs.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div id="parentdiv"class="btn-group btn-group-justified">
<div class="panel">
<div class="col-sm-6 col-md-4 col-lg-4">
<button class="btn btn-lg open-group" type="button" data-parent="#parentdiv" data-toggle="collapse" data-target="#Div1" aria-expanded="false" aria-controls="Div1">Div1 Button<span class="caret"></span>
</button>
</div>
<div class="col-sm-6 col-md-4 col-lg-4">
<button class="btn btn-lg open-group" type="button" data-parent="#parentdiv" data-toggle="collapse" data-target="#Div2" aria-expanded="false" aria-controls="Div2">Div2 Button<span class="caret"></span>
</button>
</div>
<div class="col-sm-6 col-md-4 col-lg-4">
<button class="btn btn-lg open-group"data-parent="#parentdiv" type="button" data-toggle="collapse" data-target="#Div3" aria-expanded="false" aria-controls="Div3">Div3 Button<span class="caret"></span>
</button>
</div>
<div class="collapse" id="Div1">Content of Div1 here </div>
<div class="collapse" id="Div2">Content of Div2 here </div>
<div class="collapse" id="Div3">Content of Div3 here </div>
</div>
</div>

Resources