0

The width and hight of following code change, on the change of resolution of different devices.

<div style="background-color:orange;height:125px;width:75px;">
This div has height and width applied.
</div>

Is there any way to prevent change of width and height and make it retain same width and height for all resolution.

Note: For this I have also tried with zooming ( in and out ) the html page which changes the width and height of the div.

12
  • By resolution do you mean pixel density, or screen/viewport size? Technically speaking with height and width explicitly declared, the element should stay the same size. Commented Apr 21, 2014 at 13:36
  • @Terry I mean both, pixel as well as screen/viewport size Commented Apr 21, 2014 at 13:38
  • You could use 'cm' for example or 'dppx' Commented Apr 21, 2014 at 13:38
  • You are defining the height and width in px. It should stay same Commented Apr 21, 2014 at 13:38
  • If you mean you want to maintain scale, you should look at using <meta> tags: <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"> Commented Apr 21, 2014 at 13:39

3 Answers 3

1

you need to probably add a viewport meta between your head tags:

<meta name="viewport" content="initial-scale=1">

http://webdesign.tutsplus.com/articles/quick-tip-dont-forget-the-viewport-meta-tag--webdesign-5972

Sign up to request clarification or add additional context in comments.

Comments

0

Use percentage instead of fixed pixels like :

<div style="background-color:orange;height:20%;width:20%;">

this will retain height and width on page resizing

1 Comment

I want to specify only in pixel
0

U can resize with the @-viewport CSS Declaration! This is best practice

1 Comment

could you describe a little.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.