align horizontal navigation menu - css

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>

Related

CSS Drop Down Selection Issue

The problem I am having is that once I have selected a menu option, there is no drop down for that menu option that is currently selected. I can't seem to find the right answer nor able to Google the right question to get an answer.
The whole drop down works perfectly fine otherwise, except if I select a drop down menu item like "Drivers" then if I re-highlight "Drivers" once it's already selected, there is now no drop down there. I would have to select say.. "Home" first then the unselected "Drivers" option now has the drop down menu appear.
I hope I have made what I'm asking clear enough, now here is my code.
CSS:
/***** Begin Menu CSS *****/
ul {
width: 100%;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a, .dropbtn{
display: inline-block;
font-size: 15px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
border-right: 1px solid #bbb;
}
/* Color of the main menu text when hovering */
li a:hover {
background-color: red;
}
/* Once the mouse has moved off the main menu button and is now highlighting a sub menu button, this defines what that main menu button color is */
.dropdown:hover{
background-color: red;
}
/* Color of main menu button when not selected */
.dropbtn {
background-color: 333;
}
li .dropdown {
position:relative;
display: inline-block;
}
li:last-child {
border-right: none;
}
.dropdown-content{
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 5px 7px 5px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content a{
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
background-color: #f6f6f6; /* Sets background color of the drop down menu (not selected) */
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #ccc}
.dropdown:hover .dropdown-content{
display: block;
}
/* I have no idea what this does as it appears nothing...
li a:hover:not(.active) {
background-color: #blue;
} */
.active {
background-color: #990000;
}
.active dropdown-content{
display: none;
position: absolute;
min-width: 160px;
box-shadow: 5px 7px 5px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.active dropdown-content a{
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/***** End Menu CSS *****/
And here is my HTML:
//PHP Function
function Active($menuselection, $page){
if($page == "$menuselection"){
echo "active";
}else{
echo "dropdown";
}
}
(HTML)
<table width="100%">
<tr>
<td>
<ul>
<li>
<a class="<?=Active("menu.php", $webpage); ?>" href="menu.php">Home</a>
</li>
<li class="<?=Active("tms.php", $webpage); ?>">
Territory Manager
<div class="dropdown-content">
Add TM
Search TM
</div>
</li>
<li class="<?=Active("sales.php", $webpage); ?>">
Sales
<div class="dropdown-content">
Add Sales Person
Search Sales
</div>
</li>
<li class="<?=Active("drivers.php", $webpage); ?>">
Drivers
<div class="dropdown-content">
Add Driver
Search Drivers
</div>
</li>
<li class="<?=Active("passengers.php", $webpage); ?>">
Passengers
<div class="dropdown-content">
Add Passenger
Search Passengers
</div>
</li>
</ul>
</td>
</tr>
</table>
Any help would be greatly appreciated.
Here is the HTML rendered when I select "Drivers" (no PHP)
<table width="100%">
<tr>
<td>
<ul>
<li>
<a class="dropdown" href="menu.php">Home</a>
</li>
<li class="dropdown">
Territory Manager
<div class="dropdown-content">
Add TM
Search TM
</div>
</li>
<li class="dropdown">
Sales
<div class="dropdown-content">
Add Sales Person
Search Sales
</div>
</li>
<li class="active">
Drivers
<div class="dropdown-content">
Add Driver
Search Drivers
</div>
</li>
<li class="dropdown">
Riderz
<div class="dropdown-content">
Add Passenger
Search Passengers
</div>
</li>
</ul>
</td>
</tr>
</table>
Try adding this to your code:
.active:hover .dropdown-content{
display: block;
}

Bootstrap3 CSS Style Input

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.

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

Prevent shaky div when the button is clicked

I added a border-bottom to the button and when button is clicked border-bottom is removed and button is moved 3px down to create press effect. But when button is clicked the div below the active div also moves down and up.
This screenshot can make things clear.
HTML
<div id="contactus">
<a class="dropcontact" href="javascript:void(0)">Contact Us</a>
<div id="contact-container" class="body">
<ul>
<li><input type="text" placeholder="Name" /></li>
<li><input type="text" placeholder="Email" /></li>
<li><textarea placeholder="Message"></textarea></li>
<li><input type="submit" value="send"></li>
</ul>
</div>
</div>
<footer>
<div id="footer-container" class="body">
<span>© All Rights Reserved 2014. Design By Mohit Chawla.</span>
<div class="social">
<img src="images/social/facebook-3-128.png" alt="">
<img src="images/social/pinterest-4-128.png" alt="">
<img src="images/social/twitter-4-128.png" alt="">
</div>
</div>
</footer>
CSS of the button
#contact-container input[type="submit"]{
border: none;
background-color: #f4f4f4;
color: #ffb851;
padding: 10px;
font-size: 16px;font-size: 1.6rem;
border-radius: 5px;
border-bottom: 3px solid #e5e5e5;
cursor: pointer;
}
#contact-container input[type="submit"]:active{
position: relative;
top: 3px;
border-bottom: 0px;
}
Don't change the border width, change the border colour:
#contact-container input[type="submit"]:active{
position: relative;
top: 3px;
border-bottom: 3px solid transparent;
}
This way the sizes remain constant, and don't affect the layout/sizing.

Why won't this align middle or bottom?

OK, so my stupid little login form almost looks how I want it to look. (This is basically my first CSS project ever and first HTML project since updating attempting to update my 15 year old HTML skills.) For the life of me, I can't figure out how to get the "forgot password?" link to move down, either aligned with the middle or bottom of the "Login" button. I've tried moving the display: inline; and vertical-align: middle; to all kinds of different selectors and none of them work! I've even tried setting the height of the anchor and/or the <li> elements. I don't understand what the deal is! Any help is greatly appreciated!
Here is my code:
form.login {
margin: 10px 10px 20px 20px;
padding: 0 0 0 0;
}
form.login fieldset{
margin: 0 0 0 0;
padding: 2px 2px 2px 2px;
border:2px solid;
border-radius: 5px;
width: 348px;
height: 90px;
}
form.login fieldset legend {
font-weight: bold;
font-size: 1.2em;
margin-left: 10px;
}
form.login fieldset ul {
margin: 0;
padding:0;
}
form.login fieldset fieldset {
border: 0;
width: 100%;
height: 40%;
display: inline;
vertical-align: middle;
}
form.login fieldset fieldset li{
float: left;
list-style: none;
width: 165px;
margin: 0 4px 0 4px;
}
form.login input {
width: 165px;
}
form.login label {
display: none;
}
form.login a:link,
form.login a:visited {
color: black;
font-size: 0.8em;
}
form.login a:hover {
color: blue;
}
form.login a:active {
color: blue;
}
form.login fieldset ul fieldset li button#submitLogin {
float: right;
}
and the HTML:
<html>
<head>
<link rel="stylesheet" type="text/css" href="formstyle.css" />
</head>
<body>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" class="login">
<fieldset>
<legend>Login</legend>
<ul>
<fieldset>
<li>
<label for="email">Email Address</label>
</li>
<li>
<input id="email" type="text" name="email">
</li>
<li>
<label for="password">Password</label>
</li>
<li>
<input id="password" type="password" name="password">
</li>
</fieldset>
<fieldset>
<li>
Forgot Password?
</li>
<li>
<button id="submitLogin" value="submit" name="submitLogin" type="submit">Login</button>
</li>
</fieldset>
</ul>
</fieldset>
</form>
</body>
</html>
EDIT:
Here's a screen shot of what it looks like with the code above.
Try changing:
<li class="middle">
Forgot Password?
</li>
<li class="middle">
<button id="submitLogin" value="submit" name="submitLogin" type="submit">Login</button>
</li>
and add this to your css:
.middle {
height: 22px;
line-height: 22px;
}
This explicitly gives it a set-height and and then through the line-heightproperty tells it to center the text and form objects in the li vertically.
I reworked your markup to remove the fieldsets and to make the style's more consistent. What I am doing here is making the li's all half of the width and height of the UL. That way, if you want to changed the fieldset's height and/or width, you just have to change the one spot and maybe tweak your other styles.
I also condensed and removed some other unnecessary property declarations (padding: 0 0 0 0 to padding: 0). Let me know if you have any questions.
EDIT
I worked on it to make it more consistent between Chrome and Firefox.
And I actually think you'd be better putting the height on the li elements:
http://jsfiddle.net/QRNBg/13/
Try viewing the above and run it while commenting out the display: none on the CSS .hide class declaration.
CSS
form.login {
margin: 10px 10px 20px 20px;
padding: 0;
font-size: 1.2em;
}
form.login fieldset {
margin: 0;
padding: 5px;
border: 2px solid;
border-radius: 9px;
display: inline-block;
}
form.login fieldset legend {
font-weight: bold;
font-size: 1.2em;
margin-left: 10px;
}
form.login fieldset ul {
margin: 0;
padding: 0;
height: 90px;
width: 348px;
}
form.login fieldset ul li {
width: 50%;
height: 45%;
float: left;
list-style: none;
margin: 0;
padding: 0;
text-align: left;
}
form.login input {
border: 1px solid #aaa;
}
form.login input,
form.login li.common a {
width: 93%;
height: 80%;
display: block;
margin: 5px;
font-size: 1em;
}
form.login .hide {
display: none;
}
form.login a:link,
form.login a:visited {
color: black;
font-size: 0.8em;
}
form.login a:hover,
form.login a:active {
color: blue;
}
form.login li.common {
text-align: left;
display: table-cell;
line-height: 2.5em;
}
#submitLogin {
text-align: right;
margin: 0 5px 0 -5px;
}
#submitLogin button {
padding: 5px 8px;
}
HTML
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" class="login">
<fieldset>
<legend>Login</legend>
<ul>
<li class="hide">
<label for="email">Email Address</label>
</li>
<li>
<input id="email" type="text" name="email">
</li>
<li class="hide">
<label for="password">Password</label>
</li>
<li>
<input id="password" type="password" name="password">
</li>
<li class="common">
Forgot Password?
</li>
<li id="submitLogin" class="common">
<button value="submit" name="submitLogin" type="submit">Login</button>
</li>
</ul>
</fieldset>
</form>
http://jsfiddle.net/QRNBg/11/
you want it beside the login button, yet you define it in an 'li' tag before the login button? have you tried putting that anchor in the same 'li'? using a 'table' and putting them in the same 'tr' would work for sure.
Here's a quick fix. http://jsfiddle.net/xNAnz/
I offset the li 10px from the top.

Resources