I am new to coding and I have created a website with lots of margin and padding values. So is there a logical way to make it responsive?
Margin and padding shouldn't really matter when it comes to making a responsive site. To make a site responsive, one of the big things is working on making the site width's into percentages. Also, finding a good framework can help a lot. I would suggest looking into bootstrap or foundation.
http://getbootstrap.com/css/#overview
You need to apply new margins and paddings inside Bootstrap breakpoints.
Pick only the one you need.
Some tips how to reduce amount of responsive code:
Group elements which resize in the same way with one classname, then apply new sizes only for the group of the same classname.
Apply responsive size for columns, like col-xs-12, col-sm-6, col-md-4
Don't re-style all elements for every breakpoint, if you don't have to. Check if a website is looking good on a big screen, then resize browser and restyle only this elements which break on a smaller screen.
Reduce the number of breakpoints to minimum, for example: 1. mobile devies, 2. tablets, 3. desktops.
css:
/* Large Devices, Wide Screens */
#media only screen and (max-width : 1200px) {
}
/* Medium Devices, Desktops */
#media only screen and (max-width : 992px) {
}
/* Small Devices, Tablets */
#media only screen and (max-width : 768px) {
}
/* Extra Small Devices, Phones */
#media only screen and (max-width : 480px) {
}
/* Custom, iPhone Retina */
#media only screen and (max-width : 320px) {
}
Related
I am making a parallax site using http://keithclark.co.uk/articles/pure-css-parallax-websites/.
I have finished it all and looks great, but if i resize my screen window all items inside go over each other. My question now is how can i make a responsive that 'deletes' the paralax when the screen size is about an ipad size or smaller. So that i have 'normal' pages.
Just wrap your code with a #media query, e. g.:
#media (min-width: 700px) {
// your code
}
Then this code will only apply on a screen with a min-width: 700px.
I'm using CSS #media to adjust my website depending on the screen resolution
Whether i switch to a resolution with the height of 768 or 720 it will still act as if i'm my screen resolution has a height of 720px
.group-container{
min-width:1210px;
max-width:70000px;
width:1210px;
margin-left:2.5%;
height:87%;
margin-top:1%;
}
#media only screen and (max-height: 768px) {
.group-container{
margin-top:150px;
}
}
#media only screen and (max-height: 720px) {
.group-container{
margin-top:3px;
height:90%;
}
}
For the first media query you should use also a min-height set to 720px and max-height set to 768px
And if you try to use (max-width: ...px) instead?
#media only screen and (max-width: 720px) {
.group-container{
margin-top:3px;
height:90%;
}
}
This way you won't rely on your height, but the width of the window it's being displayed on. example:
your resolution is 900x1600.
Resizing the height of the window wouldn't have much effect. If you where to use max-width, that way if you resize to 600x1200 for example, it would have more effect.
EDIT: The reason why I think you should use is, the height doesn't really matter when it comes to responsive design. The height might change but it will always be scrollable, so using the height will have little to no effect.
The width of the device DOES matter, the width is important when it comes to responsive design (assuming your website isn't horizontally scrollable). It would be better to create query's based on the width of the display, then to rely on height for that matter.
our site is not responsive, and one of the requirement is to render the images on mobile devices so they fit the screen and we are running into a problem, becasue different sized images are uploaded to a web page
And this is what our CSS code looks like
#media only screen and (min-width : 320px) and (max-width: 640px) {
.article-body div img:not(.logoOP){
width: 320px !important;
height: 214px !important;
}
}
So this works fine for 600 X 400 images, because the aspect ratio is the same. However, when we have a different size images, say 400X578, the above CSS code won't work and the images look really stretched and distorted.
What is a good solution here, since I am no front end Dev.
Any help is appreciated.
Thanks
Modify your CSS to the following:
#media only screen and (min-width : 320px) and (max-width: 640px) {
.article-body div img:not(.logoOP){
width: 320px !important;
height: auto;
}
}
This will allow you to specify the width of the image and the height will automatically adjust itself proportional to the width.
Grid classes apply to devices with screen widths greater than or equal to the breakpoint sizes, and override grid classes targeted at smaller devices. Therefore, applying any .col-md- class to an element will not only affect its styling on medium devices but also on large devices if a .col-lg- class is not present.
Now if we use
<div class="col-lg-4">div 1</div>
<div class="col-lg-4">div 1</div>
<div class="col-lg-4">div 1</div>
It will layout as three columns on a row, when we narrow down the screen size, it will break into three vertical blocks.
So my question is: Do bootstrap do something to make that happen or just leave it as it is?
Any good suggestions when we apply grid classes? Since col-xs-* can also be applied to large screens. So in real lift real project, what does you do?
Thanks.
To answer this question, It's better to understand the way which Twitter bootstrap's grid system work
How Twitter Bootstrap detects devices
Media queries
We use the following media queries in our Less files to create the key
breakpoints in our grid system.
/* Extra small devices (phones, less than 768px) */
/* No media query since this is the default in Bootstrap */
/* Small devices (tablets, 768px and up) */
#media (min-width: #screen-sm-min) { ... }
/* Medium devices (desktops, 992px and up) */
#media (min-width: #screen-md-min) { ... }
/* Large devices (large desktops, 1200px and up) */
#media (min-width: #screen-lg-min) { ... }
By the use of min-width, the following code block would be applied to all screen widths which are higher than the breakpoint value.
E.g. CSS rulesets for medium devices would be applied to devices with screen widths greater than or equal to 992px And in this range of screen sizes, it would override the rulesets belonging to small devices (In compliance with the order of col-sm-* col-md-*).
And for extra small devices, CSS rulesets are not specified by media queries. I.e they're places normally within the stylesheet and they would be applied to elements no matter what the screen width of the device is, unless it get overridden by a #media query.
Considering the following structure (Example here):
<div class="row">
<div class="col-md-8">.col-md-8</div>
<div class="col-xs-6 col-md-4">.col-xs-6 .col-md-4</div>
</div>
The Applied CSS would be:
On extra small devices
first div: Nothing. Hence, as a block level element it fills the entire width of its parent.
second div: .col-xs-6 { width: 50%; }
On small devices
first div: Nothing. Hence, as a block level element it fills the entire width of its parent.
second div: .col-xs-6 { width: 50%; }
On medium devices
first div: #media (min-width: 992px) .col-md-8 { width: 66.66666667%; }
second div: #media (min-width: 992px) .col-md-4 { width: 33.33333333%; }
On large devices
first div: #media (min-width: 992px) .col-md-8 { width: 66.66666667%; }
second div: #media (min-width: 992px) .col-md-4 { width: 33.33333333%; }
As can be seen, the first <div> is displayed as a normal block level element on Extra Small and Small devices while on Medium devices it's affected by the media query.
Therefore, if you decrease the window size to less than 992px, the first <div> will fill the whole of horizontal space within its parent element.
Do bootstrap do something to make that happen(1) or just leave it as
it is(2)?
- (2) is correct: it just leaves it as it is.
When/Where to apply grid classes
Actually it's up to you. However just because col-xs-* can also be applied to large screens, it doesn't mean that it should be or must be.
If you need to break the columns into vertical blocks on extra small devices, start from col-sm-* grid classes. Or if you want to achieve that on small devices, use col-md-* or col-lg-* classes.
And by using col-lg-* you'll override the col-md-* on large devices. Just make sure the order of classes is like so:
<div class="col-xs-* col-sm-* col-md-* col-lg-*">
Is there a way so if a user changes there screen size to less than a certain pixel e.g. 1025px the div will then be scrollable?
I have had a search but I cannot seem to find anything.
Yup
#media only screen and (min-device-width : 1025px) and (max-device-width : 1024px) {
/** STYLES FOR SMALLER SCREENS HERE **/
body { padding:0px; }
}
Im not sure but I feel like it would come automatically as long as scrolling isn't disabled for your div and the position isn't fixed.