How to make a div element responsive

So, on my small website, I have a div that I created using CSS, and when I tested different resolutions, the box looked distorted on a small 11-inch screen compared to my 27-inch screen. How can I make my pixel size of 200 pixels in size of 200 pixels the same for all monitor sizes.

thanks

There is CSS for the DIV here:

text-align:center; border:3px solid black; padding-bottom:10px; height:700px; width:200px; background-color: white; margin-right: 2cm; margin-top: -19cm; margin-left: auto; 
+5
source share
5 answers

You need to add a meta tag to identify width requests and media to perform the action when the width is different. It would also be useful to add a percentage to your css elements, not pixels.

HTML code:

 <!doctype html> <meta name="viewport" content="width=device-width"/> 

add a meta tag so that the page identifies the width of the device. see mozilla will take it

In this example, the query will be applied for four different device widths in the <p> and in the background.

 <body> <h1>Media Queries Examples</h1> <p>Increase or decrease the size of your window to see the background color change</p> </body> 

CSS code:

 p { font-family: arial,san-serif; font-size: 13px; font-color: black; } h1 { font-size:30px; } @media screen and (min-width:761px) { body { background-color:white; } h1 { color:red; } } @media screen and (max-width:760px) { body { background-color: #333; } h1 { color:red; } p { color: white; } } @media screen and (max-width:480px) { body { background-color: #807f83; } h1 { color:white; } p { color: white; } } @media screen and (max-width:360px) { body { background-color: #0096d6; } h1 { color:white; font-size:25px; } p { color: white; } } 

So using @media Screen inside your css triggers a request for the screen. You can use @Media all for all media devices (see Further reading), when the width of the device reaches the limits of this request, then css will be applied to the element in question. see current example . When you drag the window in the JSFiddle window, it will change the background color and the recording color if the request is executed. You can apply the same logic to phones, tablets, TVs and desktops. Media Queries for Standard Devices - CSS Tricks

This example was provided by an anonymous JSFiddle user. It gives a clear example of what you need to make sure that your elements are designed in accordance with this unit. I do not take a loan.

additional literature
- Microsoft - Media Requests
- @ Media Rules - W3C
- Responsive Web Design Wiki

+4
source

You need to make your site responsive so that we use something called media queries , which is basically just extra markup in the css syntax.

An excellent structure to use, since you are just starting out with a responsive design, Bootstrap will be used, it is easily customizable to your project needs.

It should also help you better understand how fluid systems are integrated into your site.

Hope this helps!

+2
source

In addition to what Jordan said. This is a great place to learn about media queries and responsiveness: https://www.udacity.com/course/mobile-web-development--cs256

+2
source

You can do this to resize the page to fit any screen:

 body { background: white; width: 100%; } .content { width: 100%; } .paragraphs { width: 50%; margin: 0 auto; } 
 <html> <head> <title>Example of resizing</title> </head> <body> <div class="content"> <div class="header"> <h1>Header</h1> </div> <div class="paragraphs"> <p>#000000 color RGB value is (0,0,0). This hex color code is also a web safe color which is equal to #000. #000000 color name is Black color. #000000 hex color red value is 0, green value is 0 and the blue value of its RGB is 0. Cylindrical-coordinate representations (also known as HSL) of color #000000 hue: 0.00 , saturation: 0.00 and the lightness value of 000000 is 0.00. The process color (four color CMYK) of #000000 color hex is 0.00, 0.00, 0.00, 1.00. Web safe color of #000000 is #000000. Color #000000 rgb is equally color.</p> </div> </div> </body> </html> 

thanks

0
source

There are many ways to make a DIV responsive. The easiest way is to use a framework like bootstrap that does all your work.

Another way is to use @media('max-width: 1024px'){//code...} so you determine what happens at every screen resolution you want.

0
source

All Articles