<h1> followed by <div display: block> => no break line? - html

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>

Related

how to make button response in bootstrap

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>

How to align button left and right in the same line? [duplicate]

This question already has answers here:
Flexbox - Justify left and right on the same line
(4 answers)
CSS to keep two DIVs left and right?
(6 answers)
Left align and right align within div in Bootstrap
(7 answers)
Closed 1 year ago.
I want to display my previous button and next button sit on the same line, how do I fix it ? My button currently sit like this
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="col-md-12 text-left">
<button type="button" id="pre_button" class="btn btn-md btn-primary ml-2 button-icon rounded-small" data-toggle="tooltip" data-placement="top" title="previous">Previous</button>
</div>
<div class="col-md-12 text-right">
<button type="button" id="next_button" class="btn btn-md btn-primary ml-2 button-icon rounded-small" data-toggle="tooltip" data-placement="top" title="Next">Next</button>
</div>
Use float css rule
.f-l {
float: left;
}
.f-r {
float: right;
}
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.0/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-md-12 text-left f-l">
<button type="button" id="pre_button" class="btn btn-md btn-primary ml-2 button-icon rounded-small" data-toggle="tooltip" data-placement="top" title="previous" >Previous</button>
</div>
<div class="col-md-12 text-right f-r">
<button type="button" id="next_button" class="btn btn-md btn-primary ml-2 button-icon rounded-small" data-toggle="tooltip" data-placement="top" title="Next" >Next</button>
</div>

How to make an increment/decrement input inside dropdown?

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

Bootstrap 4 make nested row fill parent that has been made to fill viewport height using flex-grow

Currently, I am have a (class="d-flex flex-column") containing a navbar and a container and this container contains a (class="d-flex flex-column") as well that contains two rows. I use flex-grow to make my container fill the page. I wish to make the second row in this nested container to fill its parent using flex-grow again but it doesn't work. How do I make a nested element grow to fill a parent that has been made made to fill the viewport height using flex-grow in Bootstrap v4?
Should I not combine flex and container to do what I want? If so, how should I do this?
When I do the following, while the container expand to fill the height, the row within the container just stay the same height, it doesn't expand accordingly.
<div class="d-md-flex flex-column h-100">
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<button class="btn btn-outline-warning mr-auto" type="submit">Back</button>
<button class="btn btn-outline-success" type="submit">Logout</button>
</nav>
<div class="container-fluid flex-grow">
<div class="row">
<div class="col-md-9">
<div class="row">
<div class="col-md-12">
<div class="btn-toolbar justify-content-between" id="label-toolbar">
<div class="btn-group">
<select class="form-control form-control-sm" id="label-option">
<option>Main</option>
<option>Unknown</option>
</select>
<button type="button" class="btn btn-outline-primary btn-sm" id="create-button">Create</button>
<button type="button" class="btn btn-outline-primary btn-sm" id="delete-button">Delete</button>
<button type="button" class="btn btn-outline-primary btn-sm" id="edit-button">Edit</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-outline-success btn-sm" id="previous-button">Previous</button>
<button type="button" class="btn btn-outline-success btn-sm" id="next-button">Next</button>
</div>
</div>
<div id="draw-area"></div>
</div>
</div>
</div>
<div class="col-md-3 label-sidebar"></div>
</div>
</div>
</div>
Update
The following error occurs when using #ZimSystem code. How should I solve this?
I think you just need to remember that flex-grow applies to the child of display:flex, and not the parent. Therefore, if the parent is also a child flex-grow will work.
.flex-fill {
flex: 1 1 auto;
}
In your case, <div class="container-fluid flex-fill"></div> should also be d-flex so that you can use flex-grow to have it's children grow in height, and then continue this down to the drawing area.
https://codeply.com/go/gT3jsg43Lv
<div class="d-md-flex flex-column h-100">
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<button class="btn btn-outline-warning mr-auto" type="submit">Back</button>
<button class="btn btn-outline-success" type="submit">Logout</button>
</nav>
<div class="container-fluid d-flex h-100">
<div class="row flex-grow">
<div class="col-md-9">
<div class="row h-100">
<div class="col-md-12 d-flex flex-column flex-grow">
<div class="btn-toolbar justify-content-between" id="label-toolbar">
<div class="btn-group">
<select class="form-control form-control-sm" id="label-option">
<option>Main</option>
<option>Unknown</option>
</select>
<button type="button" class="btn btn-outline-primary btn-sm" id="create-button">Create</button>
<button type="button" class="btn btn-outline-primary btn-sm" id="delete-button">Delete</button>
<button type="button" class="btn btn-outline-primary btn-sm" id="edit-button">Edit</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-outline-success btn-sm" id="previous-button">Previous</button>
<button type="button" class="btn btn-outline-success btn-sm" id="next-button">Next</button>
</div>
</div>
<div id="draw-area" class="flex-grow bg-warning"> draw area </div>
</div>
</div>
</div>
<div class="col-md-3 label-sidebar"></div>
</div>
</div>
</div>
Note: The flex-fill utility class will be included in the next Bootstrap 4.1 release: https://github.com/twbs/bootstrap/commit/2137d61eacbd962ea41e16a492da8b1d1597d3d9
Here's another example with scrollable right column, and top navbar:
https://codeply.com/p/93751rK5WQ
Related
Bootstrap 4.0 - responsive header with image + navbar + full-height body
How to make the row stretch remaining height

How to wrap text inside bootstrap button without changing button size?

I'm trying to wrap or resize text inside bootstrap button without changing button size.I have couple buttons that must be aligned
I've used this class,text is wrap but button grows in size affecting the alignment with other buttons
.btn-wrap-text {
white-space: normal !important;
word-wrap: break-word !important;
}
There is sample code,just resize the view:
https://jsfiddle.net/mrapi/3yv314dx/1/
thanks
Not sure why all the complicated solutions.
Just add the following to your .btn css:
white-space: normal;
So, if you already have a .btn in your global css file, do this:
.btn {
white-space: normal;
}
Or if you do not have anything in your global css file, just do it inline, such as:
<button type="button" class="btn btn-primary" style="white-space: normal;">This is some button with text that should wrap</button>
Note: This method may not work on archaic versions of IE
Here you go with a solution https://jsfiddle.net/3yv314dx/3/
$('[data-toggle="tooltip"]').tooltip();
.btn-outline {
background-color: transparent;
color: inherit;
transition: all .5s;
}
.btn-wrap-text {
overflow: hidden;
white-space: nowrap;
display: inline-block;
text-overflow: ellipsis;
}
<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 class="container">
<div class="row">
<div class="col-sm-6">
<div class="col-sm-4 col-md-4">
<button class="btn btn-success btn-sm btn-block btn-outline">
ARTICLE
</button>
</div>
<div class="col-sm-4 col-md-4">
<button class="btn btn-success btn-sm btn-block btn-outline">
ARTICLE
</button>
</div>
<div class="col-sm-4 col-md-4">
<button class="btn btn-success btn-sm btn-block btn-outline">
ARTICLE WITH LONGER NAME
</button>
</div>
<div class="col-sm-4 col-md-4">
<button class="btn btn-success btn-sm btn-block btn-outline">
ARTICLE
</button>
</div>
<div class="col-sm-4 col-md-4">
<button class="btn btn-success btn-sm btn-block btn-outline">
ARTICLE
</button>
</div>
<div class="col-sm-4 col-md-4">
<button class="btn btn-success btn-sm btn-block btn-outline">
ARTICLE
</button>
</div>
<div class="col-sm-4 col-md-4">
<button class="btn btn-success btn-sm btn-block btn-outline">
ARTICLE WITH LONGER NAME
</button>
</div>
<div class="col-sm-4 col-md-4">
<button class="btn btn-success btn-sm btn-block btn-outline btn-wrap-text" data-toggle="tooltip" title="ARTICLE WITH LONGER NAME">
ARTICLE WITH LONGER NAME
</button>
</div>
<div class="col-sm-4 col-md-4">
<button class="btn btn-success btn-sm btn-block btn-outline">
ARTICLE
</button>
</div>
<div class="col-sm-4 col-md-4">
<button class="btn btn-success btn-sm btn-block btn-outline">
ARTICLE
</button>
</div>
<div class="col-sm-4 col-md-4">
<button class="btn btn-success btn-sm btn-block btn-outline">
ARTICLE
</button>
</div>
<div class="col-sm-4 col-md-4">
<button class="btn btn-success btn-sm btn-block btn-outline">
ARTICLE
</button>
</div>
<div class="col-sm-4 col-md-4">
<button class="btn btn-success btn-sm btn-block btn-outline">
ARTICLE
</button>
</div>
</div>
</div>
</div>
Here in the solution, I've used ellipse to truncate extra characters & to show entire text used tooltip
You can change the font size. If you dont want to change the font size use the below code
.btn-wrap-text {
overflow: hidden;
white-space: nowrap;
display: inline-block;
text-overflow: ellipsis;
}