Bootstrap button shifted to the right outside containing div - html

I've got a very simple bootstrap page that has a div with a column of buttons in it. For no apparent reason the buttons are shifted slightly to the right:
The containing div (as highlighted above) has no padding or margin:
and the buttons have the same margin applied on both sides:
associated html:
<div class="cinema-list" style="max-width: 700px;" class="m-auto">
<h2>Select Cinema</h2>
<div class="form-group">
<label for="cinemaSearchInput">Search</label>
<input
type="text"
class="form-control"
id="cinemaSearchInput"
placeholder="Cinema name..."
[(ngModel)]="searchString"
>
</div>
<div *ngIf="cinemaList != null">
<button
*ngFor="let cinema of cinemaList"
type="button"
class="btn btn-primary cinema-button m-1 w-100"
(click)="selectCinema(cinema)"
>
<span>{{cinema.name}}</span>
<i
*ngIf="isFavoriteCinema(cinema)"
class="fa fa-heart pl-1 heart"
aria-hidden="true"></i>
</button>
</div>
<div
*ngIf="cinemaList == null"
class="d-flex align-items-center pt-2">
<span class="spinner-border text-primary mr-2"></span>
<span>Loading...</span>
</div>
</div>
and scss:
.cinema-list{
.cinema-button{
display: block;
}
.cinema:hover{
background-color: $primary;
}
}
I can't see any reason why the buttons are shifted. Is this a bug with bootstrap?
This is boostrap 4.3.1
Thanks

It is because you added class m-1 in the button. please remove that class from it.
Replace
class="btn btn-primary cinema-button m-1 w-100"
With
class="btn btn-primary cinema-button w-100"
Hope this will help you.

Please use my-1 and mx-0 class instead of m-1 class.
<button
*ngFor="let cinema of cinemaList"
type="button"
class="btn btn-primary cinema-button my-1 mx-0 w-100"
(click)="selectCinema(cinema)"
>
<span>{{cinema.name}}</span>
<i
*ngIf="isFavoriteCinema(cinema)"
class="fa fa-heart pl-1 heart"
aria-hidden="true"></i>
</button>

Alok Mali's answer fixes the issue.
I can't see any reason why the buttons are shifted. Is this a bug with bootstrap?
No, this is how CSS is designed.
This is the root cause why this is happen.
In Bootstrap by default all elements have box-sizing:border-box;
This is done by reset.scss
*,
*::before,
*::after {
box-sizing: border-box; // 1
}
For border-box the width and height properties of an element include the content, padding, and border, but do not include the margin. In your case you have a margin of .25em when you applied class m-1, thats why your element (button in this case) overlflowed.
More read of box-sizing here
Hope this helps.

Related

Problem with menu display on tableheader button primeng

I'm using Primeng and I can't display correctly this menu when the button is clicked. As you can see on this image, the menu displays outside of the table header far away from the button. What I need is the menu displays just below from the button as this prototype.
<ng-template pTemplate="caption">
<div class="flex align-items-center justify-content-between mb-2">
<h3 class="m-0"> Lista de evaluaciones
</h3>
<button pButton pRipple label="Agregar evaluaciĆ³n" icon="pi pi-folder" (click)="menu.toggle($event)"
class="p-button-primary mr-2"></button>
</div>
<p-menu #menu [popup]="true" [model]="items"></p-menu>
</ng-template>
I thought the problem was the p-menu outside de div but if it's in there the flex align-item-center justify-content-between of Primeflex moves the elements. Thanks for the help.
The solution is to put the p-menu element outside of the caption, where the table styles cannot affect it:
<p-table [value]="customers" dataKey="id" [rows]="10">
<ng-template pTemplate="caption">
<div class="flex align-items-center justify-content-between mb-2">
<h3 class="m-0">Lista de evaluaciones</h3>
<button
pButton
pRipple
label="Agregar evaluaciĆ³n"
icon="pi pi-folder"
(click)="menu.toggle($event)"
class="p-button-primary mr-2"
></button>
</div>
</ng-template>
</p-table>
<p-menu #menu [popup]="true" [model]="items"></p-menu>
StackBlitz

Angular Redirecting to a specific element on the page without errors

I needed to add a span to my HTML with an ID to be able to go to it after clicking Reply button. I needed it only for the last element on the page. It works but I'm getting 2 errors in the console. Could anyone tell me what have I done wrong and how can I get rid of them?
<div class="comment">
<app-user-image></app-user-image>
<div class="position-relative d-inline-block flex-fill">
<div class="d-flex justify-content-between align-items-center">
<div><strong>{{comment.author.name}} / {{comment.author.id}}</strong><span
class="date">{{comment.created | krakenDateTime}}</span></div>
<div class="actions">
<button *ngIf="this.hateoas.supports(comment, 'update') && !edit"
type="button" class="bg-transparent border-0" title="Edit"
(click)="toggleEdit()"><i class="icon-kraken icon-kraken-edit"></i></button>
<button *ngIf="this.hateoas.supports(comment, 'delete')"
type="button" class="bg-transparent border-0" title="Delete"
(click)="displayDeletionConfirmation()"><i class="icon-kraken icon-kraken-trash"></i></button>
</div>
</div>
<textarea *ngIf="edit; else readonlyComment"
#textarea
class="d-block w-100"
style="min-height: 7rem;"
[rows]="rows()"
[(ngModel)]="commentContent"></textarea>
<ng-template #readonlyComment>
<div [innerHTML]="commentContentHtml()"></div>
</ng-template>
<strong *ngIf="showReplyButton"
class="reply-button"
(click)="toggleReplyComponent()">Reply</strong>
</div>
here is the onInit method but I have not touched it
ngOnInit(): void {
if (this.comment) {
this.textArea.nativeElement.focus()
}
}
I'm presuming textArea is a #ViewChild reading the #textarea ref
That textarea component is in an ngIf, so it won't be available during ngOnInit
Also, the ngIf specifically removes the textarea if the comment is displayed - so your logic seems a bit off
<textarea *ngIf="edit; else readonlyComment" ...>

how to make buttons extend to full width in mobile view while not end pc using bootstrap?

i want to apply text end or push the buttom to end in pc view and make each buttons take whole width and stack upon each other in mobile view for two href buttons inside ! any idea??
<div class="row flex-between-end ps-0 pe-0">
<div class="col-md-5">
<label class="col-form-label text-facebook">#wordInfo["Title"]</label>
</div>
<div class="col-md-7 ps-sm-0">
<a href="#(ViewData["ROOT_URL"])menu/menuform/#Common.CommonConst.Mode.PUB_C_REGIST/"
class="btn btn-outline-primary mb-2 ms-1 float-md-end ">
<span class="fas fa-plus " data-
fa-transform="shrink-3"></span> #wordInfo["Regist"]</a>
<a href="#(ViewData["ROOT_URL"])menu/menusublist/" class="btn btn-outline-primary mb-2
float-md-end"><span class="fa fa-bars" data-fa-transform="shrink-3"></span>
#wordInfo["MenuSubList"]</a>
</div>
pc view ok
enter image description here
should looks like this in mobile view
enter image description here
Add this class mobile to label(Menu list) & a tag(Sub,Reg).
#media (max-width: 800px) {
.mobile {
display: flex;
flex-direction: column;
align-items: center;
}
}
This will make them vertical when screen-width<=800px, change the vaue if you need to.

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
}

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 ;)