this is my code for my buttons that i have on my page, with my desktop the buttons turn out pretty much where i want them to, but when i get on a laptop the buttons move down the page further and further depending on the computer resolution..
my background image is set up to fit the screen no matter what size they have there resolution at or how they resize there browser to keep it from distorting the picture but i just can't seem to get the buttons to show in the same spot for all resolutions.. or if there was a way to get the buttons to move with the background image for its position that's pretty much what im looking for and i have tried % also but here is the code below
a.button {
position:absolute;
display:block;
}
a.button.testing-link {
width:250px;
height:87px;
background:url(http:);
top:753px;
left:750px;
}
a.button.testing2-link {
width:250px;
height:87px;
background:url(http:);
top:753px;
left:180px;
}
a.button.testing3-link {
width:250px;
height:89px;
background:url(http:);
top:753px;
left:465px;
}
This is because you need to make your css responsive. Here's a cheat sheet.
http://webdesignerwall.com/tutorials/css3-media-queries
But basically you would have something like this:
#media screen and (max-width: 600px) {
a.button {
//your rules for that
}
}
#media screen (min-width: 600px) and (max-width: 800px) {
a.button {
//your rules for that
}
}
and so on.
Answer in english: Your desktop's resolution is not the same as the laptop you viewed, therefore those rules you set for it are still applied on the laptop, it looks different because of the resolution.
Also, a mistake I ran into as a novice web developer was positioning how you are, I would suggest not positioning that way, look up on google examples of good positioning methods, perhaps using percents instead of static values in pixels.
this is what i have came up with .. let me know what you think ?
a.button {
position:absolute;
display:block;
margin-left:auto;
margin-right:auto;
}
#media screen and (min-width: 1500px) and (max-width: 2500px) {
a.button.testing-link {
width:250px;
height:87px;
background:url();
top:753px;
left:750px;
}
}
#media screen and (min-width: 600px) and (max-width: 1499px) {
a.button.testing-link {
width:250px;
height:87px;
background:url();
top:0px;
left:0px;
}
}
#media screen and (min-width: 1500px) and (max-width: 2500px) {
a.button.testing2-link {
width:250px;
height:87px;
background:url();
top:753px;
left:50px;
}
}
#media screen and (min-width: 600px) and (max-width: 1499px) {
a.button.testing2-link {
width:250px;
height:87px;
background:url();
top:0px;
left:0px;
}
}
#media screen and (min-width: 1500px) and (max-width: 2500px) {
a.button.testing3-link {
width:250px;
height:87px;
background:url();
top:753px;
left:340px;
}
}
#media screen and (min-width: 600px) and (max-width: 1499px) {
a.button.testing3-link {
width:250px;
height:87px;
background:url();
top:0px;
left:0px;
}
}
Related
Codepen here: https://codepen.io/codepenuserpro/pen/ExQrEbo
HTML:
<div></div>
CSS:
div
{
height:400px;
width:400px;
background-color:red;
}
#media only screen and (min-width: 1068px) and (max-width: 1380px)
{
background-color:blue;
}
Why isn't the div changing background color even when I resize the browser window to between 1068 - 1380px?
Media Query Syntax
A media query consists of a media type and it can contain one or more expressions, which resolve to either true or false.
If it resolves to true, the css code inside of it is applied.
#media not|only mediatype and (expressions) {
<stylesheet>
}
You must select the element- div in this case, inside the media query as of the following.
#media only screen and (min-width: 1068px) and (max-width: 1380px) {
div {
background-color:blue;
}
}
div {
height: 400px;
width: 400px;
background-color: red;
}
#media only screen and (min-width: 1068px) and (max-width: 1380px) {
div {
background-color: blue;
}
}
<div></div>
You need to select the selector(div) inside media query.
try this:
#media only screen and (min-width: 1068px) and (max-width: 1380px){
div{
background-color:blue;
}
}
You didn't select the div in the second approach.
You may want to have this:
#media only screen and (min-width: 1068px) and (max-width: 1380px) {
div {
background-color: blue;
}
}
I do have the viewport line in my code, btw. Below is my CSS - I suspect I've made an obvious error, but just am not seeing it! The text and images do flow into the expected one column, but the narrower divs remain narrow, the background image still shows, the images still full size. Please advise.
.cont { width:100%; max-width:1000px; position:relative; margin:0 auto; font-family:Arial, Helvetica, san serif; font-size:1em; text-align:left; }
.hdr { width:100%; max-width:1000px; position:relative; margin:0 auto; }
.row1 { width:100%; position:relative; background:url(https://myimagefiles.com/dinnerman/tbg.png); float:left; }
.row1l { width:26%; position:relative; margin-left:2em; float:left; }
.row1r { width:64%; position:relative; margin-left:2em; margin-right:2em; float:left; }
.row2 { width: 94%; position:relative; text-align:left; margin:0 auto; }
.row3l { float:left; width: 45%; position:relative; text-align:left; margin:0 0 0 2em; }
.row3r { float:left; width: 45%; position:relative; text-align:left; margin:0 0 0 2em; }
.grntxt { color:#207815; }
.bott { width:100%; height:19px; )
#media only screen and (max-width: 750px) {
.cont { width:100%; }
}
#media only screen and (max-width: 750px) {
.hdr { width:94%; }
}
#media only screen and (max-width: 750px) {
.mimg { width:94%; }
}
#media only screen and (max-width: 750px) {
.row1 { width:94%; margin-left:.2em; margin-right:.2em; background-image:none;}
}
#media only screen and (max-width: 750px) {
.row1l { width:94%; margin-left:.2em; margin-right:.2em; background-image:none;}
}
#media only screen and (max-width: 750px) {
.row1r { width:94%; margin-left:.2em; margin-right:.2em; background-image:none;}
}
#media only screen and (max-width: 750px) {
.row2 { width:94%; margin-left:.2em; margin-right:.2em; }
}
#media only screen and (max-width: 750px) {
.row3l { width:94%; margin:0 auto; }
}
#media only screen and (max-width: 750px) {
.row3r { width:94%; margin:0 auto; }
}
#media only screen and (max-width: 750px) {
.bott { display:none;}
}
You have a typo
.bott { width:100%; height:19px; )
Should terminate with a } not a )
.bott { width:100%; height:19px; }
You should use a CSS linter (such as CSSLint) to make sure you're not making any typos. They can be run as separate tools, as part of your build chain (Grunt, Gulp, Webpack, etc.) or directly in any proper IDE (Sublime, Atom, etc.). There's also online versions like this one which I used to track down the errors in your code. They're good for quick checks like this, but not suitable for a real development workflow.
Additionally, you should really group your media queries
#media only screen and (max-width: 750px) {
.cont { width:100%; }
.hdr { width:94%; }
.mimg { width:94%; }
...
}
There's no need to have separate ones for each set of styles you're applying.
I have the following media queries set up in my stylesheet, cna anybody tell me why the bottom query doesn't override the first query?
#media screen only and (max-width:992px) {
.some-element {float:left;}
}
#media screen only and (max-width:768px) {
.some-element {float:none;}
}
Try #media screen instead of #media screen only. The bottom query does override the top one.
#media screen and (max-width:992px) {
.some-element {
float:left;
background-color: #f00;
}
}
#media screen and (max-width:768px) {
.some-element {
/** See how the background-color property is overriden */
background-color: #000;
color: #fff;
}
}
<div class="some-element">Hi. I am floating.</div>
<h1>I am a block element</h1>
You wrote the media query in the wrong order, the only (or 'not') should come right after the '#media'.
Like this:
#media only screen and (max-width:992px) {
.some-element {float:left;}
}
#media only screen and (max-width:768px) {
.some-element {float:none;}
}
I'm trying to make a background image fill up (in height) when going mobile. When I make the browser smaller, it doesn't seem like my media queries are kicking in.
Here's what my css looks like:
#main {
background-image:url(../images/cc.jpg);
height:650px; background-size:cover;
background-position:0 -210px;
background-repeat:no-repeat;
}
#main .row {
margin-top:200px;
}
#media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
#footer {
font-size:10px;
}
#main {
background-image:url(../images/cc.jpg);
height:100%;
background-size:cover;
background-repeat:no-repeat;
}
#id{ margin-top:90px; }
#main .row {
margin-top:100px;
}
}
#media only screen and (min-device-width : 320px) and (max-device-width : 568px) and (orientation : landscape) {
#footer {
font-size:10px;
}
#main {
background-image:url(../images/cc.jpg);
height:100%;
background-size:cover;
background-repeat:no-repeat;
}
#id{ margin-top:90px; }
#main .row {
margin-top:100px;
}
}
Here's the URL if you want to see what the page looks like:
http://www.gulflifehomes.com/
Change to background-position: center; and that should do the trick. Also, you should try and one-line your code when possible background: url(../images/cc.jpg) no-repeat center center fixed;.
If you want to test media queries on desktop, you should use min-width or max-width instead of min-device-width or max-device-width.
So do this:
#media only screen and (min-width : 320px) and (max-width : 480px)
min-device and max-device refers to the ACTUAL resolution of your screen (ie: 1280x800) instead of the size of your browser. This is why your media queries isn't kicking in when resizing browser and testing on your machine.
Remove the background-position rule or reset it to 0 for mobile if you still want it in place for desktop.
You have a lot of repetitive code there. You could just do this:
#main {
background-image:url(../images/cc.jpg);
height:650px; background-size:cover;
background-position:0 -210px;
background-repeat:no-repeat;
}
#main .row { margin-top:200px; }
#media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
#footer { font-size:10px; }
#main { background-position: 0; }
#id{ margin-top:90px; }
#main .row { margin-top:100px; }
}
I want my page look nice with iphone4 and iphone 5. I wrote some media queries, but it seems they are ignored:
#media only screen and (max-device-width: 480px) {
#gpsMain{
position:absolute;
top:25px;
left:20%;
}
}
#media only screen and (max-device-width: 320px) {
#gpsMain{
position:absolute;
top:11px;
left:20%;
}
}
Why the styles are not applied? Is this the correct way to get resolutions of the two iphone?
(The queries are the last thing I wrote on css document)
Double check to see if you have a viewport set. Not sure if it matters but I always see media queries formatted like so:
#-ms-viewport {
width: device-width;
}
#viewport {
width: device-width;
}
#media screen and (max-width: 400px) {
.list-view .site-content .post-thumbnail { background: none; width: auto; z-index: 2; }
}
This is from the 2014 wordpress theme. http://www.responsinator.com/ is a good place to double check how things are looking.
Try change into this:
#media screen and (max-device-width: 480px) {
#gpsMain{
position:absolute;
top:25px;
left:20%;
}
}
#media screen and (max-device-width: 320px) {
#gpsMain{
position:absolute;
top:11px;
left:20%;
}
}