Align bootstrap dropdown in input-group to left (underneath the start of the input) - css

I have a input group (text input and button with dropdown). I am having trouble getting my dropdown to align with the text box.
<div class="row">
<div class="col-xs-6">
<div class="input-group">
<input type="text" class="form-control" />
<div class="input-group-btn">
<div class="dropdown open">
<button class="btn btn-secondary dropdown-toggle"
type="button"
id="dropdownMenuButton"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false">
dropdown
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
I have tried <div class="dropdown-menu dropdown-menu-left"> with no avail.
Here is a fiddle
What do I need to add to this to align my dropdown menu to the left underneath the start of the input (as if it was a typeahead)?
EDIT: within the dropdown menu is an angular directive, that's likely a relative tool

Here is the Quick Fix
Working Demo Here
HTML:
<div class="container">
<div class="row">
<div class="col-xs-6">
<div class="input-group">
<div class="testing">
<input type="text" class="form-control" />
</div>
<div class="input-group-btn">
<div class="dropdown open">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="false" aria-expanded="false">dropdown</button>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
CSS:
.testing {
position: relative;
}
JS:
$(document).ready(function() {
dropmenuWidgetPosition();
function dropmenuWidgetPosition() {
$('#dropdownMenuButton').dropdown('toggle');
$(window).on('show.bs.dropdown', function(e) {
var dropdownMenu = $(e.target).find('.dropdown-menu');
var dropMenuDetach = dropdownMenu.detach();
// detach it and append it to the target
$(e.target).parents('.input-group').eq(0).find('.testing').append(dropMenuDetach);
// grab the new offset position
var eOffset = $(e.target).offset();
// make sure to place it where it would normally go (this
// could be
// improved)
dropdownMenu.css({
'display': 'block',
'top': eOffset.top + $(e.target).outerHeight(),
'left': 0
});
});
// and when you hide it, reattach the drop down, and hide it
// normally
$(window).on('hide.bs.dropdown', function(e) {
var dropdownMenu = $(e.target).parents().find('.dropdown-menu');
var dropMenuDetach = dropdownMenu.detach();
$(e.target).append(dropMenuDetach);
dropdownMenu.hide();
});
}
});

Related

how to create a radio button that acts as a tab controller in spring mvc

i want to have a radio buttons that acts as tab controller same as in below jsfiddle: http://jsfiddle.net/bizamajig/mju8gzwa/
i have created the same thing in jsp with with spring tag as below.i am facing null exception in getting the selected tab value in my controller.i want to know which tab selected and based on tab selection i will query different data.
how to get which tab is selected
enter code here
<div class="container">
<div class="row">
<div id="tab" class="btn-group" data- toggle="buttons">
<a href="#daily" class="btn btn-default
active" data-toggle="tab">
<form:radiobutton path="recurrence" value="d" />Daily</a>
<a href="#features" class="btn btn-default" data-toggle="tab">
<form:radiobutton path="recurrence" value="w" />Weekly</a>
<a href="#requests" class="btn btn-default" data-toggle="tab">
<form:radiobutton path="recurrence" value="m" />Monthly</a>
<a href="#contact" class="btn btn-default" data-toggle="tab">
<form:radiobutton path="recurrence" value="o" />Once</a>
</div>
<div class="tab-content">
<div class="tab-pane active" id="prices">Prices content</div>
<div class="tab-pane" id="features">Features Content</div>
<div class="tab-pane" id="requests">Requests Content</div>
<div class="tab-pane" id="contact">Contact Content</div>
</div>
</div>
</div>
someone please help to get this working?
You can know which tab is activated currently. Based on that you can query data.
Just add below code in your jfiddle's javascript/Jquery part.
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
var target = $(e.target).attr("href") // activated tab
$(target).show();
alert(target);
});

Recursion in Play framework 2.5.X

I have a play template where I loop through a list of objects that have nested lists, and I'm displaying the items iteratively using nested for loops.
-skillList is a List[Skill]
-Skill is an object defined in a model
-skillObject.getChildrenList() return a list[Skill]
What I would like to do is be able to display this but using some type of recursion so that if the level of nesting of mylist changes I don't have to change the whole template. So is there any way to do this in a recursive way ?
<div class="custom-dd dd dd-nodrag" id="nestable_list_1">
<ol class="dd-list">
#for(skill <- skillList) {
<li class="dd-item">
<div class="dd-handle dd-nodrag row">
<span class="dd-nodrag" id="content_#skill.getCleanUri()"> #skill.getLabel() </span>
</div>
<ol class="dd-list">
#for((child, indexChild) <- skill.getChildrenList().zipWithIndex) {
<li class="dd-item" data-id="#indexChild">
<div class="dd-handle dd-nodrag row">
<span id="content_#child.getCleanUri()"> #child.getLabel() </span>
</div>
<ol class="dd-list">
#for((grandChild, indexGrandChild) <- child.getChildrenList().zipWithIndex) {
<li class="dd-item" data-id="#indexGrandChild">
<div class="dd-handle dd-nodrag row">
<span id="content_#grandChild.getCleanUri()"> #grandChild.getLabel() </span>
</div>
</li>
}
<div class="text-left addNew" id="meta-#index">
<span>
<button class="btn btn-icon w-xs plusBtn
btn-primary waves-effect waves-light toggleButton" data-toggle="modal"
data-target="#custom-width-modal"> <i class="fa fa-plus" aria-hidden="true"></i>
</button>
</span>
</div>
#(index = index + 1)
</ol>
</li>
}
</ol>
</li>
}
</ol>
Thanks in advance for any answer.
You can create a separate template that takes List[Skill] as argument and renders SkillObjects in provided list and children of these SkillObjects. Then use that template at first nested level in your main page template. Like following -
SkillTemplate.scala.html
#(skills: List[Skill])()
<ol class="dd-list">
#for((child, indexChild) <- skills.zipWithIndex) {
<li class="dd-item" data-id="#indexChild">
<div class="dd-handle dd-nodrag row">
<span id="content_#child.getCleanUri()"> #child.getLabel() </span>
</div>
#SkillTemplate(child.getChildrenList())
<div class="text-left addNew" id="meta-#index">
<span>
<button class="btn btn-icon w-xs plusBtn
btn-primary waves-effect waves-light toggleButton" data-toggle="modal"
data-target="#custom-width-modal"> <i class="fa fa-plus" aria-hidden="true"></i>
</button>
</span>
</div>
#(index = index + 1)
</li>
}
</ol>
I have not been able to test it

How to keep CSS blocks equal?

I am creating a virtual store where the main page shows the products, this is where the quantity of information in the detail of the product varies, the blocks begin to deform. How could you do to keep the size constant and in any case the text is truncated?
I'm working with MVC 5 and Bootstrap.
<!-- Bloque 1 -->
#foreach (var item in Model)
{
<div class="col-sm-3 col-lg-3 col-md-3">
<div class="thumbnail">
<!-- TRAE UNA IMAGEN DE CUALQUIER MANERA-->
<img src="#Url.Action("RenderImage", new { id = item.ProductoID})" alt="" width="150" height="320" />
<div class="panel panel-yellow">
<div class="panel-heading">
<h4 class="pull-right">$#item.PrecioUnitario</h4>
<h4>
<a href="#Url.Action("Detalle", new { id = item.ProductoID })" class="my-class">
#item.Nombre
</a>
</h4>
</div>
</div>
<div class="ratings">
#*<p>See more snippets like this online store item at <a target="_blank" href="http://www.bootsnipp.com">Bootsnipp - http://bootsnipp.com</a>.</p>*#
<p>#item.DetallesCorto</p>
</div>
<div class="ratings">
<p class="pull-right">15 Me gusta</p>
<p>
<span class="fa fa-fw fa-star"></span>
<span class="fa fa-fw fa-star"></span>
<span class="fa fa-fw fa-star"></span>
<span class="fa fa-fw fa-star"></span>
<span class="fa fa-fw fa-star"></span>
</p>
<p>
<button type="button" class="AddLink btn btn-block btn-success btn-xs" href="#" data-id="#item.ProductoID" data-toggle="modal" data-target="#myModal">
<i class="fa fa-fw fa-shopping-cart"></i> Agregar
</button>
</p>
</div>
<div class="ratings">
#if (Request.IsAuthenticated && User.IsInRole("Root") || User.IsInRole("Admin"))
{
<p>
<button type="button" class="anchorDetail btn btn-block btn-info btn-xs"
href="javascript:void(0);" data-id="#item.ProductoID">
<i class="fa fa-pencil"></i> Edicion rĂ¡pida
</button>
</p>
<p>
<button type="button" class="popupDelete btn btn-block btn-danger btn-xs"
href="javascript:void(0);" data-id="#item.ProductoID">
<i class="fa fa-trash"></i> Eliminar
</button>
</p>
}
</div>
</div>
</div>
} <!-- Cierro Forech -->
</div>
That's how it looks now:
Solution 1 (CSS)
Set a fixed height on the red paragraph and the title and hide the overflow.
.thumbnail .ratings:nth-of-type(1) p {height: 100px; overflow: hidden;}
.thumbnail h4:nth-child(2) {height: 30px; overflow: hidden;}
Solution 2 (jQuery)
Create a javascript function setting the height equal to the tallest red paragraph and the tallest title.
var maxh = 0;
$('.thumbnail .ratings:nth-of-type(1) p').each(function() {
var h = $(this).height();
if(h > maxh) maxh = h;
});
$('.thumbnail .ratings:nth-of-type(1) p').css('height', maxh);
var maxh = 0;
$('.thumbnail h4:nth-child(2)').each(function() {
var h = $(this).height();
if(h > maxh) maxh = h;
});
$('.thumbnail h4:nth-child(2)').css('height', maxh);
You might be tempted to set a fixed height to the thumbnail div. But that will require you to set the rating stars and the green button to position: absolute; bottom: [amount]px; to align them properly. I am quite sure that is not compatible with the bootstrap floats and the responsive behaviour of these items.
You can loop through each .thumbnail item and find the max height, then apply a min-height to each element matching that max height:
$(document).ready(function() {
var maxHeight = 0;
$('.thumbnail').each(function() {
var height = $(this).height();
if(height > maxHeight) {
maxHeight = height;
}
});
$('.thumbnail').css('min-height', maxHeight);
});
You may need to utilize a delay such as setTimeout to ensure everything has been loaded prior to calculating the heights.
You should use rows or set equal height to all boxes with javascript/jquery. Bootstrap uses 12 cols per row so you could modify your code to separate by 4 items per row. Also you only need the smallest device col width if larger ones are same. In your case use col-sm-3 only.
<div class="row">
<div class="col-sm-3" ></div>
<div class="col-sm-3" ></div>
<div class="col-sm-3" ></div>
<div class="col-sm-3" ></div>
</div>
Give the boxes a set height for example:
.box {
height: 150px;
}

Set a button group's width to 100% and make buttons equal width?

I'm using Bootstrap, and I'd like to set an entire btn-group to have a width of 100% of its parent element. I'd also like the inner buttons to take equal widths. As it is, I can't achieve either.
I've made a JSFiddle here: http://jsfiddle.net/BcQZR/12/
Here is the HTML:
<div class="span8 background">
<div class="btn-group btn-block" id="colours">
<span class="btn"><input type='checkbox' name='size' value='red'/>red</span>
<span class="btn"><input type='checkbox' name='size' value='orange'/>orange</span>
<span class="btn"><input type='checkbox' name='size' value='yellow'/>yellow</span>
</div> <!-- /btn-group -->
</div>
And here is my current CSS, which doesn't work:
#colours {
width: 100%;
}
Bootstrap has the .btn-group-justified css class.
How it's structured is based on the type of tags you use.
With <a> tags
<div class="btn-group btn-group-justified" role="group" aria-label="...">
...
</div>
With <button> tags
<div class="btn-group btn-group-justified" role="group" aria-label="...">
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">Left</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">Middle</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">Right</button>
</div>
</div>
There's no need for extra css the .btn-group-justified class does this.
You have to add this to the parent element and then wrap each btn element in a div with .btn-group like this
<div class="form-group">
<div class="btn-group btn-group-justified">
<div class="btn-group">
<button type="submit" id="like" class="btn btn-lg btn-success ">Like</button>
</div>
<div class="btn-group">
<button type="submit" id="nope" class="btn btn-lg btn-danger ">Nope</button>
</div>
</div>
</div>
BOOTSTRAP 2 (source)
The problem is that there is no width set on the buttons. Try this:
.btn {width:20%;}
EDIT:
By default the buttons take an auto width of its text length plus some padding, so I guess for your example it is probably more like 14.5% for 5 buttons (to compensate for the padding).
Note:
If you don't want to try and compensate for padding you can use box-sizing:border-box;
http://www.w3schools.com/cssref/css3_pr_box-sizing.asp
I don't like the solution of settings widths on .btn because it assumes there'll always be the same number of items in the .btn-group. This is a faulty assumption and leads to bloated, presentation-specific CSS.
A better solution is to change how .btn-group with .btn-block and child .btn(s) are display. I believe this is what you're looking for:
.btn-group.btn-block {
display: table;
}
.btn-group.btn-block > .btn {
display: table-cell;
}
Here's a fiddle: http://jsfiddle.net/DEwX8/123/
If you'd prefer to have equal-width buttons (within reason) and can support only browsers that support flexbox, try this instead:
.btn-group.btn-block {
display: flex;
}
.btn-group.btn-block > .btn {
flex: 1;
}
Here's a fiddle: http://jsfiddle.net/DEwX8/124/
For bootstrap 4 just add this class:
w-100
Bootstrap 4 removed .btn-group-justified. As a replacement you can use <div class="btn-group d-flex" role="group"></div> as a wrapper around elements with .w-100.
Try this:
<div class="btn-group d-flex" role="group>
<button type="button" class="btn btn-primary w-100">Submit</button>
<button type="button" class="btn btn-primary w-100">Cancel</button>
</div>
Angular - equal width button group
Assuming you have an array of 'things' in your scope...
Make sure the parent div has a width of 100%.
Use ng-repeat to create the buttons within the button group.
Use ng-style to calculate the width for each button.
<div class="btn-group"
style="width: 100%;">
<button ng-repeat="thing in things"
class="btn btn-default"
ng-style="{width: (100/things.length)+'%'}">
{{thing}}
</button>
</div>
<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.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="btn-group btn-block">
<button type="button" data-toggle="dropdown" class="btn btn-default btn-xs btn-block dropdown-toggle">Actions <span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span></button><ul role="menu" class="dropdown-menu"><li>Action one</li><li class="divider"></li><li><a href="#" >Action Two</a></li></ul></div>
Bootstrap 4
<ul class="nav nav-pills nav-fill">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Longer nav link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
Bootstrap 4 Solution
<div class="btn-group w-100">
<button type="button" class="btn">One</button>
<button type="button" class="btn">Two</button>
<button type="button" class="btn">Three</button>
</div>
You basically tell the btn-group container to have width 100% by adding w-100 class to it. The buttons inside will fill in the whole space automatically.

Twitter Bootstrap: Select element in Nav bar

I am having issues with <select> elements lining up in a bootstrap nav bar. I want the text from "Search for" all the way to the "Go!" button to be vertically aligned. It looks as if the button and selection elements are the same height, so I want them to be flush on the top and bottom.
Here's the code:
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="#">Project</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li class="active"><i class="icon-home"></i> Home</li>
</ul>
<form class="navbar-search pull-right">
<div>Search for
<select class="span2">
<option>Things</option>
</select> in
<select class="span2">
<option>City, NY</option>
</select>
<button type="button" class="btn btn-primary">Go!</button>
</div>
</form>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
Here's a jsFiddle with an example. http://jsfiddle.net/jefe317/EjS6f/2/
Both Firefox and Chrome show similar results
Rohit's answer kind of works but can leave the text off center a little. You can also remove the margin-bottom from the select:
select[class*="span"] {
margin-bottom: 0;
}
That should even everything out.
http://jsfiddle.net/EjS6f/5/
Demo
Hi #Jeff Lange Now define your button margin-top:0; and add to vertical-align:top;
As like this
.btn.btn-primary{
margin-top:0 !important;
vertical-align: top;
}
Demo
I had a similar problem but I fixed it with:
<select class="span2 navbar-btn">
<option>Things</option>
</select> in
<select class="span2 navbar-btn">
<option>City, NY</option>
</select>
<button type="button" class="btn btn-default navbar-btn">Go!<button>

Resources