I am learning the basics of responsive design, and started from scratch. I want a very simple page with no margin on the sides. Yet on an iphone, the site has still a fairly big white margin left and right. This is the CSS i have so far:
div#header_image img{
max-width:100%;
}
div#chart img{
max-width:100%;
}
div#Chart_place{
margin-bottom:2em;
}
#media screen and (min-width: 800px) {
div#container{
width:800px;
margin: 0 auto;
}
}
#media screen and (max-width: 800px) {
div#container{
width:max-width;
margin: 0;
padding: 0;
}
}
body{
font-family:Verdana, Geneva, sans-serif;
margin:0;
}
h1{
font-size: 1.5em;
margin-top:2em;
margin-bottom:2em;
}
ul{background-color:white;}
div#Feesboek_button{
}
input[type='text'], textarea {font-size:16px;}
What do I do wrong?
EDIT/UPDATE: Since my previous answer is not what you where looking for, use this:
html,body { margin:0; padding: 0; }
#container {
max-width: 800px;
padding: 0;
margin: 0 auto;
/*for ilustration purposes*/
background-color: #f13700;
}
#media (max-width: 800px) {
#container {
padding: 0;
margin: 0;
}
}
There you go, no margins on 800px or less.
See it here: http://jsfiddle.net/fCzT9/
Full screen: http://jsfiddle.net/fCzT9/embedded/result/
Previous answer:
In your CSS you have:
#media screen and (min-width: 800px) {
div#container{
width:800px;
margin: 0 auto;
}
This will be applied for every device with a screen that is at least 800px. You have declared the width with a fixed 800px and margin: 0 auto will center that container with 800px in the screen. Take into account that your device might have a high density screen (called Retina in iPhones).
The solution to your problem depends on how your layout is based, but try this:
#media screen and (min-width: 800px) {
div#container{
width: 100%;
max-width: 80em;
margin: 0 auto;
}
This way, the maximun width will be 80 times the base font-size, 16px, resulting in 1280px. As the width is declared with 100%, it will take the available width in the screen. If the screen is bigger than 1280px, it won't go beyond it since it's the max-width.
Note: If you are not using box-sizing: border-box, if you add padding to the class which already has width:100%, the padding will be added as an extra to the element's resulting width which will cause it to go beyond the max-width and in small screens you will be able to side scroll your pages = not good.
Related
I have the content of my page wrapped inside a mycontainer div.
The stuff should be aligned in the center of the page using a big device and left when using a small device.
I defined a margin and the with of the container, which works flawless on the desktop. However the media query is not used on smartphones. Where is my mistake?
.mycontainer {
margin: 0 auto;
width:50%;
#media only screen and (max-width: 767) {
margin:0 auto;
width:100%;
}
}
Edit: deleting margin: 0 auto in the media query does not change anything
#media ... should be on the root level. You'll see #media queries used within selectors like you have it above, but that is only possible within CSS pre-processors like Sass. The correct way in plain CSS is as follows:
.mycontainer{
margin: 0 auto;
width:50%;
}
#media only screen and (max-width: 767px) {
.mycontainer{
margin:0 auto;
width:100%;
}
}
You must have to mention proper size.
.mycontainer{
margin: 0 auto;
width:50%;
#media only screen and (max-width: 767px) {
margin:0 auto;
width:100%;
}
}
I'm trying to utilize max-width on a button with a margin-left and margin-right set to 28px.
When my site is shrunk down for mobile, this button still retains its margins and carries over off-screen. How can I fix this?
Here's my CSS for the button:
.button {
border: 1px solid;
border-color: #5094CF;
background: #FFFFFF;
width: 450px;
max-width: 100%;
height: 48px;
margin: 0 28px 0 28px;
}
You need mediaqueries for all resolutions you need, for example:
#media (max-width: 600px) {
.box {
margin: 0;
}
}
#media (max-width: 400px) {
.box {
margin: 10px;
}
}
Different margins depending on the resolution of the client.
Good luck
There's a pleasantly easy fix for your issue, try this:
#media all and (max-width: 658px) { // for mobile devices
.button{
// your preferred styling properties for displaying in mobile devices
}
}
I'm currently playing with bootstraps v2.3.2. media querys (I'm not using bootstraps grid, just those 4 media queries) to test them on mobile and tablet devices, and I notice that I keep getting a horizontal scrollbar and I don't understand why?
Basically I have one div and this CSS:
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
body{
margin:0;
/* height: 3000px; */ /* forced vertical scrollbar */
height: 300px;
}
div{
padding: 0 10px;
margin: 0 auto;
background: aqua;
width: 980px;
border: 1px solid black;
height: 100%;
}
/* Large desktop */
#media (min-width: 1200px) {
div{
background: red;
width: 1200px;
}
}
/* Portrait tablet to landscape and desktop */
#media (min-width: 768px) and (max-width: 979px) {
div{
background: yellow;
width: 768px;
}
}
/* Landscape phone to portrait tablet */
#media (max-width: 767px) {
div{
background: blue;
width: 100%;
}
}
/* Landscape phones and down */
#media (max-width: 480px) {
div{
background: green;
}
}
Situation when I force vertical scrollbar: JSBin
But when I don't force vertical scrollbar, I get the wanted result: JSBin
So it's obviously due the vertical scrollbar. I found this article about scrollbar issue in Responsive Web Design, but I get the same result in both Chrome and FF.
Update: as looking the source of bootstrap v3.3.2 I've noticed that they have new media queries, however, they don't use the minimal possible width for the .container. This are their media queries:
#media (min-width: 768px) {
.container {
width: 750px; /* 18px difference */
}
}
#media (min-width: 992px) {
.container {
width: 970px; /* 22px difference */
}
}
#media (min-width: 1200px) {
.container {
width: 1170px; /* 30px difference */
}
}
And here's the JSBin. Even when I forced the vertical scrollbar to appear, this won't trigger the horizontal scrollbar.
But if I want to use the minimal possible width for the media queries, like:
#media (min-width: 768px) {
.container {
width: 768px;
}
}
#media (min-width: 992px) {
.container {
width: 992px;
}
}
#media (min-width: 1200px) {
.container {
width: 1200px;
}
}
This will trigger the horizontal scrollbar - JSBin
Did the guys from bootstrap did that on purpose, because of the possibly that there can be the presence of vertical scrollbar?
Question: Why can't I use the minimal possible width in the media query when the vertical scrollbar is present?
I know that this may be a novice question, but I would appreciate if someone clarify this for me.
Bootstrap Media Querys
Setting media query
Bootstrap supports four media sizes:
Phones < 768px (8 inch)
Tablets ≥ 768px
Desktops ≥ 992px (10.33 inch)
Desktops ≥ 1200px (12.5 inch)
These are not fixed sizes!
If you have a screen that has a min-width of 768px the media query should trigger.
However setting a container to 768px will almost allways make that screen overflow
First of all the body element of all modern browser does have a margin to it.
example: Webkit browsers: body {margin: 8px;} so if your element of 768px and a margin-top of 8 and margin-bottom of 8 you get: 784px
so your screen is 768px (or less) and your content is 784px this will make it overflow (as it should). That said bootstrap sets: body {margin:0;}
An other example would be border. Border adds size to your element unless box-sizing isn't default. While outline sets the border inside your element.
Did the guys from bootstrap did that on purpose, because of the possibily that there can be the presence of vertical scrollbar ?
There is a possibility of that but i would think they set it because there is a bunch of css property's that affect size, so they gave a margin of error so to speak to avoid strange behavior like a horizontal scroll bar popping up.
Question: Why can't I use the minimal possible width in the media query when the vertical scrollbar is present?
You can use it: Fiddle!
Just Remember that some browsers will render it with a certain width.
Checkout the fiddle
https://jsfiddle.net/YameenYasin/as4Lmgas/1/
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
body{
margin: 0;
}
div {
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
background: blue;
height:auto;
min-height:300px; // For testing purpose only
}
#media (min-width: 768px) {
div {
width: 750px;
background: silver;
}
}
#media (min-width: 992px) {
div {
width: 970px;
background: yellow;
}
}
#media (min-width: 1200px) {
div {
width: 1170px;
background: red;
}
}
<div></div>
I'm having some odd space issues on the left of my site. For some reason there is slightly more space on the left than on the right in mobile view, thus looking off-centered. I'm guessing its off for desktop view as well, but its not noticeable. I can't figure out what is making it this way. http://jeffreydowellphotography.com/
/* ---------->>> MOBILE gap/space issues <<<-----------*/
#media screen and (max-width: 400px) {
#pageWrapper { margin: 0;}
.sqs-layout .sqs-row .sqs-block:last-child {
padding-bottom: 0;
padding-top: 0;
}}
/* ---------->>> MOBILE center logo <<<-----------*/
#media only screen and (max-width: 400px) {
h1.logo {
text-align:center;
margin-bottom: 20px !important;
}}
/* ---------->>> MOBILE logo size <<<-----------*/
#media only screen and (max-width: 400px) {
.logo-image .logo img {
max-height: 110px;
margin: 5px;
width: auto;
}
.social-links {
padding-top: 20px;
}}
Try removing the margin: 5px; on .logo-image .logo img in your mobile styles. The image with the margin may be wider than the div that contains the image and it comes off as being non-centered.
UPDATE
I took a look at your site, its actually the margin on the .slide selector. Add this in your mobile styles:
.slide { margin: 0; }
I'm using these media queries in CSS to make my footer responsive.
I want to make the 3 columns (#footer-left, #footer-middle, #footer-right) automatically move under each other when the screen is made smaller.
what would be the best way of doing this? I have a fiddle here: jsfiddle
/* for 980px or less */
#media screen and (max-width: 980px) {
#footer-left {
width: 41%;
padding: 1% 4%;
}
#footer-middle {
width: 41%;
padding: 1% 4%;
margin: 0px 0px 5px 5px;
border-right:none;
}
#footer-right {
padding: 1% 4%;
}
#footer-bottom {
display:none;
}
}
/* for 800px or less */
#media screen and (max-width: 780px) {
#footer-left {
border-right:none;
}
#footer-middle {
margin-left: 0px;
border-right:none;
}
}
/* for 700px or less */
#media screen and (max-width: 700px) {
#footer-left {
border-right:none;
}
#footer-middle {
margin-left: 0px;
border-right:none;
}
}
/* for 480px or less */
#media screen and (max-width: 480px) {
#footer-right {
display: none;
}
}
Just make your #footer-left, #footer-middle, and #footer-right divs all be width:100% when you want them to stack, with float:none on each of them. Your width may need to be less than 100% if you keep padding on any of the divs (in your case, width would be 92%, since you've got it set up for 4% padding on left and right of each div).