Select2 Select in Bootstrap Modal - twitter-bootstrap-3

I've already checked the other threads, covering this problem, but none of this solutions work for me.
I'm using jquery 1.11.2, select2-4.0.0-beta.3 and bootstrap-3.3.1
My modal looks like following:
<div class="modal fade" id="addProductModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Add Product</h4>
</div>
<div class="modal-body">
{!! BootForm::openHorizontal(2,10)->action('/recipes/'.$recipe->id.'/product')->post() !!}
{!! BootForm::select('Produkte: ','product_list[]' , $products)->id('products') !!}
{!! BootForm::submit('Erstellen') !!}
{!! BootForm::token() !!}
{!! BootForm::close() !!}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Schließen</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
And I want to call $('#products').select2();
The plugin works fine in other places. But it's screwed up in a modal:
Update: (Not) Working fiddle here http://jsfiddle.net/Strernd/o0d3vtek/

The issue you're having is that, when Select2 is binded to the select, the generated span is something like:
<span class="select2 select2-container select2-container--default" dir="ltr" style="width: 100px;">
<span class="selection">
<span class="select2-selection select2-selection--single" tabindex="0" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-expanded="false" aria-owns="select2-products-results" aria-labelledby="select2-products-container">
<span class="select2-selection__rendered" id="select2-products-container">Mein Produkt</span>
<span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span>
</span>
</span>
<span class="dropdown-wrapper" aria-hidden="true"></span>
</span>
You'll notice the hardcoded width: 100px that forces the text to be "splitted". You might be thinking "why the hell?!" and the response most certainly is: you're using a beta version.
You can solve this issue by:
Forcing width: 100% with the following CSS code:
.select2-container {
width: 100% !important;
padding: 0;
}
Take a look at this working jsfiddle (I added some col-xs classes to your label and another div). Beware that this solution works as long as you have enough width for your text. If the width is smaller than the text you'll have the same issue and you'll need to tweak the CSS to add overflow: auto; and text-overflow: ellipsis;
Use the latest stable version 3.5.2, which works correctly as this jsfiddle shows.

span.select2-container {
z-index:10050;
}
does not work when you have select2 outside of the modal.
EDIT
I found this would be a better solution when using select2 in Bootstrap Modal and outside them.
.select2-container--open{
z-index:9999999
}

You can use this link when you want to use select2 in modal:
$('#my-select').select2({
dropdownParent: $('#my-modal')
});

What I did was to add this code just above the page
span.select2-container {
z-index:10050;
}

Related

Cannot bottom align image in jumbotron

I'm trying to bottom align an img in a jumbotron, but cannot figure it out.
<div class="jumbotron">
<div class="container">
<div class="row">
<div class="col-lg-8">
<h1>Hello, world!</h1>
<p>This is a template for a simple marketing or informational website. It includes a large callout called the hero unit and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
<p><a class="btn btn-primary btn-lg">Learn more »</a></p>
</div>
<div class="col-lg-4 text-center">
<img src="http://via.placeholder.com/200x200">
</div>
</div>
</div>
</div>
I tried adding the following to the CSS
.vertical-bottom {
display: flex;
align-items: bottom;
}
And then added the additional class to the DIV containing the img
<div class="col-lg-4 text-center vertical-bottom">
This didn't work, why is it so hard to vertically align things in bootstrap?
Here a kind of code:
Bootply
Css:
The media query is set to 1200 because I see you're using col-lg-xx
#media screen and (min-width:1200px) {
.flex_container img{
object-fit: contain;
object-position: 100% 100%;
}
.flex_container {
display: flex;
}
}
Html:
<div class="jumbotron">
<div class="container">
<div class="row flex_container">
<div class="col-lg-8">
<h1>Hello, world!</h1>
<p>This is a template for a simple marketing or informational website. It includes a large callout called the hero unit and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
<p><a class="btn btn-primary btn-lg">Learn more »</a></p>
</div>
<div class="col-lg-4 text-center flex_container">
<img src="http://via.placeholder.com/200x200" style="">
</div>
</div>
</div>
</div>

Bootstrap 3 equal height thumbnails (like equal height cards in bootstrap 4)

I have a row of thumbnails like this:
I want them to be equal height though. This is my code:
<div class="row text-center">
<div class="col-md-3 col-sm-6">
<div class="thumbnail">
<div class="caption">
<h3>HOTKEY + COMBO</h3>
<p>Hotkey description goes here. Category only shown in explore.</p>
<p>
<a href="#" class="btn btn-default" data-tooltip="Change Hotkey">
</p>
</div>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="thumbnail">
<div class="caption">
<h3>HOTKEY + COMBO</h3>
<p>short desc</p>
<p>
<a href="#" class="btn btn-default" data-tooltip="Change Hotkey">
</p>
</div>
</div>
</div>
<div class="col-md-3 col-sm-6 hotkey-add">
<div class="thumbnail">
<div class="caption">
<p></p>
<p><span class="glyphicon glyphicon-plus"></span></p>
</div>
</div>
</div>
</div>
Is this possible? Like we see in bootstrap4 here is equal height cards:
http://www.codeply.com/render/KrUO8QpyXP#
I know I'm a little late on this, but I think the best way is flexbox. Here's how it would work in Bootstrap 3:
.row.display-flex {
display: flex;
flex-wrap: wrap;
}
.thumbnail {
height: 100%;
}
Just add display-flex to the containing row. Also, the upcoming Bootstrap 4 has flexbox as the default so this extra CSS won't be necessary in the future.
Thumbnails with flexbox
You can also do more with the position of child elements.
Also see,
make Bootstrap columns all the same height
It seems that bootstrap 4, like you show in the example, is using to get the same height, display: table for the container div and display: table-cell for the inner ones.
Other solution can be using <table> instead <div>, using flex property...
Checkout this How can I make Bootstrap columns all the same height?

Bootstrap 3 navbar over first row

I have had a search and cannot find this exact problem so I hope the question is not duplicate.
First time users of Bootstrap 3.
From reading here and the bootstrap documentation I believe the navbar should have its own container such as:
<nav id="myNavbar" class="navbar navbar-default navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbarCollapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/index.html">My Site</a>
</div>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="nav navbar-nav">
<li class="active"><span class="glyphicon glyphicon-home"></span> Home</li>
<li><span class="glyphicon glyphicon-list-alt"></span> Services</li>
<li><span class="glyphicon glyphicon-info-sign"></span> About</li>
<li><span class="glyphicon glyphicon-envelope"></span> Contact</li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row">content goes here and this content is under the navbar</div>
</div>
The body of the page then has its own container. Is that Correct?
I have done that and then added a row but the first row content is under the navbar.
Have I missed something like a class that I should add to the first row to ensure it starts below the navbar and not after it?
I found a similar question where the answer was to ensure the navbar had "navbar-fixed-top" but I already have that.
Read documentation carefully.
According to Bootstrap navbar docs:
The fixed navbar will overlay your other content, unless you add padding to the top of the body. Try out your own values or use our snippet below. Tip: By default, the navbar is 50px high.
body {
padding-top: 70px; // Your navbar height
}
Make sure to include this after the core Bootstrap CSS.
If I understand your problem correctly that you want content below the navbar just write
navbar-fixed
instead of
navbar-fixed-top
like this
<nav id="myNavbar" class="navbar navbar-default navbar-inverse navbar-
fixed"role="navigation">
it will work
see this fiddle fiddle
are you looking for this ???
This is caused by the Bootstrap class fixed-top, Fixed navbars use position: fixed, which pulls the Nav from the normal flow of the DOM.
For this to have an effect, having your content below the Navbar not overflow unto the Navbar, BootStrap Docs>> https://getbootstrap.com/docs/4.5/components/navbar/
Under the #Placement section, advise you to give custom CSS to the body.
Add some padding to the <body style="padding: somepadding"> element.

Navbar not appears responsive mode bootstrap 3 + joomla

Dears I am working on www site. In normal desktop mode everything works fine but when I am changing it to responsive mode menu dissapears.
Case is connected with module breadcrumbs. When I turn the module off it works perfectly.
Looking for help.
Here is my code:
Navbar section:
<body>
<div class="container">
<!-- The justified navigation menu is meant for single line per list item.
Multiple lines will require custom code not provided by Bootstrap. -->
<!-- Jumbotron -->
<div class="jumbotron">
<jdoc:include type="modules" name="slider" style="xhtml" />
<!-- Static navbar -->
<nav class="navbar navbar-justified">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<jdoc:include type="modules" name="nav2" style="xhtml" />
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</nav>
Thank you in advance.
may be you have already button included but try to locate button by apply css like following: to '.navbar-toggle' class
.navbar-toggle { background-color: red;}
actually your navbar-button color may be inherit css of your site so if you assign custom css like below you can see button like standard button.
.navbar-toggle {
background: transparent none repeat scroll 0 0;
border: 1px solid #ccc;
}
.navbar-toggle span {
border: 1px solid #ccc;
}

Bootstrap modal using custom CSS (from HTML template) not working well

I have a bootstrap modal that on a Button click I show it.
Everything works great but the Modal is displayed in the very right of the screen that I can't see even the Modal footer buttons.
I'm using a HTML Template that has a custom Bootstrap CSS and that's the reason of the issue.
Here is a screenshot:
My Modal html code is:
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
And my jQuery code is:
$('#btnSave').click(function() {
$('#myModal').modal('show')
});
Here is the jsFiddle using the custom CSS that I have (from the HTML Template).
http://jsfiddle.net/uuvgLnsx/1/
Try this...
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="position: fixed; left: 25%; width:60%;>
The problem is here:
#media screen and (min-width: 768px) {
.modal-dialog {
left: 50%;
right: auto;
width: 600px;
padding-top: 30px;
padding-bottom: 30px;
}
The 'left: 50%' pushes the your dialog box into the middle. Change left to auto.