Full Width Split Dropdown Button in Twitter Bootstrap - html

I have a place on my site which is using a bunch of button elements styled with btn-block (example from the Twitter Bootstrap Docs). I now want to switch some of them to split buttons (example), but I can't seem to get the split buttons and the normal buttons to be the same length.
I have experimented with all kinds of things, but I can't seem to find a way to do this. Has anyone ever managed to do it? Keep in mind that I do not want to hard-code the width of any elements if I don't have to. (Note that this includes not using hard-coded percentages either.) If it is absolutely necessary, I am OK with defining a width for the toggle part of the button (because I know there will only be a single arrow character in there) but want to specify as few "magic numbers" as possible in order to keep the code maintainable in the future.

Wrap the dropdown-lead in a container:
(Note: This example is for Bootstrap 2.x)
.dropdown-lead {
width: 100%;
}
.leadcontainer {
left: 0;
position: absolute;
right: 30px;
}
.dropdown-toggle {
width: 30px;
float: right;
box-sizing: border-box;
}
.fillsplit {
position: relative;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/2.3.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/2.3.2/js/bootstrap.min.js"></script>
<button class="btn btn-block btn-primary" type="button">Block level button</button>
<div class="btn-group btn-block fillsplit">
<div class="leadcontainer">
<a class="btn btn-primary dropdown-lead" href="#"><i class="icon-user icon-white"></i> User</a>
</div>
<a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#"><span class="caret"></span></a>
<ul class="dropdown-menu">
<li><i class="icon-pencil"></i> Edit
</li>
<li><i class="icon-trash"></i> Delete
</li>
<li><i class="icon-ban-circle"></i> Ban
</li>
<li class="divider"></li>
<li><i class="i"></i> Make admin
</li>
</ul>
<div>
</div>

I was looking for the same kind of behavior and found this flexbox solution: http://codepen.io/ibanez182/pen/MwZwJp
It's an elegant implementation which makes use of the flex-grow property.
Just add the .btn-flex class to the .btn-group in your HTML. This is all the CSS you need:
.btn-flex {
display: flex;
align-items: stretch;
align-content: stretch;
}
.btn-flex .btn:first-child {
flex-grow: 1;
}
Credit goes to the author of the pen: Nicola Pressi

If you add the class btn-block to the .btn-group element and give the dropdownbutton elements % widths, that'd do the trick.
.dropdown-lead{
width: 96%;
box-sizing: border-box;
}
.dropdown-toggle{
width: 4%;
box-sizing: border-box;
}
Here's an example: http://jsfiddle.net/eBJGW/5/

Related

Inlined icons in a button arent centered when i change the width and height of the button to small numbers

I have buttons which follow the following structure:
<button type="button" class="btn btn-dark btn-sm"(click)="doSomething()">
<i class="fa fa-pencil" aria-hidden="true"></i>
</button>
They look like this:
I can change the height and width of the buttons and the inline icons will stay centered:
.btn.btn-dark.btn-sm {
height: 80px;
width: 200px;
}
But then when im making them smaller for mobile, all of the sudden, the inlined icons stop being centered after i fall below a certain width/height:
#media (max-width: 690px){
.btn.btn-dark.btn-sm {
width: 10px;
height: 20px;
}
}
Why do they stop being centered on small width/height? How would i fix it? I tried alligning them to the center etc, but didnt find a working solution yet.
It looks like the button may have some padding that interferes when too small. Try this snippet
.btn.btn-dark.btn-sm {
height: 20px;
width: 20px;
padding: 0;
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<button type="button" class="btn btn-dark btn-sm" (click)="doSomething()">
<i class="fa fa-pencil" aria-hidden="true"></i>
</button>

Bootstrap input-group, fixed width button

I have an input-group as follow:
<div class="input-group" style="width:100%;"> <div class="input-group-btn"> <a style="padding-left: 0px;padding-right: 0px;" class="form-control btn btn-primary" onclick="CaptureMapLocation('DependentRelation','0');" role="button"><i class="fa fa-map-marker"></i></a> </div> <div class="input-group-btn"> <a style="padding-left: 0px;padding-right: 0px;" class="form-control btn btn-default disabled" role="button"><i class="fa fa-search"></i></a> </div> <div class="input-group-btn"> <a style="padding-left: 0px;padding-right: 0px;" class="form-control btn btn-default disabled" role="button"><i class="fa fa-remove"></i></a> </div> </div>
I need the last button to have a fixed width, how to do that?
You can achieve this with CSS - the following will target the input group button that is the last child of the input group and apply a width to it.
You should move all your inline styling to a separate (external) CSS sheet which will make the code cleaner and easier to read.
Note the following will apply to all input group buttons in your page so you might want to apply a specific class or id to the parent input group div.
.input-group-btn:last-child {
width: 100px; // or whatever your desired width is
}
You can also do this with flex
.input-group {
display: flex;
}
.input-group-btn {
flex-grow:1;
}
.input-group-btn:last-child {
flex-grow: 0;
flex: shrink:0;
flex-basis: 100px; // or whatever your desired width is
}
If you want to apply the fixed witdh to the second button then it would be
.input-group-btn:nth-child(2){
width: 100px; // or whatever your desired width is
}
Ultimately - if any button could be afffected - you could create a "fixed-width-class" and apply it to the button / s you want affected.
.input-group-btn.fixed-width {
width: 100px; // or whatever your desired width is
}

How can I avoid that in-line icons jump to the next line in mobile?

How can I avoid that the icon jumps to the next line?
In desktop the icons are in-line but in mobile I can't make the icons fit horizontally the screen.
This is the code of the navbar:
<nav class="navbar fixed-bottom navbar-light bg-company-dark nav2" style="margin-top: 5px;">
<div class="d-flex container justify-content-end">
<button class="iconButton" onclick="window.location.href='/';"><i class="fas fa-chevron-left"></i></button>
<button id="translateFromApps" class="iconButton">
<i class="fas fa-language"></i>
</button>
<button id="deleteApp" class="iconButton"><i class="fas fa-trash"></i></button>
<button id="toggleApp" class="iconButton"><i class="fas fa-minus"></i></button>
<a class="iconButton" href="apps/createApp"><i class="fas fa-plus"></i></a>
<button id="editApp" class="iconButton"><i class="far fa-edit"></i></button>
</div>
</nav>
Thanks for any help
the flex-warp:wrap in the class .navbar>.container, .navbar>.container-fluid{} makes the button jump into the next line ...you can either remove it or reduce the padding to fit the buttons in the container
The CSS flex-wrap property specifies whether flex items are forced into a single line or can be wrapped onto multiple lines. If wrapping is allowed, this property also enables you to control the direction in which lines are stacked.
Add the following css and you're done...
.navbar>.container>* {
display: flex;
flex-direction: column;
flex-grow: 1;
text-align: center;
align-items: center;
height: 35px;
}
.d-flex.container.justify-content-end>*>* {
flex-grow: 1;
display: flex;
align-items: center;
}

How to disable sidenav overlay in Materializecss?

I have the following code:
<ul id="slide-out" class="side-nav">
<li><a class="subheader">Scalls Seleccionados</a></li>
<li><a class="btn waves-effect waves-light cyan"><i class="material-icons">inbox</i>Scall 1</a></li>
<li><a class="btn waves-effect waves-light cyan"><i class="material-icons">inbox</i>Scall 2</a></li>
<li><a class="btn waves-effect waves-light cyan"><i class="material-icons">inbox</i>Scall 3</a></li>
<li><div class="divider"></div></li>
</ul>
<a data-activates="slide-out" class="button-collapse btn-floating btn-large cyan" style="top: 10px; left: 10px;">
<i class="material-icons">menu</i>
</a>
Do you have any idea how to disable/remove the overlay when I display the sidenav in Materializecss?
I've spend a lot of time trying to remove it.
IF the issue is because the overlay is overlapping the nav menu, use this CSS fix;
.navbar-fixed {
z-index: 999;
}
// the default value is 997 in materialize.min.css, which places the nav behind the overlay... :(
add this to your css file :
#sidenav-overlay {
background-color: transparent;
}
I know it is an old question but for anyone wanting to remove the overlay the following works:-
.sidenav-overlay {
height: 0px;
width: 0px;
}
or with Svelte:-
:global(.sidenav-overlay) {
height: 0px;
width: 0px;
}
One approach would be to add .sidenav-overlay{opacity: 0;} to your css.
Well, I have also not found any specific function call to do so.
This is how disabling the sidenav without removing it from DOM.
var sideNavElem = $('a[data-activates="slide-out"]');
$(sideNavElem).off('click');
$(sideNavElem).click(function(e){
e.preventDefault();
});
is it similar to what you are looking for?
You can easily remove it from DOM using onOpenStart event
$('.side-nav').sidenav({
..., //your sidenav options here
onOpenStart: function(sidenav) {
sidenav.M_Sidenav._overlay.remove();
}
});

Bootstrap 3 "btn-group" non-responsive behavior on small screens

Is there a bootstrap 3 way to handle small screen sizes for "btn-group"?
Button group is placed in <td> and wrapped in <div class="btn-group">:
Looks okay, until you re-size it to <768px. Then you have:
How to make them persistent? I tried to add class btn-group-justified. But it gives as a result full width buttons and looks even worse on re-size to small screen size.
P.S> I have an idea, how to implement it adding full set of custom classes. My question is about bootstrap3 way. May be I missed something.
You can create two button groups with the same buttons and make one of them btn-group-vertical. Then after applying the hidden-xs and visible-xs to them you can hide and show vertical group on appropriate screen size.
<div class="btn-group hidden-xs">
<button class="btn btn-default">View</button>
<button class="btn btn-default">Delete</button>
</div>
<div class="btn-group-vertical visible-xs">
<button class="btn btn-default">View</button>
<button class="btn btn-default">Delete</button>
</div>
Unfortunately, this requries repeating the markup of the buttons but it should not be an issue if you use any templating tool (define the markup once and include it twice).
Wide screen:
Narrow screen:
See the JSFiddle.
I want to offer you a version with icons from FontAwesome.
With a minimum screen resolution text hide leaving only icons.
Sorry for my english.
<div class="btn-group">
<button class="btn btn-default" title="View"><i class="fa fa-eye"></i><span class="hidden-xs"> View</span></button>
<button class="btn btn-default" title="Delete"><i class="fa fa-times"></i><span class="hidden-xs"> Delete</span></button>
</div>
UPDATE by Vishal Kumar: add GLYPHICONS preview
Check this fiddle: http://jsfiddle.net/Jeen/w33GD/4/
Here's an alternative to #fracz's answer you can try that won't duplicate HTML content. Just copied the css from btn-vertical-group and btn-group and used a media query.
All you have to do is add btn-toolbar-responsive to the toolbar div's classes.
It's in scss for simplicity although you can convert it online easily. Here is the JS Bin:
demo
SCSS:
.btn-toolbar.btn-toolbar-responsive{
text-align: center;
margin: 0;
.btn-group{
float: none;
}
#media (max-width: 767px){
.btn + .btn,
.btn + .btn-group,
.btn-group + .btn,
.btn-group + .btn-group {
margin-top: -1px;
margin-left: 0;
}
.btn-group{
position: relative;
display: block;
vertical-align: middle;
margin: 0;
.btn {
display: block;
float: none;
max-width: 100%;
}
.btn:not(:first-child):not(:last-child) {
border-radius: 0;
}
.btn:first-child:not(:last-child) {
border-top-right-radius: 4px;
border-top-left-radius: 4px;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}
.btn:last-child:not(:first-child) {
border-top-right-radius: 0;
border-top-left-radius: 0;
border-bottom-right-radius: 4px;
border-bottom-left-radius: 4px;
}
}
.btn-group:not(:first-child):not(:last-child) {
.btn {
border-radius: 0;
}
}
.btn-group:first-child:not(:last-child) {
.btn:last-child, .dropdown-toggle {
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}
}
.btn-group:last-child:not(:first-child) {
.btn:first-child {
border-top-right-radius: 0;
border-top-left-radius: 0;
}
}
}
}
Okay, so this worked in a test page I made:
<div class='btn-group'>
<button class='btn btn-default col-xs-6'>View</button>
<button class='btn btn-default col-xs-6'>Delete</button>
</div>
Forcing each button to be 50% using col-xs-6 kept it from wrapping in my own test page modeled after your example. However, if you have a wider table than the example and you squish down to 320px, the text will overflow the buttons and it looks even worse than your bad example.
You may already know this and it may not be practical for your situation, so I apologize if I'm just presenting unhelpful examples. However, if your table is much wider than what you posted as an example, I would suggest making your rows using the BS grid instead of a table. What this allows you to do is make a single row become two rows when the page shrinks, e.g.
<div class='row'>
<div class='col-xs-12 col-sm-6'>Some additional details</div>
<div class='col-xs-6 col-sm-3'>Date</div>
<div class='col-xs-6 col-sm-3'>
<div class='btn-group'>
<button class='btn btn-default col-xs-6'>View</button>
<button class='btn btn-default col-xs-6'>Delete</button>
</div>
</div>
</div>
then, just find a way to alternate colors, add borders, or whatever you need to show the separation between the multiple row rows.
In the BootPly that I just made, as I said, the buttons start to overlap at very small sizes, but they don't wrap when inside a <td> in my browser tests:
http://www.bootply.com/117330
try to set min-width on <td>
<td style="min-width: 90px">
<div class="btn-group">
<button class=" btn btn-default btn-circle" type="button">
<i class="fa fa-check"></i>
</button>
<button class=" btn btn-default btn-circle" type="button">
<i class="fa fa-question"></i>
</button>
<button class=" btn btn-default btn-circle" type="button">
<i class="fa fa-times"></i>
</button>
</div>
</td>
<div id="secondNav" class="btn-group" role="group">
<button class='btn btn-default'>View</button>
<button class='btn btn-default'>Delete</button>
</div>
You can accomplish this with some simple jQuery
<script>
$(window).resize(function() {
justifyBtnGroup('secondNav');
});
function justifyBtnGroup(id) {
var btnGroup = $('#' + id);
if($(window).width() > 768) {
btnGroup.addClass('btn-group').removeClass('btn-group-vertical');
} else {
btnGroup.removeClass('btn-group').addClass('btn-group-vertical');
}
}
justifyBtnGroup('secondNav'); // will run when page loads
</script>
This help for me. It doesn't make the buttons vertical, but it doesn't compress them either
<div class="btn-group flex-wrap" data-toggle="buttons">
No, If you open page in small screen, bootstrap wrap you buttons.
<div class="btn-group btn-group-lg">...</div>
<div class="btn-group">...</div>
<div class="btn-group btn-group-sm">...</div>
<div class="btn-group btn-group-xs">...</div>
you can add the class (btn-group-xs,btn-group-sm) in the media < 720px
hope it will help you ;)