-6

How to set the value to my margin property when I want to responsive it? I mean, if I want to set value to width, for example to 50%

So what if I want to set with margin? I have to set it in em is it right? or font size: em because pixel is a absolute unit but em is a relative unit, is that right?

Maximilian Fixl
  • 670
  • 6
  • 23
ali
  • 11
  • 6

1 Answers1

-1

Google is your friend.

Responsive design is based off of certain pixel breakpoints where you decide to adjust components.

For example:

 @media screen and (max-width: 500px) {
      body {background-color: green;}
 }

This will change the background color of the body element to green when the browser window's width is <= 500px.

The Mozilla reference is a good place to start. Take a read and let us know if you have more specific questions.

Welcome to SO.

sheng
  • 1,226
  • 8
  • 17
  • I know that but When I want to create a template I use px unit for all elements like : margins-width-paddings-fontsize everything – ali Nov 04 '17 at 12:26
  • But now I want to responsive my web page and somebody said that you have to use em and % units for your elements – ali Nov 04 '17 at 12:28
  • @ali `em`s are based off of `font-size` and percentages are based off of dimensions (browser width, parent element dimensions, etc.). People do recommend using `em`s on margins and paddings, but I would recommend you stick with percentages for dimensions and `em`s for fonts. It's a personal preference, really. Hopefully that helps... – sheng Nov 04 '17 at 12:32
  • Thank you soooooooo much bro – ali Nov 04 '17 at 12:34