I'm trying to modify just a few classes in my CSS for different screen resolutions, I'm aiming to have:
The default applied CSS for 1200+ width,
A media query embedded in the css for resolutions between 601 and
1199 px, //This is what's not working
A media query embedded in the css for resolutions 600px and below
When i use a single width condition, for example #media screen and (max-width: 600px) { , the css is applied as it should be.
However when I try #media screen and (max-width: 1199 px) and (min-width: 601){ the style never gets applied..
I've tried swapping the order of these conditions and also just having #media screen and (max-width: 1199 px) on the basis that the 600px rule will override it afterward but for some reason it just doesn't seem to work. Just to be clear, i've either got the default styling or the 'max-width: 600px' style when i shrink the screen to less than 600px, i can't seem to get a style applying for the middleground.
Any obvious mistakes in my CSS?/suggestions? Would be appreciated!
I bunged my html and css into a jsfiddle for anyone who wants to see for themselves http://jsfiddle.net/X6cZ7/3/ (Observe the navigation bar li items as you drag the view for the website, they change style at <600px but should also look red (for testing) at <1199 yet they dont) Only testing on Chrome at the mo, in case that's relevant.
CSS (Relevant #media stuff at the bottom..):
* {margin: 0; padding:0;}
body
{
font: normal 100% 'Poiret One', 'Trebuchet MS', sans-serif;
color: Grey;
background-image: url('Images/background_gradient.png');
background-repeat:repeat-x;
background-color: #d4ffaa;
margin: 0 auto;
height: auto;
max-width: 90%;
}
h2
{
margin: 0.6em 0;
color: Grey;
border-bottom: 2px solid #d4ffaa;
font: normal 2em 'Poiret One', 'Trebuchet MS', sans-serif;
}
#central_container
{
width: 100%;
margin: 0 auto;
height: 100%;
float: left;
}
#leftside_container
{
float: left;
width: 67.1%;
clear: left;
}
#header_container
{
width: 100%;
max-height: 300px;
height: 15em;
}
#header_title
{
width: 100%;
height: 80%;
}
#header_title h1{ font-size: 4em; color: Ivory;}
#navbar_container
{
width: 100%;
height: 20%;
}
.navbar_links ul{ list-style-type: none; }
.navbar_links li
{
display: inline;
size: 4em;
}
.navbar_links a:link, a:visited
{
font-size: 1.5em;
text-align: center;
text-decoration:none;
padding: 0.1em 0.4em;
color: Ivory;
border-left:10px solid transparent;
border-right:10px solid transparent;
border-bottom: 10px solid Ivory;
}
.navbar_links a:hover, a:active
{
color: Grey;
border-bottom: 10px solid #d4ffaa;
}
#currentpage_container
{
background-color: Ivory;
width: 100%;
height: 20%;
}
#currentpage_content
{
font-family: 'Trebuchet Ms';
padding: 1em 3em;
}
#currentpage_content p { padding: 0.8em;}
#rightside_container
{
float: right;
width: 33%;
}
#register_container
{
width: 100%;
max-height: 300px;
height: 15em;
}
.bubble{
background-color: Ivory;
border-radius: 15px;
-moz-border-radius: 15px;
display: inline-block;
position: relative;
height: 80%;
width: 100%;
margin: 1em 0;
}
.bubble p
{
padding: 1em;
white-space: preline;
font-weight: bold;
}
.bubble::after { /*arrow*/
border-top: 30px solid transparent;
border-bottom: 30px solid transparent;
border-right: 30px solid Ivory;
content: '';
position: absolute;
left: -30px;
top: 50%;
}
#contact_container
{
background-color: Ivory;
width: 100%;
}
#contacts_content{ padding: 1em 3em; }
#contacts_content .text
{
font: normal 0.9em 'Trebuchet Ms';
padding: 0.8em 0;
}
.contactNum, .contactEmail { font-size:1.5em; }
.contactNum::before { content:url(Images/phone_icon.gif);}
.contactEmail::before { content:url(Images/email_icon.gif);}
#logos_content
{
padding: 0.5em 3em;
height: 150px;
}
.logo
{
display: none;
max-width: 40%;
position:relative;
max-height: 40%;
}
.logo2
{
display: none;
max-width: 40%;
position:relative;
max-height: 40%;
right: -50%;
}
#social_content
{
padding: 1em 3em;
}
/* SMALLER RESOLUTION CHANGES */
#media screen and (max-width: 1199 px) and (min-width: 601){
.navbar_links ul{ list-style-type: none; }
.navbar_links li
{
display: inline;
background: Ivory;
}
.navbar_links a:link, a:visited
{
font-size: 1.5em;
padding: 0.1em 0.4em;
color: red;
border-left:3px solid transparent;
border-right:3px solid transparent;
border-bottom: 3px solid #d4ffaa;
}
.navbar_links a:hover, a:active
{
color: Grey;
border-bottom: 3px solid Grey;
}
}
#media screen and (max-width: 600px) {
#central_container,
#leftside_container,
#rightside_container,
#header_container,
#header_title,
#navbar_container,
#currentpage_container
{
float: none;
width: auto;
height: auto;
}
#header_title h1{ font-size: 3em; color: Ivory;}
.navbar_links ul{ list-style-type: none; margin-bottom:1em;}
.navbar_links li
{
display: inline;
}
.navbar_links a:link, a:visited
{
padding: 0;
border-left: 2px solid transparent;
border-right: 2px solid transparent;
border-bottom: 2px solid Ivory;
}
.navbar_links a:hover, a:active
{
border-bottom: 2px solid #d4ffaa;
}
}
In your css there is some typing mistake, hence its not working, please check below
Not Correct
#media screen and (max-width: 1199 px) and (min-width: 601){
}
Correct one
#media screen and (min-width: 601px) and (max-width: 1199px){
}
EDIT:
There shouldn't be any spaces between the value and unit, i.e. 1199 px is wrong it should be 1199px.
Yo have forgot to put "px" in max-width: 1199. I think this is creating problem.
Anyways, You should code for mobile first & keep on coding for larger resolutions.
Your fiddle: http://jsfiddle.net/X6cZ7/4/
Related
I designed the page with left side navigation, which on the full screen looks fine, however, when I resize it to mobile size, my main content stays in one column and does not fill up full viewport- leaving quite an empty space on the left.
I believe something in media queries might be causing this.
Here is a link: https://codepen.io/sweexee/pen/abvqyOY
Let me know if you can see it and CSS:
/* Typography imported from Google Fonts */
header {
font-family: "Taviraj", serif;
color: #257ecc;
}
p,
a {
font-family: Taviraj, serif;
}
/*Generic styles*/
html {
scroll-behavior: smooth;
}
html,
body {
min-width: 290px;
background-color: #ffffff;
line-height: 1.5;
}
body {
margin: 8px;
display: block;
}
a {
background-color: #257ecc;
text-decoration: none;
color: white;
text-align: center;
display: inline-block;
transition: all 0.3s;
}
a:hover {
opacity: 0.8;
color: #cc4d47;
}
p {
font-weight: 300;
font-size: 1.2rem;
}
blockquote {
border-left: 10px solid #257ecc;
margin: 1.5em 10px;
padding: 0.5em 10px;
}
blockquote:before {
color: #257ecc;
content: open-quote;
font-size: 4em;
line-height: 0.1em;
margin-right: 0.25em;
vertical-align: -0.4em;
}
blockquote p {
display: inline;
font-weight: 400;
font-style: italic;
font-size: 1.5rem;
color: #cc4d47;
}
ul {
display: block;
margin-block-start: 1em;
margin-block-end: 1em;
margin-inline-start: 0px;
margin-inline-end: 0px;
padding-inline-start: 40px;
}
li {
display: list-item;
}
/* Navigation styles*/
nav {
display: block;
}
#navbar {
position: fixed;
min-width: 290px;
top: 0px;
left: 0px;
width: 300px;
height: 100%;
background-color: #257ecc;
border-right: solid;
border-color: #828e99;
}
#media only screen and (max-width: 815px) {
#navbar {
max-height: 275px;
border: none;
border-bottom: 2px solid;
position: absolute;
width: 100%;
z-index: 1;
top: 0;
padding: 0;
margin: 0;
}
}
nav > header {
color: #ffffff;
margin: 10px;
text-align: center;
font-size: 1.9rem;
font-weight: 600;
display: block;
}
#navbar ul {
padding: 0;
height: 80%;
overflow-y: auto;
overflow-x: hidden;
}
#media only screen and (max-width: 815px) {
#navbar ul {
border: 1px solid;
height: 207px;
}
}
#navbar ul > li {
color: #ffffff;
border-top: 1px solid;
border-color: #cc4d47;
list-style: none;
position: relative;
width: 100%;
}
#navbar a {
display: block;
padding: 12px 30px;
text-decoration: none;
cursor: pointer;
font-size: 1.1rem;
font-family: "Roboto", sans-serif;
font-weight: 300;
}
/*Main ccontent styles*/
main {
display: block;
}
#main-doc {
position: absolute;
margin-left: 310px;
padding: 20px;
margin-bottom: 110px;
}
#media only screen and (max-width: 400px) {
#main-doc {
margin-left: -10px;
}
}
#media only screen and (max-width: 815px) {
#main-doc {
position: relative;
margin-top: 270px;
}
}
/* Section styling*/
section {
display: block;
}
#main-doc header {
display: block;
font-size: 1.6rem;
font-weight: 600;
text-align: left;
margin: 0px;
padding-top: 10px;
}
section article {
color: #3d4247;
margin: 15px;
}
article {
display: block;
}
section article > p {
display: block;
}
section article > img {
display: block;
max-width: 100%;
height: auto;
margin-left: auto;
margin-right: auto;
margin-top: 20px;
}
section article > ul {
list-style: none;
}
section article > ul li::before {
content: "\2022";
color: #257ecc;
font-weight: bold;
display: inline-block;
width: 1em;
margin-left: -1em;
}
section article > ul > li {
font-family: "Taviraj", sans-serif;
font-size: 1.2rem;
font-weight: 300;
color: #3d4247;
}
section article > ul > li > a {
color: #257ecc;
background-color: #ffffff;
}
Add margin-left: 0; in the #main-doc in #media only screen and (max-width: 815px)
width media query as below
With margin-left reflection: 310px; # main-doc moves to the right even in the mobile width of the contents.
#media only screen and (max-width: 815px)
#main-doc {
position: relative;
margin-left: 0; /* *** add this *** */
margin-top: 270px;
}
After adding, your site will look like the following when the mobile width
Your #main-doc has margin-left: 310px;.
Remove this in your media query concerning (max-width: 815px) and you're good!
Not quite sure why my media queries aren't working. Very much a beginner. Trying to get the navigation menu to respond similarly to
http://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_topnav
Normal media queries don't work either, I know i don't have topnav as the class setting for the nav like they do in the w3 example. I just have been using nav.
/**********************************
GENERAL
***********************************/
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
}
html, body {
height: 100%;
}
body{
margin:0;
padding:0;
background: rgba(226,226,226,1);
}
a{
text-decoration: none;
}
li{
list-style-type: none;
display: inline
}
#wrapper{
max-width: 100%;
max-height: 100%;
/*min-height: calc(100vh - 120px);*/
/* 80px header + 40px footer = 120px */
width: 85%;
margin: 0 auto;
overflow: visible;
position:relative;
background: rgba(147,206,222,1);
}
img{
max-width: 100%;
width: 200px;
margin-right: 15px;
float: left;
margin-bottom: 20px;
padding:1px;
border:1px solid #021a40;
}
h1{
text-align: center;
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.8);
font-family: Garamond;
}
/**********************************
HEADING
***********************************/
header{
color:blue;
text-align: left;
float: left;
margin: 0 0 30px 0;
padding: 20px 0 0 0;
width: 100%;
font-size: 32;
}
/**********************************
NAVIGATION
***********************************/
nav{
max-width: 100%;
max height: 100%;
padding: 3.5em;
margin: 0;
background-color: green;
text-align: right;
font-family: Garamond;
}
nav ul {
list-style: none;
margin: 0 10px 20px; /*pushes div down*/
padding: 0;
text-decoration: none;
/*background-color: purple;*/
max-width: 100%;
max-height: 200px;
}
nav menu:{
}
nav li {
display: inline-block;
}
nav a, a:link, a:visited {
font-weight: 800;
padding: 15px 10px;
/*border-style: double;*/
border-radius: 10px;
margin-bottom: 20px;
color:white;
text-align: center;
font-weight: bold;
text-transform: uppercase;
}
a:hover{
background-color: gray;
}
#back-to-hp{
text-align: left;
}
/**********************************
FOOTER
***********************************/
footer {
background: rgba(255,255,255,1);
/*max-height: 100%;
position:relative;
left: 0;
bottom: 0;
height: 60px;
width: 100%;
overflow:hidden;
text-align: center;*/
width:100%;
height:100px;
position:relative;
bottom:0;
left:0;
padding-top: 10px;
margin-top: 15px;
}
}
/**********************************
PAGE: ADOPTION
***********************************/
#image-paragraph{
font-size: 20;
text-align: center;
float: right;
}
#content{
font-family: Garamond;
}
/**********************************
PAGE: ABOUT
***********************************/
/**********************************
PAGE: CONTACT
***********************************/
/**********************************
COLORS
***********************************/
/**********************************
MEDIA QUERIES
***********************************/
/*#media all (max-width: 960px) {
body{
background-color: royalblue;
}
p{
color:white;
}
}
##media (min-width:481px) and (max-width: 700px) {
}*/
#media screen and (max-width:680px) {
ul.nav li:not(:first-child) {display: none;}
ul.nav li.icon {
float: right;
display: inline-block;
}
}
#media screen and (max-width:680px) {
ul.nav.responsive {position: relative;}
ul.nav.responsive li.icon {
position: absolute;
right: 0;
top: 0;
}
ul.nav.responsive li {
float: none;
display: inline;
}
ul.nav.responsive li a {
display: block;
text-align: left;
}
}
You have two media queries set at the max-width of 680px. Possibly one was meant to be a min-width? If not then I don't see why you didn't put all of it under a single media query.
EDIT:
Try changing ul.nav li:not(:first-child) {display: none;} to nav ul li:not(:first-child) {display: none;}.
This is because media queries read css as nested from their parents, so you need to include the parent elements correctly.
Also, from experience, I've noticed visibility: hidden; consistently works better in many scenarios than display: none;. This depends on your element positioning, though. Either works in your case.
I'm learning how to code Wordpress themes currently, and I'm having trouble centering my navigation menu. It moves too far to the right. I have included an image to illustrate the problem with the code that I have presented.
Here is a link to a screenshot of the problem: http://i59.tinypic.com/8z1m2o.png
body {
font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;
font-size: 14px;
color: #333;
}
a:link,
a:visited {
color: #000;
text-decoration: none;
}
p {
line-height: 14px;
}
/* General Layout */
div.container{
max-width: 960px;
margin: 0 auto;
padding-left: 20px;
padding-right: 20px;
}
article.post {
border-bottom: 1px solid #bbbbbb;
}
article.post:last-of-type{
border-bottom: none;
}
/* Header */
.site-header {
border-bottom: 2px solid #999;
padding-top: 10px;
}
/* Footer */
.site-footer {
margin-top: 0px;
border-top: 2px solid #999;
margin-left: auto;
margin-right: auto;
}
/* Navigation */
.site-nav {
position: fixed;
left:50%;
}
.site-nav ul{
background-color: rgba(255,255,255,0.8);
padding: 0px;
margin: 0px;
}
.site-nav ul li{
text-align: center;
display: inline-block;
overflow:hidden;
text-decoration: none;
margin-right: 10px;
padding-right: 10px;
border-right: 1px solid #DDD;
}
.site-nav ul li:last-of-type {
border-right: none;
}
.site-nav has position: fixed, left: 50% so the left side of the element will be positioned in the middle of the screen. Remove this rule or give the element margin-left: -X where X is equal to half of .site-nav's width if you must use fixed positioning.
.site-nav {
width: 100%
position: fixed;
margin: 0;
}
.site-nav ul{
position: relative;
background-color: rgba(255,255,255,0.8);
padding: 0px;
margin: 0px auto;
}
I sometimes want to recode responsive navigations to be mobile-first instead of having styles that adjust to smaller user devices.
Manually recoding CSS to reverse the style cascade from max-width to min-width isn't as quick as I was hoping.
Sample of CSS that could be recoded to be mobile-first: http://codepen.io/bl4ckdu5t/pen/vOBRqL
nav {
height: 40px;
width: 100%;
background: #455868;
font-size: 11pt;
font-family: 'PT Sans', Arial, sans-serif;
font-weight: bold;
position: relative;
border-bottom: 2px solid #283744;
}
nav ul {
padding: 0;
margin: 0 auto;
width: 600px;
height: 40px;
}
nav li {
display: inline;
float: left;
}
nav a {
color: #fff;
display: inline-block;
width: 100px;
text-align: center;
text-decoration: none;
line-height: 40px;
text-shadow: 1px 1px 0px #283744;
}
nav li a {
border-right: 1px solid #576979;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}
nav li:last-child a {
border-right: 0;
}
nav a:hover, nav a:active {
background-color: #8c99a4;
}
nav a#pull {
display: none;
}
/*Styles for screen 600px and lower*/
#media screen and (max-width: 600px) {
nav {
height: auto;
}
nav ul {
width: 100%;
display: block;
height: auto;
}
nav li {
width: 50%;
float: left;
position: relative;
}
nav li a {
border-bottom: 1px solid #576979;
border-right: 1px solid #576979;
}
nav a {
text-align: left;
width: 100%;
text-indent: 25px;
}
}
/*Styles for screen 480px and lower*/
#media only screen and (max-width : 480px) {
nav {
border-bottom: 0;
}
nav ul {
display: none;
height: auto;
}
nav a#pull {
display: block;
background-color: #283744;
width: 100%;
position: relative;
}
nav a#pull:after {
content:"";
background: url('http://s30.postimg.org/68factszx/nav_icon.png') no-repeat;
width: 30px;
height: 30px;
display: inline-block;
position: absolute;
right: 15px;
top: 10px;
}
}
/*Smartphone*/
#media only screen and (max-width : 320px) {
nav li {
display: block;
float: none;
width: 100%;
}
nav li a {
border-bottom: 1px solid #576979;
}
}
I don't know any tool that can help you with that. Here's a good article that can help you to do the changes manually:
link
max-width is the maximum width at which these styles will be shown. A screen wider than the specified number will not use the styles associated with that rule.
Similarly, min-width is the minimum width at which these styles will be shown. A screen narrower than the specified number will not use the styles associated with that rule.
When highlighting text with IE 8 on a webpage that I'm currently developing the font changes and/or sometimes the size. The same thing happens sometimes when I hover over the menu.
This is how my css looks like and I don't know why the error occurs? One more thing that is very strange is that I have installed Windows 7 with paralells on my osx and the error does not occur there but only on PC computers. I have tried changing fonts but with no help...
This is my css:
body {
font-family: verdana, sans-serif;
font-size: 14px;
}
#wrapper, .wrapper {
width: 900px;
padding: 0 30px;
margin-left: auto;
margin-right: auto;
}
#header {
background: url('http://localhost:8888/wp-content/uploads/2012/09/120920_scam_banner.jpg') no-repeat;
height: 150px;
margin: 20px 0;
}
#header div {
width: 900px;
height: 150px;
margin-left: auto;
margin-right: auto;
position: relative;
background: none;
}
#header div a {
text-indent: -9999px;
position: absolute;
width: 900px;
height: 150px;
}
#header div a:hover {
background: none;
}
#section {
}
#menu {
float: left;
width: 175px;
padding: 20px 25px 0 0;
border-right: 2px solid #000;
text-align: right;
}
#menu a, a {
color: #000;
text-decoration: none;
}
.mp-formdiv {
float: right;
}
img {
border: 1px solid #000;
}
#menu a:hover, a:hover {
color: #fff;
background: #000;
}
.menu li {
margin: 3px 0;
text-align: right;
}
#menu h3 {
line-height: 52px;
}
#menu .artists {
padding-left: 10px;
}
#menu-artists li {
}
#content {
float: right;
width: 670px;
padding: 20px 0 50px 20px;
}
#footer {
overflow:hidden;
clear: both;
}
#white_footer {
float: left;
width: 300px;
background: #fff;
height: 20px;
}
#footer_content {
height: 20px;
}
.store {
overflow-y: scroll;
}
#the_store {
margin-top: 10px;
}
/* FONTS */
h1 {
font-size: 3em;
margin-bottom: 40px;
white-space: nowrap;
line-height: 0%;
}
h1.storefront {
font-size: 2em;
}
h2 {
font-size: 2em;
}
h3 {
font-size: 1.5em;
}
#content p strong {
font-weight: bold;
}
#content p img {
float: left;
margin: 5px 20px 20px 0;
}
#content p img:after {
margin-top: 20px;
}
#subscribe_mail input[type=text]{
width: 85px;
height: 12px;
font-size: 0.60em;
margin-bottom: 5px;
float: left;
margin-right: 4px;
}
#subscribe_mail input[type=text]:focus {
font-size: 0.75em;
}
#subscribe_mail input[type=submit] {
border: 1px solid #999;
font-size: 0.75em;
float: left;
}
.mp-message, .mp-loading {
font-size: 0.75em;
}
.MailPressFormName {
display: none;
}
#artist_info {
display: none;
margin-top: 40px;
overflow: hidden;
clear: both;
}
.more-less {
background: #000;
float: left;
color: #fff;
padding: 0 2px;
margin-top: 10px;
}
#artist_less {
display: none;
}
.gallery-icon a:hover {
background: none;
}
.gallery dl {
margin-top: 0 !important;
margin-bottom: 15px;
}
.gallery dl dd {
font-size: 0.75em;
}
.newsletterH {
margin-bottom: 5px;
}
I would use Firefox's Firebug plugin to see where the styles are coming from. IE provides a less friendly developer tool window that does something similar (I only use this if the style issue is only occurring in IE). I'd check your :hover and :focus rules first since those would cause things to happen on hover or select.