Bootstrap "close" Class: Button Sometimes Pushed out of Alert by Text - html

I'm wondering if there are any edits I can make on top of bootstrap's css to resolve the following behaviour where my close class button sometimes gets pushed out of its alert by the text within.
Most of the time, it appears fine like so:
But at certain screen widths, just before the text in the alert wraps, the close button no longer has enough room at the end of the alert. In this image, I reduced the screen width by a few pixels compared to the previous image:
Here is my code snippet (edited to replace ASP.NET controls and code render blocks):
<div class="mt-0 mb-3 alert alert-primary">
<span class="text-here">foo</span>
<a class="close">
<span>×</span>
</a>
</div>

Good observation
The green div with display:inline-block; & width to 100% should resolve this...
working snippet below:
.fixedAlert {
display: inline-block;
width: 100%;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<div class="container">
<div class="mt-0 mb-3 alert alert-success fixedAlert">
<span class="text-here"> FIXED ALERT... I'm wondering if there are any edits I can make on top of bootstrap's css to resolve the following behaviour where my close class button sometimes gets pushed out of its alert by the text within</span>
<button type="button" class="close">
<span>×</span>
</button>
</div>
<div class="mt-0 mb-3 alert alert-primary ">
<span class="text-here"> ORIGINAL ALERT... I'm wondering if there are any edits I can make on top of bootstrap's css to resolve the following behaviour where my close class button sometimes gets pushed out of its alert by the text within</span>
<button type="button" class="close">
<span>×</span>
</button>
</div>
</div>
Updated: in light of questioner's comment below

It turns out I'd simply removed one class too many while removing client-side dismiss functionality in favour of an ASP.NET click event postback.
The class in question, alert-dismissible, which is supposed to go alongside the alert class when a close button is present. It adds a larger amount of padding to the right side of the alert div, such that the floating close button/anchor always has enough room to sit at the top right. It also gives the close button some styling, including padding, such that it is nicely centered in that vertical space.
That also explains why my close button was at the bottom right instead. A comment on the main question that got deleted by its OP did point out that the close button looked like it was in a weird position.
Here is my new working code, without any additional custom classes needed:
<div class="mt-0 mb-3 alert alert-dismissable alert-primary">
<span class="text-here">foo</span>
<a class="close">
<span>×</span>
</a>
</div>

Related

HTML/CSS/Blazor Fixed Buttons above and below list which needs to fill remaining space

I have an app built in blazor for a shopping list.
The UI is composed of the default blazor template tab,
an Add Item button at the top and a Finished shopping button at the bottom.
Between the 2 buttons I want the remaining space to be taken up by a list of custom components.
I do not know how to get the height of the list set to the remaining space on the page.
Closest I have gotten is by setting the size of the list container to 100vh - 140pixels where 140pixels is the size of the buttons.
As the nav tab appears on the top for narrow screens and the left for wide screens I can't just hardcode in the value for it.
I would also prefer if this didn't rely on me hardcoding this as well.
I have tried setting the container height to 100% but that is just giving it no limit.
The list is in a div with the overflow-auto class from bootstrap.
The code
<body style="height:100%">
<div style="">
<div style="">
<button class="btn btn-primary" style="margin-bottom: 10px; width:100%;" #onclick="AddItem">Add Item <span class="oi oi-plus" style="margin-left: 5px;" aria-hidden="true"></span> </button>
</div>
<div class="overflow-auto" style="height: calc(100vh - 140px);">
#foreach (var item in _shoppingItems)
{
<ShoppingItemComponent Item="#item" DeleteItem="DeleteItem" BoughtToggle="UpdateItem" ></ShoppingItemComponent>
}
</div>
<div style="">
<button class="btn btn-primary" style="width:100%;" #onclick="ClearList">Shopping Done</button>
</div>
</div>
</body>
You can see it running here, although note I am fiddling with it there so it may not match exactly with the styling in this question.
https://smartshoppingapp.azurewebsites.net/
I have found some solutions around stack overflow around the problem, however I cannot get them working within my solution, I think all of the blazor boilerplate divs and bodies etc that wrap around my page are preventing the 100% height working as intended. i.e index.html and mainlayout.razor
Use bootstrap flex:
I un-wired your buttons to get it to work locally.
<div class="vh-100 d-flex flex-column align-items-stretch">
<button class="btn btn-primary">
Add Item <span class="oi oi-plus" style="margin-left: 5px;" aria-hidden="true"></span>
</button>
<div class="flex-fill overflow-auto">
#foreach (var item in _shoppingItems)
{
<ShoppingItemComponent Item="#item"
DeleteItem="DeleteItem"
BoughtToggle="UpdateItem" />
}
</div>
<button class="btn btn-primary">
Shopping Done
</button>
</div>
As a side note: When I am debugging these sort of issues I assign background colours to the divs to see what is really happening. That and inpecting the HTML with the browser tools.

Bootstrap pull-right only working at small width

I'm using Bootstrap to get some text and a button to appear on the same line on opposite sides of the screen. I'm using pull-right to bring the button to the right side of the screen, but it only works when the screen width is narrow. If I make it wider, the button moves next to the text. Here's a JSFiddle example and the relevant code:
<body>
<div class='container-fluid'>
<form class="form-inline">
<div class="form-group ">
<label>Some Text</label>
<button type="button" class="btn btn-primary pull-right">Some Button</button>
</div>
</form>
<div><p>The button only appears on the right side of the window when the width is fairly narrow, even though it has the Bootstrap 'pull-right' class.</p></div>
</div>
</body>
Is there a way to get the button to the right at all widths? Apologies, I'm not great with Bootstrap and CSS, so I'm sure this is an easy thing that I'm missing. Also, for what it's worth, this is for an Electron app, so it only needs to work in Chrome.
Thanks.
That's because it's wrapped in a form group div, which is only the full width on smaller viewports. You could get rid of the form group and just make the div width:100% in css.

prevent bootstrap navbar-fixed-bottom overlap

In some cases the bootstrap navbar-fixed-bottom will overlap other content without displaying a scrollbar.
For example https://jsfiddle.net/m5vgd9g7/1/:
<div>
<a class="btn btn-primary" href="#">
Button
</a>
</div>
<div class="navbar navbar-default navbar-fixed-bottom"
style="padding-bottom:0px; min-height:0px">
bottom
</div>
If you make the display pane very short vertically, the text "bottom" overlaps the button:
How can the overlap be prevented, so a vertical scrollbar appears before they overlap?
You should add a class to your top div which is row, so your top html would look like
<div class="row">
<a class="btn btn-primary" href="#">
Button
</a>
</div>
This will add you a scrollbar for your content vertically. But when we declare a fixed navbar you should keep in mind to add a padding/margin to the rest of the content to the size of the navbar, which should display the rest of the content without being intruded by the navbar. So your final html for the top div would look like,
<div class="row" style="padding-bottom:15px;">
<a class="btn btn-primary" href="#">
Button
</a>
</div>
Note: I would never use inline styles as it would complicate the html in the long run and hard to debug. I did it here for the sake of demonstration.
And the fiddle example is here : https://jsfiddle.net/m5vgd9g7/
EDIT
Thanks to #JDiMatteo who commented about the row class addition. I was about to maintain the bootstrap standards in grid system. (ref: http://getbootstrap.com/css/#grid). Apparently it seems row should be contained within container or container-fluid classes for it to work. This will define a row, where elements/columns(as in bootstrap) could reside in. And by using this, you can get rid of the custom styling we used earlier, padding/margin.
<div class="container">
<div class="row">
<a class="btn btn-primary" href="#">
Button
</a>
</div>
</div>

Show and Hide a <div> in xs view, with a button

I have created a Bootstrap Template where there is a "sidebar" div (col-lg-3) and a content at the right (col-lg-9).
In the xs view all the columns are 12, how can I insert a button that hide and show the content in the sidebar div just in the xs view at the click on it?
I don't know Javascript or jQuery, someone can help me?
Thanks!
If you're using Bootstrap, you might want to check out the Collapse plugin: http://getbootstrap.com/javascript/#collapse
There is a pretty simple example, but you'd want to set it up like this:
*note that you want to add the visible-xs class to the button, so that it is only displayed on xs screens. Additionally, I added the in class on the div that collapses, so that is shows by default (otherwise it would be hidden on all screen sizes).
<div class="row">
<div class="col-lg-3">
<button class="btn btn-primary visible-xs" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
*Button only visible on xs*
</button>
<div class="collapse in" id="collapseExample">
*sidebar content*
</div>
</div>
<div class="col-lg-9">
*content in col-lg-9*
</div>
</div>
Here is an example of the above code. Make sure the screen size is small enough, otherwise the button will be hidden. Click the button to toggle the visibility of col-lg-3 content. http://jsfiddle.net/7v7p744L/1/
Additionally, you could just add the hidden class to the button and say at what size you want it to take effect.
eg:
*hidden in xs
*hidden in sm

Bootstrap floating drops item onto second line

This is my code: http://www.bootply.com/Tm5C3Ja7RL
<div class="col-md-12">
<h3>Test</h3><button class="btn btn-default pull-right">Button</button>
</div>
It drops the button onto a second line as well as aligning it to the right. I only want to push it to the right. Can anyone show me the best way of doing this.
As EWit mentioned, a header is a block element.
This block will push down other elements behind it.
There are several solutions, one better/cleaner than the other
Changing the header to an inline element
h3 {
display:inline;
}
This will result in your title with the button right next to it.
I don't think the pull-right will have an effect on it. Should be tested.
You could also add the condition that the h3 must have a certain class or must be inside an element with a certain class.
Splitting the column in 2
<div class="col-md-10">
<h3>Test</h3>
</div>
<div class="col-md-2">
<button class="btn btn-default pull-right">Button</button>
</div>
By also using col-sm, for example, you could alter this so that the button is displayed next to the title in a medium/large screen and under it in a small screen.
However, the pull-right might make it look pretty weird then.
<div class="col-md-10 cold-sm-12">
<h3>Test</h3>
</div>
<div class="col-md-2 col-sm-12">
<button class="btn btn-default pull-right">Button</button>
</div>
Put the button in the h3-element
As EWit mentioned, you can also put the button inside the h3-element.
This will keep the button in the same line, but might alter the text formatting.
<div class="col-md-10">
<h3>Test <button class="btn btn-default pull-right">Button</button></h3>
</div>
Put it inside the <h3>. Headers in HTML take up the full width as a block object. As such other objects are pushed down.
Try:
<div class="col-md-12">
<h3>Test <button class="btn btn-default pull-right">Button</button></h3>
</div>
I myself extend it with some markup for basic links but to align it to the same height as the text in the header.
h1 .pull-right {
padding: 15px 5px 0 0;
}
But I have no idea what values would be best for a button to align it. Trial and error I guess.