In the navigation menu below, could somebody please show me how I would make it responsive to resize in width for iPad to iPhone etc. I have it looking perfectly how I want it on desktop however when I view the website on iPad or iPhone the menu is too wide still resulting in the main content of the page looking smaller and off center.
css
#menu, #menu ul {
margin: 0 auto;
padding: 0;
background-color: #FFFFFF;
}
#menu {
display: table;
width: 100%;
list-style: none;
position: relative;
top: -30px;
text-align: center;
-webkit-box-shadow: 0px 3px 5px 0px rgba(50, 50, 50, 0.75);
-moz-box-shadow: 0px 3px 5px 0px rgba(50, 50, 50, 0.75);
box-shadow: 0px 3px 5px 0px rgba(50, 50, 50, 0.75);
font-size: 18px;
height: 20px;
z-index: 101;
}
#menu.fixed {
position: fixed;
top: 0;
width: 100%;
}
#menu li {
display: table-cell;
list-style: none;
padding-right: 50px;
left: 50px;
vertical-align: middle;
}
#menu > li:hover > ul {
background: #FFF;
display: block;
left: 0;
width: 100%;
-webkit-box-shadow: 0px 3px 2px 0px rgba(50, 50, 50, 0.75);
-moz-box-shadow: 0px 3px 2px 0px rgba(50, 50, 50, 0.75);
box-shadow: 0px 3px 2px 0px rgba(50, 50, 50, 0.75);
border-top: thin dotted #999;
top: 32px;
}
#menu > li > ul {
display: none;
position: absolute;
text-align: center;
}
#menu li a {
display: block;
padding: 2px 10px;
text-decoration: none;
font-weight: lighter;
white-space: nowrap;
color: #333;
}
#menu li a:hover {
color: #CCCCCC;
font-size: 18px;
vertical-align: middle;
}
#menu li ul li {
display: inline-block;
float: none;
}
HTML
<div id="menu">
<ul>
<li>Milk</li>
<li>Eggs</li>
<li>Cheese</li>
<li>Vegetables</li>
<li>Fruit</li>
</ul>
</div>
You indeed should use css Media Queries.
By using #media (min-width: 768px){} you tell the browser that all windows above 768px width will include the following css-code. This is the right way to use it, because this is a mobile first approach, not familiar with that term.. google it.
Just by changing you're display: table-cell; to a display: table-row for the mobile format, will put the items under each other.
I made an example by using the things above, including an html button and a little jQuery.
See Demo here
try like this: LINK
CSS:
#media handheld, only screen and (max-width: 768px) {
#menu li {
clear:both;
float:none;
display:block;
background-color:#f0f0f0;
margin-bottom:2px;
}
}
According to the devices you need, just change the max-width of media query
Just use media queries, find the dimensions of the devices you wish to optimize for, and assign those dimensions in your media query. After that you may select the classes for the menu bar and create new rules and margins etc.
::Sources::
http://www.w3schools.com/css/css_mediatypes.asp
http://www.youtube.com/watch?v=aPtA4nYkvDw - Khoury's channel and website are really helpful.
Related
I am working on a project for school and am trying to add a drop down menu to my head navigation. I am still pretty new to css but had fun playing with the styling to get an interesting alignment that would work with the vision I had for the page (this is part of a larger piece that I didn't include to keep it relevant to the question)
I wanted to create a right aligned menu that was set to the bottom of the head div. I got everything to work by using absolute positioning but now that I am trying to add a fancy multi level drop down menu things aren't working. I have tried combinations of inline block and relative and absolute positioning but the dropdown does not align correctly. It just bunches up at the bottom offset to the right.
When I try styling the nav bar like people do in tutorials it gets messed up when I remove the absolute positioning.
Is there a way to get the dropdown to work with the current method of styling? I don't have any hover effects or visibility yet because I can't even get it lined up! That part should be pretty straight forward for the dropdown and submenus.
and probably more importantly
Is there a better way to accomplish this visual goal? (right-aligned at the bottom of the white div)
This is not a dynamic styling yet so you have to stretch the viewport for it to make sense.
/*====================================MAIN=================================*/
body {
background-color: #d5d3d5;
font-family: 'Gill Sans', 'Gill Sans MT', 'Calibri', 'Trebuchet MS', sans-serif;
margin: 0px;
padding: 0px;
}
.flex_body {
background: linear-gradient(90deg, rgba(255, 255, 255, .0), rgba(255, 255, 255, 1) 20%);
display: flex;
margin: 0px;
padding: 0px;
height: 800px;
}
.page_body {
background: linear-gradient(90deg, rgba(255, 255, 255, .0), rgba(255, 255, 255, 1) 15%);
margin: 0px 0px 0px 30px;
padding: 0px 0px 0px 20px;
height: 800px;
overflow: hidden;
}
/*=============================MAIN=NAVIGATION=================================*/
#header {
background-color: #ffffff;
height: 130px;
margin: 0px;
padding-bottom: 0px;
position: relative;
box-shadow: inset 0px -15px 18px -6px rgba(121, 104, 124, 0.678);
}
#headNAV ul {
list-style-type: none;
position: absolute;
text-align: right;
bottom: 0;
right: 0;
margin: 8px;
}
#headNAV ul li {
display: inline;
position: relative;
font-size: 18px;
padding: 5px 0px 15px 0px;
margin: 0px 0px 0px -5px;
}
#headNAV ul li:not(:last-child) {
border-right: 1px solid #8f85a1dc;
}
#headNAV ul li a {
display: inline-block;
padding: 5px 40px 10px 40px;
margin: 0px 0px -2px 0px;
text-decoration: none;
color: #353138;
}
#headNAV ul li a:hover {
background-color: #50328ddc;
color: white;
text-decoration: underline;
box-shadow: 0px 5px 3px 1px #50328ddc;
}
#search_icon {
max-width: 5%;
max-height: 5%;
margin: 0px;
padding: 0px;
display: inline;
}
#headNAV ul li input {
margin: 5px 35px 10px 35px;
}
/*======================myPage-Nav============================*/
#myPage_button:hover>#myPage {
color: white;
}
#myPage_button {
text-decoration: underline;
}
#myPage {
color: #50328ddc;
font-size: 22px;
font-weight: bold;
text-decoration: underline;
}
#dropdown-btn {
padding: 0px 10px;
}
#myPage-menu {
margin: auto;
}
#headNAV ul li #myPage-menu li {
position: absolute;
background-color: #fff;
display: inline-block;
padding: 0px;
border: none;
}
<header id="header">
<nav id="headNAV">
<ul>
<li>Mission</li>
<li>News</li>
<li>Events</li>
<li>Forums</li>
<li><a id='myPage_button' href="#">My<span id='myPage'>Page</span><span id = "dropdown-btn" class="fas fa-caret-down"></span></a>
<ul id="myPage-menu">
<li>Main Feed</li>
<li>Projects</li>
<li>Messages</li>
<li>Profile</li>
<li>Search</li>
</ul>
</li>
<li><input type="text" name="search" placeholder="Search..."></li>
<li><a id="header_login" href="#">Login/SignUp</a></li>
</ul>
</nav>
</header>
Thank you for any input!
Kevin
For some reason my google web font in the navigation menu keeps on changing its weight from page to page although I have set it to 700. The CSS for the menu is identical on each page. Could somebody please tell me whats going on as I have never found this before.
For future posterity reasons I shall delete the live link as soon as somebody answers. Thanks!
My CSS is
* {
font-family: 'Lato', sans-serif;
}
#menu {
font-weight:700;
display: table;
width: 100%;
list-style: none;
position: relative;
top: -20px;
text-align: center;
left: -10px;
-webkit-box-shadow: 0px 3px 5px 0px rgba(50, 50, 50, 0.75);
-moz-box-shadow: 0px 3px 5px 0px rgba(50, 50, 50, 0.75);
box-shadow: 0px 3px 5px 0px rgba(50, 50, 50, 0.75);
font-size: 18px;
height: 20px;
z-index: -101;
}
Firstly, you need to fix this:
body {
background-color: #FFF;
background-image: url(bg.png);
color: #D6D6D6;
font-family: font-family: 'Lato', sans-serif;
}
Your font-family declaration is duplicated.
Secondly, your 700 is being overridden by the #menu li a class here:
#menu li a {
display: block;
padding: 2px 10px;
text-decoration: none;
font-weight: lighter; /*should be changed to 700*/
white-space: nowrap;
color: #333;
}
This is my website. The nav bar is causing me horrendous problems. Last night my friend told me it was dropping down and I just don't know how to fix it:
http://i60.tinypic.com/23iigpi.png
So I removed the width and reduced the text on some buttons which is depressing for me.
Anyway, now I want my smaller nav bar to centre in the middle of my white block. Does anyone know the best way?
http://www.simplypsychics.com/null/index-test.html
I have tried:
and modifying various positioning in the CSS but nothing seems to work.
This is my CSS for the nav:
#nav {
position: absolute;
top: 98px;
left:15px;
float: left;
list-style: none;
background-image:url(../images/menubanner.png);
background-color: #f5c3fd;
border-radius:7px;
-webkit-box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.05);
-moz-box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.05);
box-shadow: 1px 3px 1px rgba(0, 0, 0, 0.05);
}
#nav li {
float: left;
}
#nav li a {
display: block;
padding: 8px 13px;
text-decoration: none;
font-weight: bold;
color: #494949;
border-right: 1px solid #fceaff;
}
#nav li a:hover {
color: #822e8e;
}
#nav .home-icon1 {
background: url(../images/icon-home.png) no-repeat center;
width: 39px;
height: 34px;
background-color: #494949;
color: #f5c3fd;
border-top-left-radius: 7px;
border-bottom-left-radius: 7px;
position: relative;
border-right: 1px solid #fceaff;
float: left;
padding: 0;
list-style: none;
}
#nav .home-icon1 a:hover {
background: url(../images/icon-home.png) no-repeat center;
width: 39px;
height: 34px;
background-color: #494949;
color: #f5c3fd;
border-top-left-radius: 7px;
border-bottom-left-radius: 7px;
position: relative;
border-right: 1px solid #fceaff;
float: left;
padding: 0;
list-style: none;
}
#nav .home-icon2 {
background: url(../images/icon-findapsychic.png) no-repeat left;
padding: 0px 0px 0px 15px;
}
#nav .home-icon3 {
background: url(../images/icon-psychicreadings.png) no-repeat left;
padding: 0px 0px 0px 25px;
}
#nav .home-icon4 {
background: url(../images/icon-bookareading.png) no-repeat left;
padding: 0px 0px 0px 22px;
}
#nav .home-icon5 {
background: url(../images/icon-aboutus.png) no-repeat left;
padding: 0px 0px 0px 30px;
}
#nav .home-icon6 {
background: url(../images/icon-help.png) no-repeat left;
padding: 0px 0px 0px 14px;
}
and this is my HTML:
<div id="nav" style="margin:0 auto !important;">
<li class="home-icon1" onclick="window.location.href='http://www.simplypsychics.com/'"></li>
<li class="home-icon2">FIND A PSYCHIC READER</li>
<li class="home-icon3">PSYCHIC READINGS</li>
<li class="home-icon4">BOOK A READING</li>
<li class="home-icon5">FIND OUT MORE</li>
<li class="home-icon6">HELP/FAQ</li>
</div>
Also if the nav bar looks awful for you like it did my friend please let me know! :(
On parent (#headerwhiteback) set:
text-align: center;
Then on #nav, remove:
position: absolute;
float: left;
And add this CSS:
#nav {
display: inline-block;
}
#nav::before {
content: "";
clear: both;
}
Also, to your liking: add margin-top: on #nav (25px seems ok) and make padding-top: on next element, #headertextbottom, much smaller (20px seems ok).
This is just a quick fix for your header. Please remember: CSS looks horrific here and looks set to be rewritten from scratch or only cause you more and more trouble. Good luck!
If the nav bar is more-or-less a set width (#nav looks to stay at 840px) then you can set left:50% and margin-left:-420px (-420 px because it's half the width of the navbar, and we want to move it towards the left). This should work because you've already set the navbar to be positioned absolutely.
You'll have to remove this from the #nav div though: style="margin:0 auto !important;"
Inline style and !important is doubly bad!
I am having trouble with this, I have looked through other peoples questions and answers I have found some helpful info however I am struggling to apply it to my menu. I am looking for my current menu which is pure CSS and HTML no other scripts or code to become fully responsive and mobile friendly. i.e. I want to make sure when the browser window size is reduced that the menu also gets smaller then to the point where it turns into the mobile button that you tap to expand.
I am hoping someone can show me the exact code I need to add to it with the correct class names etc. I have already tried and failed at this by trying to adapt other peoples answers. I am aware there are various places that will "build" one for free and give me the code however I want the desktop version of my menu to be 100% the same I just need it to scale properly to smaller screens.
I also do not want to use jquery javascript or anything else that is not HTML5 or CSS3, the code is inserted into my index.php and css into my external css file,
From my index page:
<!-- NAV-BAR-START -->
<div id="navbar"><div id='cssmenu'>
<ul>
<li><a href='/?p=home'><span>Home</span></a></li>
<li class='has-sub'><a href='/?p=gallery'><span>Gallery</span></a>
<ul>
<li><a href='/?p=photos'><span>Photos</span></a></li>
<li><a href='/?p=videos'><span>Videos</span></a></li>
<li><a href='/?p=audio'><span>Audio</span></a></li>
</ul>
</li>
<li class='has-sub'><a href='/?p=ian-milne'><span>Ian Milne</span></a>
<ul>
<li><a href='/?p=about'><span>About Ian</span></a></li>
<li><a href='/?p=testimonials'><span>Testimonials</span></a></li>
<li class='last'><a href='/?p=location'><span>Location</span></a></li>
</ul>
</li>
<li><a href='/?p=events'><span>Events</span></a></li>
<li><a href='/?p=bookings'><span>Bookings</span></a></li>
<li class='last'><a href='/?p=contact'><span>Contact</span></a></li>
< /ul>
</div></div>
<!-- NAV-BAR-END -->
And the associated CSS:
/* CSS DROPDOWN MENU */
#cssmenu {
border: none;
border: 0px;
margin: 0px;
padding: 0px;
font: 67.5% 'Lucida Sans Unicode', 'Bitstream Vera Sans', 'Trebuchet Unicode MS', 'Lucida Grande', Verdana, Helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
width: auto;
text-align:center;
}
#cssmenu ul {
background: #000dfa;
height: 50px;
list-style: none;
margin: 0;
padding: 0;
-webkit-border-radius: 8px 8px 0px 0px;
-moz-border-radius: 8px 8px 0px 0px;
border-radius: 8px 8px 0px 0px;
-webkit-box-shadow: inset 0px 16px 0px 0px rgba(255, 255, 255, 0.1);
-moz-box-shadow: inset 0px 16px 0px 0px rgba(255, 255, 255, 0.1);
box-shadow: inset 0px 16px 0px 0px rgba(255, 255, 255, 0.1);
}
#cssmenu li {
float: none;
padding: 0px 0px 0px 15px;
display: inline-block;
}
#cssmenu li a {
color: #ffffff;
display: block;
font-weight: normal;
line-height: 50px;
margin: 0px;
padding: 0px 25px;
text-align: center;
text-decoration: none;
}
#cssmenu li a:hover {
background: #000894;
color: #ff8400;
text-decoration: none;
-webkit-box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
-moz-box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
}
#cssmenu ul li:hover a {
background: #000894;
color: #ff8400;
text-decoration: none;
}
#cssmenu li ul {
display: none;
height: auto;
padding: 0px;
margin: 0px;
border: 0px;
position: absolute;
width: 200px;
z-index: 200;
}
#cssmenu li:hover ul {
display: block;
}
#cssmenu li li {
display: block;
float: none;
margin: 0px;
padding: 0px;
width: 200px;
background: #000dfa;
/*this is where the rounded corners for the dropdown disappears*/
}
#cssmenu li:hover li a {
background: none;
}
#cssmenu li ul a {
display: block;
height: 50px;
font-size: 12px;
font-style: normal;
margin: 0px;
padding: 0px 10px 0px 15px;
text-align: left;
}
#cssmenu li ul a:hover,
#cssmenu li ul li:hover a {
border: 0px;
color: #ff8400;
text-decoration: none;
background: #000894;
-webkit-box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
-moz-box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
box-shadow: inset 0px 0px 7px 2px rgba(0, 0, 0, 0.3);
}
I have now put this into jsfiddle aswell for those who were asking
http://jsfiddle.net/GregTimeassistant/WLP8h/
You can style for each media query. Just copy/paste all your styles for each case.
You can resize your browser window so you can see the result for each media query.
Just experiment a lot, you will see that it is easy to customize your design for each aspect ratio.
#media (max-width: 600px) {
#cssmenu {
/*
copy styles here
*/
}
}
Check this example that covers a lot of devices (but needs some updating for new HD smartphones and tablets).
https://gist.github.com/marcobarbosa/798569
So, I have this made.
HTML
<div id="navholder" class="bgd">
<nav id="nav">
<ul>
<li>Почетна</li>
<li>Делатност</li>
<li>Историјат</li>
<li>Службе</li>
<li>Колектив</li>
<li>Контакт</li>
</ul>
</nav>
</div>
#navholder {
height: 60px;
text-align: center;
margin: 0 auto;
}
#nav {
height: 30px;
margin-top: 10px;
background: #B8860B;
}
#nav ul li{
margin-top: 3px;
display: inline;
font-size: 120%;
opacity: 1.0;
}
#nav ul li a {
display: inline-block;
height: 120%;
padding: 5px;
-webkit-box-shadow: -1px 0px 22px rgba(50, 50, 50, 0.5);
-moz-box-shadow: -1px 0px 22px rgba(50, 50, 50, 0.5);
box-shadow: -1px 0px 22px rgba(50, 50, 50, 0.5);
border: 1px solid white;
opacity: 1.0;
background: #DAA520;
}
#nav a:hover {
color: white;
background: black;
width: ?
}
I want the buttons once hovered over with a mouse to increase about 20%. The problem that I found is if I use the exact width like "width: 60px not every button is of the same size.
On the other hand if I use width: 120% I believe the page takes the width of the whole #navholder element which is defined by the class .bgd.
Any ideas on how can I make this happen?
Thanks.
You could use transform: scale()
jsFiddle example
#nav a:hover {
transform:scale(1.3,1.3);
-webkit-transform:scale(1.3,1.3);
-moz-transform:scale(1.3,1.3);
}
Just increase the padding on hover:
#nav a:hover {
color: white;
background: black;
padding: 5px 10px; /* 5px top/bottom, 10px left/right */
}
You may set width with em's and increase font-size.
Also, you may add border/padding on hover:
#nav a:hover {
border-right: solid 20px black;
/* or padding-right */
}