in Education by
I am fairly new to CSS Media queries. I am actually trying to adjust left margin for a button ('Add+' button as shown in the attached image) for different screen widths. I am trying to do this: @media only screen and (min-width: 200px) and (max-width: 350px) { .button_orange_extended { margin-left:0px; } } /*Media query for one specific screen width*/ @media only screen and (min-width: 360px) and (max-width: 400px) { .button_orange_extended { margin-left:30px; } } /*Another Media query for specific screen width*/ @media only screen and (min-width: 400px) and (max-width: 450px) { .button_orange_extended { margin-left:80px; } } By this means, i got to write this code around 10-12 times and adjust margin accordingly. Considering that i need to adjust margins not only for mobiles but for other devices like tablets. So, is there an short alternative approach? (Below is the image). JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Instead of using px, you can use em. ems are relative to the current font size, whereas px is an absolute unit of measurement. So if you used em on all your elements, you could just change the body's font-size. This way, you won't have to set the size of every element per every different screen width, you'll only have to change the font size. I've used http://pxtoem.com/ for converting from px to em, I'd recommend it for beginners. Also, a very good post describing why you should use em instead of px: Why em instead of px?

Related questions

0 votes
    I am fairly new to CSS Media queries. I am actually trying to adjust left margin for a button (' ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 8, 2022 in Education by JackTerrance
0 votes
    I am fairly new to CSS Media queries. I am actually trying to adjust left margin for a button (' ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 12, 2022 in Education by JackTerrance
0 votes
    I have a problem with table-layout:fixed and width of inner columns if their content wider than column. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Aug 1, 2022 in Education by JackTerrance
0 votes
    I am exploring Float Label pattern for web page using HTML and CSS. The code was referred from http: ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 27, 2022 in Education by JackTerrance
0 votes
    I use the vendor time picker component. Unfortunately, it uses rem units for most of its sizes, but ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I'm unable to change/remove the link underline and color of the nested text. I checked the debug ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    What are the Advantages of CSS?...
asked Mar 3, 2021 by JackTerrance
0 votes
    I styled a button: .subscribe_button { background-color: red; } .subscribe_button:hover { background-color: ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I have a div and an iframe on the page the div has z-index: 0; the iframe has its content with ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    I have a div and an iframe on the page the div has z-index: 0; the iframe has its content with ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    I have a div and an iframe on the page the div has z-index: 0; the iframe has its content with ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    I have a div and an iframe on the page the div has z-index: 0; the iframe has its content with ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    I have a div and an iframe on the page the div has z-index: 0; the iframe has its content with ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    I am implementing a design that uses custom styled submit-buttons. They are quite simply light grey buttons ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    It took me forever to reduce the problem to this. I cannot express the amount of frustration I'm ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 5, 2022 in Education by JackTerrance
...