I'm sorry if the title is confusing, the actual problem is very simple to understand.
I have a bootstrap responsive navbar which toggles between mobile and desktop view at 768px breakpoint.
However, I would like it to keep the mobile navbar til 992px breakpoint.
Because above 768px wide, this is how the menu looks
So I added a media query to the css to fix that
#media (min-width: 768px) and (max-width: 992px) {
.navbar-header {
float: none;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.navbar-fixed-top {
top: 0;
border-width: 0 0 1px;
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
margin-top: 7.5px;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.collapse.in{
display:block !important;
}
}
Now the mobile menu toggles at 992px but the sub-menus are not displaying in their correct position above 768px and below 992px
How can I fix that?
And am I doing the media queries correctly?
jsFiddle: https://jsfiddle.net/8zne82d2/7/
You should also target .navbar-nav .open .dropdown-menu
Try to add something like this:
#media (max-width: 992px) {
.navbar-nav .open .dropdown-menu {
position: static;
float: none;
width: auto;
margin-top: 0;
background-color: transparent;
border: 0;
-webkit-box-shadow: none;
box-shadow: none;
}
}
Example here https://jsfiddle.net/8zne82d2/9/
Related
I am having difficulty in rendering the dropdown menu properly on my website www.bg-hairsalon.com It is a wordpress website that utilizes the theme Zerif-Lite. It doesn't show the options when I click on the navigation button. However, if I scroll down and then click on the navigation toggle button it displays the menu. I am using android and iphone both to test my website. If you could take a look that would be great. I was using android to test this menu. This doesn't work on iphone as well.
The code I am using for the navigation menu so far is as follows:
Not sure how much of this code do I need.
#media screen and (max-width: 480px){
.navbar {
background: #FFF;
border: 0;
border-radius: 0 !important;
text-align: left;
-webkit-box-shadow: 0px 5px 11px 0px rgba(50, 50, 50, 0.08);
box-shadow: 0px 5px 11px 0px rgba(50, 50, 50, 0.08);
}
}
#media screen and (max-width: 480px){
#main-nav {
position: fixed;
width: 100%;
z-index: 1000;
min-height: 75px;
}
}
#media screen and (max-width: 480px){
#main-nav.fixed {
position: fixed;
top: 0;
}
}
.nav li a.nav-active {
color: #b8db4d !important;
}
.nav li a.nav-active:before {
position: absolute;
margin: auto;
z-index: 1;
content: "";
width: 75%;
height: 2px;
background: #b8db4d;
bottom: 0px;
left: 12.5%;
}
.navbar-inverse .navbar-nav >li {
display: inline;
margin-right: 20px;
margin-top: 20px;
}
.navbar-inverse .navbar-nav>li:last-child {
margin-right: 0 !important;
}
.navbar-inverse .navbar-nav>li>a {
color: #404040;
padding: 0;
line-height: 35px;
}
.navbar-inverse .main-navigation ul > li {
display: inline;
margin-right: 20px;
margin-top: 20px;
}
.navbar-inverse .main-navigation > ul > li:last-child {
margin-right: 0 !important;
}
.navbar-inverse .main-navigation > ul > li > a {
color: #404040;
padding: 0;
line-height: 35px;
}
.navbar-inverse .navbar-nav ul.sub-menu {
display: none;
position: absolute; top: 100%;
background:#fff;
width:200px;
box-shadow: 3px 3px 2px rgba(50, 50, 50, 0.08);
}
.navbar-inverse .navbar-nav ul.sub-menu {
margin:0;
}
.navbar-inverse .navbar-nav ul.sub-menu ul.sub-menu{
position: absolute;
left:100%;
top:0;
}
.navbar-inverse .navbar-nav ul.sub-menu li {
float: none;
position: relative;
list-style:none;
padding:10px;
}
.navbar-inverse .navbar-nav ul.sub-menu li a {
color:#404040;
}
.navbar-inverse .navbar-nav ul.sub-menu li:hover > a {
color:#b8db4d;
}
.navbar-inverse .navbar-nav li:hover > ul.sub-menu {
display: block;
}
.navbar-brand {
height: 76px;
position: relative;
line-height: 45px;
}
.current a {
color: #b8db4d !important;
position: relative;
outline: none;
}
.current:before {
position: absolute;
margin: auto;
z-index: 1;
content: "";
width: 75%;
height: 2px;
background: #b8db4d;
bottom: 0px;
left: 12.5%;
}
.navbar-inverse .navbar-nav>li>a:hover {
color: #b8db4d;
outline: none;
}
#media screen and (max-width: 480px){
.navbar-toggle {
border: 0;
background-color: #808080;
margin-top: 23px;
}
}
.navbar-inverse .navbar-toggle:hover,.navbar-inverse .navbar-toggle:focus {
background-color: #b8db4d;
filter: alpha(opacity=100);
opacity: 1;
box-shadow: none;
}
#media screen and (max-width: 480px){
.navbar-toggle.active{
background-color: #b8db4d !important;
}
}
#media screen and (max-width: 480px){
.navbar-toggle.collapsed{
background-color: #808080 !important;
}
}
Trying to make the navigation align left and line break like a normal paragraph. At the moment it seems to break weirdly when hovering.
Example:
Hoping to achieve the below which is only working when I hover on a certain link.
Code:
#media screen and (max-width: 1024px) {
li {
float: left;
padding-right: 8px;
font-size: 14px;
margin-bottom: 20px;
display: inline-block.
}
li a:hover {
border-bottom: 2px solid;
padding-bottom: 1px;
}
nav.isotope-filters ul li a:active,
nav.isotope-filters ul li a.selected {
border-bottom: 2px solid;
padding-bottom: 1px;
}
}
I though inline-block would resolve this issue but it's not.
float are the guilty. Don't use floats when there aren't nothing to float. And don't mix float with inline-block. Float transform all displays in block.
#media screen and (max-width: 1024px) {
li {
padding-right: 8px;
font-size: 14px;
margin-bottom: 20px;
display: inline-block;
float: none;
}
li a:hover {
border-bottom: 2px solid;
padding-bottom: 1px;
}
nav.isotope-filters ul li a:active,
nav.isotope-filters ul li a.selected {
border-bottom: 2px solid;
padding-bottom: 1px;
}
}
This plain code(btw, I took it from another stackoverflow poste) works as the red div#wrapper reaches from top to bottom...
<html>
<head>
<style media="screen">
#wrapper {
height:100%;
width:300px;
background-color:red;
}
#first {
background-color:#F5DEB3;
height: 200px;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="first"></div>
</div>
</body>
</html>
but when I integrate this to a wordpress+bootstrap+timber theme it's not working... even with a html,body{height: 100% } written in style.css...
I'm not sure if this is bootstrap or wordpress related problem...
hmtl, body{
height: 100%!important;
}
#wrapper {
height:100%!important;
background-color:red;
}
.navbar-brand-image{
margin: 0 auto;
}
#media (max-width: 1000px) {
.navbar-header {
float: none;
}
.navbar-toggle {
display: block;
float: none;
text-align: center
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
margin: 7.5px -15px;
width: 100%;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.navbar-text {
float: none;
margin: 15px 0;
}
/* since 3.1.0 */
.navbar-collapse.collapse.in {
display: block!important;
}
.collapsing {
overflow: hidden!important;
}
}
.navbar{
margin-bottom: 0px
}
.navbar .navbar-nav a{
color: #fff;
font-weight: bold
}
.navbar .navbar-nav a:hover{
background-color: rgba(0, 0, 0, 0.2);
}
.navbar .navbar-nav {
display: inline-block;
float: none;
}
.navbar .navbar-collapse {
text-align: center;
}
Without seeing the rest of the CSS in the page it's not possible to pinpoint the problem. You can however add an !important to the height element to ignore any CSS inheritance.
#wrapper {
height:100% !important;
width:300px;
background-color:red;
}
When you use these libraries there are big chances of them override in your code.
To check if this is the case place !important at the end of your css properties.
Example:
#wrapper {
height:100% !important;
width:300px !important;
background-color:red !important;
}
I use the following code to style my navigation: External codePen
/*--- Navigation Main ---*/
.nav {
margin: 0px;
background-color: rgb(200,216,239)
}
ul.topnav {
display: block;
list-style-type: none;
margin: 0 450px 0;
padding: 0;
overflow: hidden;
position: relative;
border-bottom: solid 1px
}
ul.topnav li {
float: left;
}
ul.topnav li a {
display: block;
text-align: center;
padding: 1px 15px;
text-decoration: none;
height: 65px;
line-height: 70px;
}
ul.right {
margin: auto;
float: right;
list-style-type: none;
border-bottom: 1px
}
#club-name {
border-bottom: 1px firebrick;
}
/*--- Navbar colors ---*/
ul.topnav li a:hover:not(.active) {
background-color: rgb(144,149,158);
color: rgb(198, 218, 238);
}
ul.topnav li a:active:not(.active) {
background-color: rgb(46,53,66);
color: rgb(198, 218, 238);
}
ul.topnav li a.active {
background-color: firebrick;
}
/*--- Pseudoclasses ---*/
nav a:link {
color: rgb(144,149,158);
text-decoration: none;
}
a:visited {
color: rgb(144,149,158);
}
/*--- Small Screen view ---*/
#media (max-width: 600px){
nav {
margin: 0px;
}
ul.right,
ul.topnav li {
float: none;
text-align: center;
}
}
/*--- fonts ---*/
#club-name {
font-family: Bevan;
font-size: 20px;
color: aliceblue
}
ul.topnav ul.right li {
font-family: Pontano Sans;
font-size: 20px;
font-weight: bolder;
}
<div class="nav">
<ul class="topnav">
<li><a id="club-name" class="active" href="index.html">Hercules</a></li>
<ul class="topnav right">
<li>The Team</li>
<li>Facilities</li>
<li>Membership</li>
</ul>
</ul>
</div>
My styling works as I want until I set ul.topnav { margin: 0 350px 0; }.
If you update this margin to 0 and make the window smaller, you will see the effect I achieved before, but once I applied margins, the collapsible effect does not work anymore.
Hope someone can help, or offer me a different solution.
When you set the ul.topnav margin to 350px, the ul.topnav li elements start to run into each other and wrap before the breakpoint is reached as the screen size gets smaller. You can achieve an effect similar to the one you achieved before you applied the margins by setting the margins for ul.topnav to 0 auto, and then setting the max-width for this element to 800px or so. This provides some space on either side of the ul.topnav at larger screen sizes, ensures the ul.topnav li elements don't get too squished at smaller screen sizes, and allows your breakpoint to work as expected.
The CSS for ul.topnav in this solution looks like this:
ul.topnav {
display: block;
list-style-type: none;
margin: 0 auto;
max-width: 800px;
padding: 0;
overflow: hidden;
position: relative;
border-bottom: solid 1px
}
I changed bootstrap's navbar collapse at 992px breakpoint but it still show me dropdown menu
http://imgur.com/WR4LS2o,qHvd6RH#0
using this standard css code
#media (max-width: 991px) {
header nav.navbar-main.clearfix {
background-color: transparent;
}
.navbar-header {
float: none;
}
.navbar-left,.navbar-right {
float: none !important;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.navbar-fixed-top {
top: 0;
border-width: 0 0 1px;
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
background-color: white;
float: none!important;
margin-top: 7.5px;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.collapse.in{
display:block !important;
}
}
How can i do?
(I'm sorry for the external link but i dont have enought reputation to link an image)
The first method is to generate a custom bootstrap in overiding the
breakpoints.
( I think it's the best way because it does the whole job alone )
The second method is too add this css lines to your given code :
.navbar-nav .open .dropdown-menu {
position: static;
float: none;
width: auto;
margin-top: 0;
background-color: transparent;
border: 0;
-webkit-box-shadow: none;
box-shadow: none;
}
.navbar-nav .open .dropdown-menu .dropdown-header, .navbar-nav .open .dropdown-menu>li>a {
padding: 5px 15px 5px 25px;
}
.navbar-nav .open .dropdown-menu>li>a {
line-height: 20px;
}
.navbar-default .navbar-nav .open .dropdown-menu>li>a {
color: #777;
}
You can find a fiddle with a default navbar here
Solved in this way
#media (max-width: 991px) {
.navbar-main .navbar-nav li ul {
display: block;
position: inherit;
left: auto;
top: auto;
width: 100%;
background: transparent;
padding: 0 0 0 10px;
z-index: 1;
box-shadow: none;
}
.navbar-collapse.collapse.in {
overflow-y: auto;
}
}