Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change CSS only for mobile devices? [duplicate]

Tags:

html

css

mobile

web

I just finished creating my website but now I have found a failure. My problem is that my website looks totally nice on the PC. But if I go and look at it from my mobile phone, the spaces between certain images etc. are a great deal too much...

So my question is, how can I create some CSS codes who are only affecting the mobile devices and maybe tablets?

Is there a way?

like image 415
Jan Avatar asked Mar 03 '17 18:03

Jan


People also ask

Can we do CSS in mobile?

The pro version of W3.CSS is perfect for mobile apps. It is small and very fast.


2 Answers

CSS has feature called media queries. From the MDN link:

Media queries, added in CSS3, let the presentation of content be tailored to a specific range of output devices without having to change the content itself

For example:

div {
    background: black;
}

@media (max-width: 1000px) {

      div {
            background: yellow;
       }

}

The background color of this div will be yellow on screen under 1000px width like in the example provided.

like image 146
Eyal Cohen Avatar answered Oct 25 '22 17:10

Eyal Cohen


You can use media-queries for different screen resolutions. Example -

#image img {
    width:375px;
}
@media screen and (min-width: 1366px) {
    #image img {width:375px;}
}
like image 42
Purvil Bambharolia Avatar answered Oct 25 '22 18:10

Purvil Bambharolia