My mobile menu has large gaps in between the list items, my code does not help me, can anyone else see something?
This is most likely due to px or some other screen-scaled metric not translating properly onto the mobile resolution.
I have tried unsuccessfully to upload a supporting image.
html, body
{
font-family: "Lato", sans-serif;
width: 100%;
height: auto; margin: 0;
}
.nav {
background-color: #3333FF;
width: 100%;
height: 40px;
line-height: 40px;
}
.menu {
font-family: Monserrat, sans-serif;
font-size: 18px;
color: white;
list-style-type: none;
padding: 0;
position: relative;
z-index: 1;
}
.menu a {
text-decoration: none;
color: #fff;
line-height: 40px; /* Line height 40px, not 40-px */
}
.menu ul li {
text-align: center;
display: inline;
padding: 10px;
width: 11.11%;
}
.menu li:visited, .menu li:active, .active, .menu li:hover
{
background: #0000EE;
color: #fff;
}
label {
margin: 0 14px 0 0;
font-size: 20px;
display: none;
}
#toggle {
display: none;
}
/* Show Hamburger */
#media screen and (max-width: 500px) {
label {
cursor: pointer;
display: block;
color: #fff;
}
.menu {
text-align: center;
width: 100%;
display: none;
}
.menu a {
display: block;
background-color: #999;
margin:0;
padding: 0;
}
#toggle:checked + .menu {
display: block;
}
} /* A finishing bracket was missing */
Related
I'm sorry to ask this question because it has been largely posted, but I checked a lot of links and didn't solve it yet. I have a navbar with 2 elements and I cannot center it in the middle of the nav.
#menu {
background: #000000;
background: linear-gradient(to bottom, #973F8E, #DC4069);
color: #FFF;
height: 52px;
width: 500px;
padding-left: 18px;
border-radius: 50px;
border: 1px solid #000000;
margin: auto;
display:block;
text-align:center !important;
}
#menu ul, #menu li {
margin: 0 auto;
padding: 0;
list-style: none;
display: block;
text-align: center;
}
#menu ul {
width: 100%;
}
#menu li {
float: left;
display: inline;
position: relative;
}
#menu a {
display: block;
line-height: 50px;
padding: 0 14px;
text-decoration: none;
color: #FFFFFF;
font-size: 15px;
text-transform: uppercase;
}
#menu a.dropdown-arrow:after {
content: "\25BE";
margin-left: 5px;
}
#menu li a:hover {
color: #000000;
background: #FFA6AF;
}
#menu input {
display: none;
margin: 0;
padding: 0;
height: 52px;
width: 100%;
opacity: 0;
cursor: pointer
}
#menu label {
display: none;
line-height: 50px;
text-align: center;
position: absolute;
left: 35px
}
#menu label:before {
font-size: 1.6em;
content: "\2261";
margin-left: 20px;
}
#menu ul.sub-menus{
height: auto;
overflow: hidden;
width: 170px;
background: #444444;
position: absolute;
z-index: 99;
display: none;
}
#menu ul.sub-menus li {
display: block;
width: 100%;
}
#menu ul.sub-menus a {
color: #FFFFFF;
font-size: 16px;
}
#menu li:hover ul.sub-menus {
display: block
}
#menu ul.sub-menus a:hover{
background: #F2F2F2;
color: #444444;
}
<nav id="menu">
<input type='checkbox' id='responsive-menu' onclick='updatemenu()'><label></label>
<ul>
<li><a href='/'>DASHBOARD</a></li>
<li><a href='/model'>MODEL</a></li>
</ul>
</nav>
Probably in the large number of css elements I'm not able to see where the code is not working.
I posted the code here:
codepen
You should remove the left padding from the main #menu element, set the ul's display to inline-block and the width to auto (just remove the width property).
This will work because the #menu element has text-align: center. the ul will be centered since its width is not 100% (because width is set to auto and the display to inline-block).
#menu {
background: #000000;
background: linear-gradient(to bottom, #973F8E, #DC4069);
color: #FFF;
height: 52px;
width: 500px;
padding-left: 0; // remove this
border-radius: 50px;
border: 1px solid #000000;
margin: auto;
display:block;
text-align:center !important;
}
#menu ul, #menu li {
margin: 0 auto;
padding: 0;
list-style: none;
display: block;
text-align: center;
}
#menu ul {
display: inline-block; // and set this
}
#menu li {
float: left;
display: inline;
position: relative;
}
#menu a {
display: block;
line-height: 50px;
padding: 0 14px;
text-decoration: none;
color: #FFFFFF;
font-size: 15px;
text-transform: uppercase;
}
#menu a.dropdown-arrow:after {
content: "\25BE";
margin-left: 5px;
}
#menu li a:hover {
color: #000000;
background: #FFA6AF;
}
#menu input {
display: none;
margin: 0;
padding: 0;
height: 52px;
width: 100%;
opacity: 0;
cursor: pointer
}
#menu label {
display: none;
line-height: 50px;
text-align: center;
position: absolute;
left: 35px
}
#menu label:before {
font-size: 1.6em;
content: "\2261";
margin-left: 20px;
}
#menu ul.sub-menus{
height: auto;
overflow: hidden;
width: 170px;
background: #444444;
position: absolute;
z-index: 99;
display: none;
}
#menu ul.sub-menus li {
display: block;
width: 100%;
}
#menu ul.sub-menus a {
color: #FFFFFF;
font-size: 16px;
}
#menu li:hover ul.sub-menus {
display: block
}
#menu ul.sub-menus a:hover{
background: #F2F2F2;
color: #444444;
}
You can use flex positions.
Use property justify-content : center to center all children div inside a parent div. It's useful to distribute the space between or around the elements.
This will also make your CSS code lighter. The more CSS, the more difficult it is.
It's also good for responsive design.
I have also removed some CSS property. This code can be further improved and reduced. Good luck !
#menu {
background: #000000;
background: linear-gradient(to bottom, #973F8E, #DC4069);
color: #FFF;
height: 52px;
width: 500px;
// padding-left: 18px;
border-radius: 50px;
border: 1px solid #000000;
margin: auto;
// display:block;
// text-align:center !important;
}
#menu ul, #menu li {
margin: 0 auto;
padding: 0;
// list-style: none;
// display: block;
text-align: center;
}
#menu ul {
width: 100%;
display: flex;
justify-content: center;
}
#menu li {
// float: left;
margin : 0px;
display: inline;
// position: relative;
}
#menu a {
display: block;
line-height: 51px;
padding: 0 14px;
text-decoration: none;
color: #FFFFFF;
font-size: 15px;
text-transform: uppercase;
}
#menu a.dropdown-arrow:after {
content: "\25BE";
margin-left: 5px;
}
#menu li a:hover {
color: #000000;
background: #FFA6AF;
}
#menu input {
display: none;
margin: 0;
padding: 0;
height: 52px;
width: 100%;
opacity: 0;
cursor: pointer
}
#menu label {
display: none;
line-height: 50px;
text-align: center;
position: absolute;
left: 35px
}
#menu label:before {
font-size: 1.6em;
content: "\2261";
margin-left: 20px;
}
#menu ul.sub-menus{
height: auto;
overflow: hidden;
width: 170px;
background: #444444;
position: absolute;
z-index: 99;
display: none;
}
#menu ul.sub-menus li {
display: block;
width: 100%;
}
#menu ul.sub-menus a {
color: #FFFFFF;
font-size: 16px;
}
#menu li:hover ul.sub-menus {
display: block
}
#menu ul.sub-menus a:hover{
background: #F2F2F2;
color: #444444;
}
<nav id="menu">
<input type='checkbox' id='responsive-menu' onclick='updatemenu()'><label></label>
<ul>
<li><a href='/'>DASHBOARD</a></li>
<li><a href='/model'>MODEL</a></li>
</ul>
</nav>
I am trying to implement a responsive top navigation bar into my website. After several trials it's still not working properly and I can't understand where I went wrong.
Could you please tell me if there are any mistakes ?
I attached below the script for the top navigation bar and the script for responsive.
Thank you very much for your help.
Turo
#main_nav {
background-color: #FFFFFF;
position: sticky;
top: 0;
position: -webkit-sticky;
margin: collapse;
border-bottom: 0.2em solid #F8FBF9;
z-index: 10;
box-shadow: 0.2em 0.3em 0.8em #E5E4E3;
}
#main_nav ul {
padding: 0;
margin: 0;
text-align: center;
}
#main_nav ul li {
display: inline-block;
width: 19.7%;
}
#main_nav ul li a{
color: #FF0D90;
padding: 1em 0;
font-family: Monaco, monospace;
font-weight: lighter;
font-size: 1.2em;
text-decoration: none;
text-align: center;
display: inline-block;
width: 100%;
}
#main_nav ul li a:hover {
color: #5CA3F9;
background-color: #F8FBF9;
}
.sel_nav{
background-color: #FAFCFB;
}
#media screen and (max-width: 480px) { /* CSS Rules */
body {
width: 100%;
padding: 0;
margin-right: 0;
margin-left: 0;
overflow: scroll;
}
#main_nav {
position: relative;
margin-right: 0;
margin-left: 0;
width: 100%;
height: 100%;
text-align: center;
}
#main_nav ul {
width: 19%;
padding: 1%;
text-align: center;
margin: 0;
}
#main_nav ul li {
display: block;
width: 100%;
vertical-align: middle;
text-align: center;
margin: 0 auto;
margin-left: 120%;
}
#main_nav ul li a {
display: block;
text-align: center;
vertical-align: middle;
padding: 0.5em 3em 0.2em 1.5em;
}
Try the below code, it should work. You had some unnecessary width and padding in your code and you don't need to use display: inline-block; for each and every elements. Here's a cleaner code:
#main_nav {
display: inline-block;
overflow: hidden;
background-color: #FFFFFF;
top: 0;
position: sticky;
position: -webkit-sticky;
margin: collapse;
border-bottom: 0.2em solid #F8FBF9;
box-shadow: 0.2em 0.3em 0.8em #E5E4E3;
width: 100%;
}
#main_nav ul {
list-style-type: none;
text-align: center;
display: flex;
justify-content: space-around;
padding: 0;
}
#main_nav ul li {
display: inline-block;
}
#main_nav ul li a {
color: #FF0D90;
text-decoration: none;
font-family: Monaco, monospace;
font-weight: lighter;
font-size: 1.2em;
padding: 1.5em 1.5em;
}
#main_nav ul li a:hover {
color: #5CA3F9;
background-color: #F8FBF9;
}
#media screen and (max-width: 480px) {
#main_nav {
display: block;
}
#main_nav ul {
display: block;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
}
#main_nav ul li {
display: block;
}
#main_nav ul li a {
display: inline-block;
padding: 0.5em 3em;
}
}
<nav id="main_nav">
<ul>
<li>HOME</li>
<li>NATURA</li>
<li>CITTA'</li>
<li>IMMAGINI</li>
<li>CONTATTI</li>
</ul>
</nav>
To test responsiveness, test it out at JSFiddle.
I was attempting to build a responsive nav using flexbox. When the screen is smaller than 744px, I wanted a toggle button to appear, the main nav to have a max-height of 0, and then on click, have the nav display in block. Fairly typical stuff.
However, I'm used to doing this just with floats and I'm running into several problems:
I don't understand how to drop the UL below the nav without pushing the nav logo and toggle up;
The UL with the LI doesn't seem to be responding to the max-height trick.
If anyone can provide some assistance or point me in the direction of tutorial that would be great.
* {
margin: 0;
padding: 0;
}
body {
font-family: 'open-sans', 'sans-serif';
font-size: 17px;
color: #444;
}
.navText {
font-size: 14px;
}
nav {
height: 100%;
width: 100%;
background-color: white;
}
.nav-fixedWidth {
//border: 1px solid;
min-height: 120px;
width: 960px;
margin: 0 auto;
display: flex;
justify-content: space-between;
align-items: center;
}
.mainNav {
list-style: none;
display: flex;
}
.mainNav li {
margin-right: 60px;
padding: 10px;
//border: 1px solid;
}
.mainNav li:nth-child(5){
margin-right: 10px;
}
.mainNav li a {
text-decoration: none;
color: #444;
display: block;
}
.mainNav li a:hover {
color: #9d9d9d;
}
.logo {
height: 60px;
width: 60px;
background-color: #ccc;
}
.toggle {
height: 60px;
width: 60px;
background-color: #ccc;
display: none;
}
#media screen and (max-width: 960px) {
.nav-fixedWidth
{
width: 95vw;
}
}
#media screen and (max-width: 744px) {
.nav-fixedWidth
{
flex-wrap:wrap;
}
.toggle
{
display: block;
}
}
<nav>
<div class="nav-fixedWidth">
<div class="logo"></div>
<div class="toggle"></div>
<ul class="mainNav">
<li class="navText">Webinars</li>
<li class="navText">e-Books</li>
<li class="navText">Blog</li>
<li class="navText">e-Course</li>
<li class="navText">Search</li>
</ul>
</div>
</nav>
I know this might be a bit late for your particular need, but you might want to take a look at this solution by Chris Coiyer
https://codepen.io/chriscoyier/pen/GJRXYE
html {
background: #666;
}
body {
width: 60%;
margin: 0 auto;
background: white;
}
.nav {
position: relative;
ul {
display: flex;
height: 3rem;
overflow: hidden;
flex-wrap: wrap;
list-style: none;
padding: 0;
width: 80%;
}
li {
a {
display: block;
padding: 1rem 0.5rem;
text-decoration: none;
white-space: nowrap;
}
}
&.open {
ul {
height: auto;
display: block;
}
}
}
.x {
position: absolute;
top: 0.75rem;
right: 0.75rem;
cursor: pointer;
}
This solution does require a small amount of JavaScript to toggle the menu.
Hope it helps :-)
I am currently using HTML and CSS to modify my library's libguides2 homepage. For some reason there is a phantom white column that is showing up on the right side of the page. It's there in Chrome, Firefox, and Safari. It does NOT show up on IE. It doesn't show up when the page loads, but if you scroll to the right on desktop or zoom out on mobile, there it is.
Here's a screenshot:
Here's the live site:
http://nybg.beta.libguides.com/
And here's my fiddle:
https://jsfiddle.net/pjp5rxws/
The white space isn't in the fiddle, but Springshare support (the people who make and host libguides) says that it's not something in the code for the page that I can't get at.
Any ideas? This issue is not the end of the world, but I would like to understand and fix it if possible!
And I know that my css should be in a separate document although it is not yet in a separate document--the site is set up in such a way that this is how I am managing my beta version for the time being. I do plan to move the css!
I'm not sure what of my code is helpful here, so here is my css:
* {
margin: 0;
padding: 0;
outline: none;
-webkit-box-sizing: border-box;
- moz-box-sizing: border-box;
box-sizing: border-box;
}
*:after,
*:before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
nav,
section {
display: block;
}
html {
font-size: 100%;
height: auto !important;
height: 100%;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
.clear {
display: block;
}
.clear::after {
clear: both;
content: ".";
display: block;
height: 1px;
visibility: hidden;
}
html,
body {
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
}
mobilenav {
display: none;
width: 100%;
z-index: 1000;
background-color: #000000;
text-align: center;
}
mobilenav div {
width: 100%;
}
mobilenav a {
color: #ffffff;
letter-spacing: 0.0625em;
font-weight: bold;
text-transform: uppercase;
display: block;
text-decoration: none;
text-align: center;
padding: 1rem;
}
mobilenav a:hover {
color: #DADADA;
text-decoration: none;
}
mobilenav > nav > ul {
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
list-style: none;
margin: 0;
padding: 0;
}
mobilenav > nav > ul:hover {
background-color: #000000;
}
mobilenav > nav > ul > li {
flex: 0 1 auto;
margin: 0;
padding: 0;
position: relative;
width: 100%;
transition: all linear 0.1s;
}
mobilenav > nav > ul > li a + div {
display: none;
position: absolute;
}
mobilenav > nav > ul > li:hover a + div {
display: block;
background-color: #000000;
}
mobilenav > nav > ul > li a + div > ul {
list-style-type: none;
}
mobilenav > nav > ul > li a + div > ul > li {
margin: 0;
padding: 0;
}
mobilenav > nav > ul > li a + div > ul > li > a {
display: block;
padding: .25rem 1.5rem;
text-decoration: none;
}
mobilenav > nav > ul > li > a {
align-items: flex-start;
display: flex;
padding: 1rem 1.5rem;
text-decoration: none;
}
.container {
display: flex;
padding: 1% 0;
}
.headerimage {
display: flex;
align-content: center;
align-items: center;
padding: 0 2%;
}
.headerimage img {
width: 100%;
padding-right: 50px;
}
.logoname {
text-transform: uppercase;
flex-flow: row;
}
.fullpage {
background-color: #ffffff;
}
.menu {
background-color: #000000;
}
.site-navigation ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
flex-direction: row;
flex-wrap: wrap;
}
.site-navigation a {
color: #ffffff;
letter-spacing: 0.0625em;
font-weight: bold;
text-transform: uppercase;
display: block;
text-decoration: none;
text-align: center;
padding: 1rem;
}
.site-navigation a:hover {
color: #DADADA;
}
.fullpagesnh {
background: url(https://s3.amazonaws.com/libapps/accounts/69823/images/IVO_2541_LARGE.jpg) no-repeat center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.fullpagesnh h2 {
color: #ffffff;
}
.fullpagesnh a {
text-decoration: none;
color: #ffffff;
}
.fullpagesnh a:hover {
color: #ffffff;
text-decoration: underline;
}
.snhcontainer {
display: flex;
justify-content: center;
}
.searchandhours {
flex-direction: row;
display: flex;
align-items: center;
}
.librarysearch {
margin: 100px 0 100px 0;
padding: 20px;
}
.fullpagesnh form {
padding: 20px;
background-color: rgba(0, 0, 0, .75);
}
.hours ul {
padding: 20px;
margin-left: 50px;
background-color: rgba(0, 0, 0, .75);
color: #ffffff;
list-style: none;
}
.contentcontainer {
background-color: #ffffff;
padding-top: 100px;
}
.row {
display: inline-block;
}
.sideblack {
margin: 5% 2.5%;
margin-bottom: 50px;
padding: 20px;
background-color: #000000;
color: #ffffff;
text-transform: uppercase;
text-align: center;
font-size: larger;
font-weight: bold;
}
.sideblack:hover {
color: #000000;
background-color: #ffffff;
}
.Special_box {
margin: 5% 2.5%;
border: 1px solid #CECECE;
word-wrap: break-word;
}
.Special_box h2 {
color: #000000;
}
.Special_box p {
color: #999AA9;
font-weight: bold;
}
.Special_box:hover {
background-color: #CECECE;
}
.Special_box a {
color: #ffffff;
}
.Special_box .bottom {
padding: 10px;
}
.Special_box img {
width: 100%;
margin: 0;
padding: 0;
}
.libguidescontent .row {
padding: 0;
margin: 0;
width: 100%;
}
.nav.nav-pills button.btn {
background-color: #ffffff !important;
color: #000000 !important;
}
.libguidescontent .alert {
background-color: #F5F5F5;
border: none;
}
.libguidescontent h1 {
padding-top: 50px;
padding-bottom: 25px;
}
.libguidescontent a {
color: #000000;
}
.libguidescontent strong {
color: #26B56E;
}
.whitespace {
height: 200px;
}
.footfoot {
background-color: #000000;
}
.foot-navigation ul {
display: flex;
list-style: none;
margin: 0;
padding-bottom: 40px;
display: flex;
justify-content: center;
flex-direction: row;
flex-wrap: wrap;
}
.foot-navigation ul li {
padding-right: 50px;
color: #ffffff;
font-weight: bold;
}
.foot-navigation ul li h3 {
font-size: 16px;
color: #ffffff;
text-transform: uppercase;
font-weight: bold;
margin-bottom: 0;
}
#media only screen and (max-width: 1024px) {
.Special_box img {
display: none;
}
.sideblack {
display: none;
}
}
#media all and (max-width: 600px) {
mobilenav {
display: block;
}
.contentcontainer {
padding: 0;
}
.headerimage img {
width: 200px;
padding-right: 30px;
}
.headerimage h1 {
font-size: 14px;
word-wrap: normal;
font-weight: 600;
}
.site-navigation ul {
flex-flow: column wrap;
padding: 0;
}
.foot-navigation ul {
flex-flow: column wrap;
padding-left: 20px;
}
.searchandhours {
flex-flow: column wrap;
padding-left: 20px;
}
.librarysearch {
margin: 0;
}
.libraryhours {
display: none;
}
body {
margin: 0;
}
.menu {
display: none;
}
}
In your .contentcontainer div, you have multiple .row elements with negative left and right margins :
.row {
margin-right: -15px;
margin-left: -15px;
}
You might want to give your .contentcontainer some padding of the opposite value :
.contentcontainer {
padding-left: 15px;
padding-right: 15px;
}
Removing the margin for row solved the issue.
See Attached for reference.
overflow-x: hidden;
add that to the css of the html
html, body {
width: 100%;
height: 100%;
overflow-x: hidden;
margin: 0px;
padding: 0px;
}
Thank you so much, all! Many good solutions. Here is another I got back from the Springshare Lounge group:
Hi Esther,
It looks like the main section of your page is using Bootstrap columns (the part in ). However, it's not in a container or container-fluid, so the appropriate sizing isn't being applied. I'd suggest changing your code just a tiny bit:
<div class="contentcontainer container-fluid">
<div class="departmentbuttons">
That should do it!
Best,
Carrie, Springshare Support
I'm trying to position the main content to the left and the nav to the right. Currently the nav is sitting at the bottom. Anyone tell me where I went wrong?
The Code (http://codepen.io/kiddigit/pen/PNXRVE)
* {
font-family: garamond;
line-height: 1.9em;
color: #212121;
}
.wrapper {
width: 75%;
margin: 0 auto;
border: 1px solid blue;
padding: 10px;
overflow: hidden;
}
.wrapper2{
overflow: scroll;
}
.main_content {
float: left;
}
.main_text {
float: left;
}
.nav {
float: right;
padding-top: 10px;
width: 25%;
}
header {
border-bottom: 5px solid;
margin-bottom: 10px;
overflow: hidden;
}
header ul {
list-style-type: none;
margin-top: 20px;
display: inline;
}
header li {
float: right;
margin-right: 20px;
width: 110px;
}
header li:first-child {
margin-right: 0;
}
header li a {
display: block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
header li a:hover {
background-color: #111;
color: white;
}
header h1 {
float: left;
text-align: left;
margin: 0 170px .5em 0;
line-height: 0;
font-size: 2em;
}
h1 a {
text-decoration: none;
color: black;
}
/*drop-down menu styles begin*/
.dropbtn {
color: black;
padding: 13px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {
display: inline-block;
float: right;
}
.dropdown-content {
display: none;
position: absolute;
}
.dropdown-content a {
color: white;
padding: 0 27.5px ;
text-decoration: none;
display: block;
background-color: #3f3f3f;
}
.dropdown-content a:hover {
color: #a9a9a9;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: black;
color: white;
}
/*drop-down menu styles end*/
/*Right nav content starts here*/
.nav li {
list-style-type:none;
font-size: 1em;
}
.nav ul {
padding-left: 10%;
font-size: 1em;
}
.nav ul a:link {
text-decoration: none;
color: black;
font-size: 1em;
}
.nav ul a:visited {
text-decoration: none;
color: black;
font-size: 1em;
}
.nav ul a:hover {
text-decoration: none;
background-color: black;
color: white;
padding:3px;
font-size: 1em;
}
/*Right nav ends here*/
Add width: 75%; to .main_content. It's a div so it will, by default take up 100% of its parent container.
You have .main-text but your element doesnt have that class. It has an id of main-text. Also, it should have a width, and .main_content shouldn't be floated:
http://codepen.io/anon/pen/eZbrPd
Floats are messy. Consider using inline-block instead:
http://codepen.io/anon/pen/dMweQe