Bootstrap3 CSS Style Input - css

I am trying to make a search field with a dropdown inside. I have been trying to use bootstrap's input group to give the illusion that the button is inside the field.
This is what I am trying to accomplish in the screenshot below:
This is what I have so far:
I am trying to figure out how to get the dropdown menu to move over to the far right of the search field and get that carrot to show as well.
Any tips on adjusting the position of the menu as well as making that dropdown button have no color on hover?
<div class="container div-cntr">
<div class="form-group">
<div class="input-group">
<input type="text" class="form-control input-lg" id="toolSearch" name="toolSearch" placeholder="What are you looking for?">
<div class="input-group-btn">
<button aria-expanded="false" aria-haspopup="true" data-toggle="dropdown" class="btn btn-default btn-lg dropdown-toggle filterOptions" type="button"> <span class="caret"></span> <span class="sr-only">Toggle Dropdown</span> </button>
<ul class="dropdown-menu">
<li><input type="checkbox"/> Option 1</li>
<li><input type="checkbox"/> Option 2</li>
</ul>
</div>
</div>
<br />
<button type="button" class="btn btn-default btn-lg">Search</button>
</div>
</div>
-
.div-cntr {
left: 50%;
margin-left: -350px;
margin-top: -150px;
min-height: 150px;
position: absolute;
text-align: center;
top: 50%;
width: 700px;
}
.filterOptions{
border-left: 0px;
}
.btn-lg {
line-height: 1.22;
}
#toolSearch:focus {
outline:none;
}
Here is a fiddle I have set up: https://jsfiddle.net/carlhussey/tfrpncu7/

Here is the CSS you need to accomplish what you indicated you wanted:
.dropdown-menu {
right: 0; /* Align dropdown-menu to right instead of left */
left: auto;
}
.input-group .dropdown-toggle.filterOptions {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
z-index: 5; /* Fix for 2 input-group-btns and this one not being the last-child */
}
.dropdown-menu>li>a:focus,
.dropdown-menu>li>a:hover {
background-color: transparent; /* Fix for dropdown-menu item hover background-color */
}
Here is what it looks like:
I went ahead and updated your Fiddle:
https://jsfiddle.net/tfrpncu7/3/

You should be using input-group-lg along with input-group and dropdown-menu-right to position the dropdown menu correctly. For the other CSS use pseudo elements.
Working Example: (The level of specificity is so the example works on Stackoverflow.)
.div-cntr {
margin-top: 100px;
text-align: center;
max-width: 700px;
/*for example only*/
background: red;
min-height: 300px;
/*for example only*/
}
.form .open>.dropdown-toggle.filterOptions.focus,
.form .open>.dropdown-toggle.filterOptions:focus,
.form .open>.dropdown-toggle.filterOptions:hover .input-group-lg>.form-control,
.form .input-group.input-group-lg>.input-group-btn>.filterOptions {
border: 1px solid #ccc;
border-left: 0;
outline: none;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
border-radius: 0;
background: #fff;
}
.form .dropdown-menu.dropdown-menu-search {
top: 60px;
right: 110px;
border-radius: 0;
border: 0;
background: #fff;
}
.form .dropdown-menu.dropdown-menu-search:after {
top: -15px;
right: 10px;
position: absolute;
content: '';
border-width: 0px 15px 15px 15px;
border-style: solid;
border-color: #fff transparent;
height: 0;
width: 0;
}
.form .form-control.toolSearch,
.form .form-control.toolSearch:focus {
outline: none;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
border-radius: 0;
border: 1px solid #ccc;
border-right: 0;
}
.form .input-group-btn .btn.btn-search,
.form .input-group-btn .btn.btn-search.active {
border-radius: 0;
border: 1px solid #ccc;
border-left: 0;
}
.form .input-group-btn .btn.btn-search:hover,
.form .input-group-btn .btn-search:focus {
outline: none;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
border: 1px solid #ccc;
border-left: 0;
border-radius: 0;
background: #fff;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container div-cntr">
<div class="form-group form">
<div class="input-group input-group-lg">
<input type="text" class="form-control toolSearch" id="toolSearch" name="toolSearch" placeholder="What are you looking for?">
<div class="input-group-btn">
<button aria-expanded="false" aria-haspopup="true" data-toggle="dropdown" class="btn btn-default btn-lg dropdown-toggle filterOptions" type="button"> <span class="caret"></span> <span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu dropdown-menu-right dropdown-menu-search">
<li>
<a href="#" class="small" data-value="option1" tabIndex="-1">
<input type="checkbox" /> Option 1</a>
</li>
<li>
<a href="#" class="small" data-value="option2" tabIndex="-1">
<input type="checkbox" /> Option 2</a>
</li>
<li>
<a href="#" class="small" data-value="option3" tabIndex="-1">
<input type="checkbox" /> Option 3</a>
</li>
<li>
<a href="#" class="small" data-value="option4" tabIndex="-1">
<input type="checkbox" /> Option 4</a>
</li>
<li>
<a href="#" class="small" data-value="option5" tabIndex="-1">
<input type="checkbox" /> Option 5</a>
</li>
<li>
<a href="#" class="small" data-value="option6" tabIndex="-1">
<input type="checkbox" /> Option 6</a>
</li>
</ul>
<button role="button" class="btn btn-lg btn-default btn-search"><span class="glyphicon glyphicon-search"></span> Search</button>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

Here's a Fiddle with the position of the dropdown set, and the button with a white background on `:active'. Let me know if this is what you were looking for.
https://jsfiddle.net/tobyl/4p41p3kg/2/
Added CSS:
.dropdown-menu {
left: auto;
right: 0;
}
.open > .dropdown-toggle.btn-default:active, .open > .dropdown-toggle.btn-default:focus {
background-color: #fff;
}

I'll start by answering the second part of your question
Making that dropdown button have no color on hover
Chrome dev-tools (right click any element of the page and select Inspect element) can help a lot when it comes to styling elements under certain states (like hover). To see which style rule is applied during hover we can force the hover state on the button through dev-tools. We see that .btn-default is applying
.btn-default:hover {
color: #333;
background-color: #e6e6e6;
border-color: #adadad;
}
Since this button has the following class precedence
<button class="btn btn-default btn-lg dropdown-toggle filterOptions"> (classes to the right override rules from classes to the left)
We can override the hover styles of .btn-default by making a rule for the hover state of filterOptions.
.filterOptions:hover {
background-color: white;
border-color: #ccc;
}
Adjusting the position of the menu as well as
Again by inspecting the dropdown element in dev-tools we can see that the correct style rule to override the default positioning and make the dropdown position to the right would be:
.open>.dropdown-menu {
right: 0;
left: initial;
}
Updated fiddle:
https://jsfiddle.net/tfrpncu7/4/
Remember, css has no scoping what so ever so it's a good idea to always apply new non-bootstrap classes when styling a specific element.
If your project is large, consider using a css naming convention like BEM to keep the risk of naming collisions low.

Related

align horizontal navigation menu

i have a horizontal navigation bar.
i wish to add a search bar to the navigation bar, but when i insert it, my navigation bar is misaligned.
https://jsfiddle.net/r6ntxg2f/
as you can see my menu is hovering above the green line, and the right side menu is hovering even more. i wish to align the whole menu to the green line.
<li id="searchbar">
<form id="search" method="post" style="">
<input id="bb" type="text" style="" />
<input id="cc" type="submit" value="Search" style="" />
</form>
</li>
this is how it is without search. https://jsfiddle.net/q476f585/ (working)
Seems like your sizes and padding was causing the issue, see the jsfiddle for an updated solution. All I done was updated the padding and display style. For the bottom border you will have to ensure that the other padding on the first two buttons are correct.
You can fix the issue by adjusting padding. Here is the working code.
ul#menu_left {
position: relative;
left: 100px;
width: 75%;
font: 75% verdana;
list-style-type: none;
padding: 10px 10px 5px 10px;
border-bottom: 1px solid green;
}
ul#menu_right {
padding-right: 10px;
float: right;
padding-top: 2px
}
ul#menu_left li {
display: inline;
}
ul#menu_left li a {
padding: 6px 4px;
border-bottom: 1px solid green;
text-decoration: none;
color: white;
background-color: green;
}
ul#menu_left a:hover {
color: black;
background: yellow;
border-bottom: 1px solid yellow;
}
li#searchbar {
background-color: green;
padding: 6px 4px;
border-bottom: 1px solid green;
}
li#searchbar form {
display: inline;
}
li#searchbar input {
width: 50px;
}
<ul id="menu_left">
<li><a id="tab1" href="#">The We</a>
</li>
<li><a id="tab2" href="#">Book</a>
</li>
<li><a id="tab3" href="#">Tab</a>
</li>
<li id="searchbar">
<form id="search" method="post">
<input id="bb" type="text" />
<input id="cc" type="submit" value="Search" />
</form>
</li>
<ul id="menu_right">
<li><a id="tab5" style="" href="#">Up</a>
</li>
<li><a id="tab6" href="#">Contact</a>
</li>
</ul>
</ul>

Font Awesome - When stacking icons, how can I center the second icon

When stacking icons, how can I center the second icon?
I'm trying to create a white background for a circle and a checkbox see plnkr example:
http://plnkr.co/5JM1yk6eoeAnj1VgkxXA
<span class="fa-stack">
<i class="fa fa-circle-thin fa-stack-2x"></i>
<i class="fa fa-check-circle fa-stack-2x"></i>
</span>
input[type="checkbox"]:checked + label .fa-check-circle {
display: block;
background: white;
border-radius: 50%;
color: #37B34A;
height: 28px;
width: 28px;
}
.fa-circle-thin {
color: #DDDDDD;
background-color: #FFFFFF;
border-radius: 50%;
height: 28px;
width: 28px;
text-align:center;
cursor: pointer;
}
Giving a margin-left to .fa-stack .fa-check-circle will do it
.fa-stack .fa-check-circle {
margin-left: 2px;
}
Although I think this is not the best way of doing what you're trying to do there, I think this way should be a better way of doing it: http://jsfiddle.net/7w41fboo/
======== Update =========
If you need to remove the white space of the background of your checked circle, you can do it with this trick. First exchange the fa-check-circle for fa-check like this:
HTML
<div class="faWhiteBg">
<input type="checkbox">
<label>
<span class="fa-stack">
<i class="fa fa-circle-thin fa-stack-2x"></i>
</span>
Unchecked
</label>
</div>
<br />
<input type="checkbox" checked>
<label>
<span class="fa-stack">
<i class="fa fa-check"></i>
</span>
Checked
</label>
Then style your fa-check in your CSS
.fa-stack .fa-check {
background: #37B34A;
color: #fff;
font-size: 22px;
padding: 5px;
border-radius: 50%;
}
.fa-stack {
cursor: pointer;
}
/* The code below is a code to display the white background only for the non checked circle, if you don't want it you can remove this part of the code and remove it from your HTML as well*/
.faWhiteBg .fa-stack {
background: #fff;
border-radius: 50%;
}
Here's an online example

Custom button, that doesn't want to work properly when I am switching to another language

I am trying to create a button just like this one. This button already works fine in the English version, but when I switch to french, it breaks. The French text is much longer, and the button breaks into two separate parts. Any ideas how I can create a "responsive" (text size relative) button?
My code:
<div class="row-fluid">
<div class="text-box text-center"><p>View By</p></div>
<div class="btn-group pull-right small-tab" style="padding-right:20px">
<button class="btn dropdown-toggle" data-toggle="dropdown">
<span class="fa fa-bars"></span>
</button>
<ul class="dropdown-menu pull-right">
<li </li>
<li </li>
<li </li>
</ul>
</div>
</div>
.text-box {
display: inline-block;
height: 27px;
min-width: 70px;
border: 1px solid #c2c2c2;
border-radius: 3px 0 0 3px;
font-size: 14px;
padding: 1px 0 0 0;
margin-right: -1px;
text-align: center;
margin-left: 225px;
p {
margin-top: 5px;
}
}
.small-tab {
.btn:first-child {
border-radius: 0px 3px 3px 0px;
}
}
.btn-group.open .btn.dropdown-toggle {
background-color:#1388e2;
}
.btn {
color:#ffffff;
background-color:#46a9f8;
border: none;
}
.btn:hover {
color:#ffffff;
background-color:#128ded;
}

Convert Bootstrap 2.3.2 & jQuery-Spinner to work with Bootstrap 3.*

I am trying to convert xixilive's jQuery Spinner Plugin that uses Bootstrap 2.3.2 code into bootstrap 3.* Unfortunately it's not working as it should be, along with no JavaScript errors, so I believe it's just a CSS issue.
Here is what I have done so far:
HTML/CSS
<div class="input-group spinner" data-trigger="spinner">
<input type="text" value="0"
data-min="0"
data-max="10"
name="spinner"
id="spinner"
data-rule="quantity" readonly />
<span class="input-group-btn">
<!-- Up arrow -->
<a href="javascript:;" class="spin-up" data-spin="up">
<i class="fa fa-sort-up"></i>
</a>
<!-- Down arrow -->
<a href="javascript:;" class="spin-down" data-spin="down">
<i class="fa fa-sort-down"></i>
</a>
</span>
</div>
Expected output
Demo Fiddle: http://jsfiddle.net/DAS3K/
I just solved it by myself. Here is the code if anyone is looking for solution
Replace bootstrap-spinner.css file with this one:
.spinner .input-group-btn {
padding: 2px
}
.spinner .input-group-btn a.spin-up, .spinner .input-group-btn a.spin-down {
height: 10px;
overflow: hidden;
display: block;
text-align: center;
position: relative;
color: #999
}
.spinner .input-group-btn a.spin-up .fa-sort-down, .spinner .input-group-btn a.spin-down .fa-sort-down {
position: relative;
top: -9px
}
.spinner .input-group-btn a.spin-up:hover, .spinner .input-group-btn a.spin-down:hover {
color: #555
}
.spinner input {
width: 4em;
text-align: center;
font-size: 12px;
border-radius: 4px 0 0 4px;
background-color: #FFFFFF;
border: 1px solid #CCCCCC;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;
transition: border 0.2s linear 0s, box-shadow 0.2s linear 0s;
line-height: 20px;
}
.spinner .input-group-btn {
background-color: #EEEEEE;
border: 1px solid #CCCCCC;
height: 20px;
line-height: 20px;
min-width: 14px;
padding: 4px 5px;
text-align: center;
text-shadow: 0 1px 0 #FFFFFF;
width: auto;
}
.spinner .input-group-btn a:focus {color: #999 !important; }
and use following HTML code
<div class="col-sm-1">
<div class="input-group spinner" data-trigger="spinner">
<input type="text" class="form-control" value="0" data-min="0" data-max="10" name="spinner" id="spinner" data-rule="quantity" >
<span class="input-group-btn">
<i class="fa fa-sort-desc"></i>
<i class="fa fa-sort-down"></i>
</span>
</div>
</div>
If you use to want use glyphicon instead of font-awesome then replace fa and fa-xxx classes in HTML and bootstrap.spinner.css file as well.
You could:
Wrap the buttons into a bootstrap add-on
Switch icon to glyphicon for the icon spinners, there's no direct suitable change though for the old to new icons thus I've adjusted for chevrons.
Swap input-group-btn to input-group-addon
This would produce HTML a little like:
<div class="input-append spinner" data-trigger="spinner">
<div class="input-group">
<input type="text" id="spinner-input" class="form-control" value="1" data-rule="quantity" />
<span class="input-group-addon">
<i class="glyphicon glyphicon-chevron-up"></i>
<br />
<i class="glyphicon glyphicon-chevron-down"></i>
</span>
</div>
</div>
I've had apply some extra CSS rules and the linebreak for the buttons could be handled instead with mini columns instead! but I hope that gives you an head-start regardless!
Result:
Demo Fiddle: http://jsfiddle.net/792hq/

Links not active in firefox with bootstrap buttons

I ran into a strange issue while building my wordpress site. All links that are inside the bootstrap buttons are not active in firefox.
What could cause this?
Here's the html output:
<button class="btn pull-right" role="button">
<a href="http://domain.dev/?cat=4" name="View all News">
All News
</a>
</button>
Here's the css:
.home #primary #home-more .btn {
background-image: url("../img/home-button-sprite-more.png");
background-repeat: no-repeat;
margin-right: 0px;
background-color: transparent;
padding: 13px 40px;
background-position: 20px 0px;
}
button.btn {
display: inline-block;
padding: 13px 24px;
margin-bottom: 0px;
margin-right: 10px;
font-size: 10px;
text-transform: uppercase;
font-weight: bold;
line-height: 1;
text-align: center;
vertical-align: middle;
cursor: pointer;
border: medium none;
border-radius: 0px 0px 0px 0px;
white-space: nowrap;
-moz-user-select: none;
}
Instead of,
<button class="btn pull-right" role="button">
<a href="http://domain.dev/?cat=4" name="View all News">
All News
</a>
</button>
You have to use,
<a href="http://domain.dev/?cat=4" name="View all News">
<button class="btn pull-right" role="button">
All News
</button>
</a>
Or,
<a href="http://domain.dev/?cat=4" title="View all News" class="btn pull-right">
All News
</a>
Try what #Devo has suggested else try this
<a class="btn btn-primary" href="http://domain.dev/?cat=4">All News</a>
Hope this helps.
Use this:
<div class="btn pull-right" role="button">
<a href="http://domain.dev/?cat=4" name="View all News">
All News
</a>
</div>
I think it should work

Resources