CSS website fit to width of device

how to fit web page to screen size in css
viewport width css
how to fit web page to screen size in html
how to make website fit mobile screen
how to make my website resize automatically when the screen resolution changes
auto resize website for mobile
viewport definition
html screen resolution auto adjust

So, I am working on a web project, when I encountered a problem when viewing the website on, pretty much, any mobile device. The problem was that, when you first enter the page, the full width of the page would not be displayed, only a small portion of it. I am looking for a solution to correct this problem, without changing all of my code, or implementing a framework, such as bootstrap.

The domain is the-salon.uk if you would like to see the problem for yourself.

Thanks, all.


How it appears on Desktop - Screenshot

How it appears on mobiles - Screenshot

You could fudge it by explicitly specifying the width in the meta viewport tag... eg:

<meta name="viewport" content="width=1000px, initial-scale=1.0">

To be perfectly clear, that won't make for a great user experience. It's quite bad in fact, but it will keep all of the content on the page. Users will have to pinch-zoom to use anything though.

Like the comments say, you should look into responsive design. It's really too broad a topic for a SO answer, but it involves using a combination of percentage based/flexible items and css media-queries (look it up) to change the layout of the page at certain screen widths.

Hope that helps somewhat! I'd slap in the change to the meta-viewport as a hot-fix since your site is already live, and then go about the process of learning how to make it responsive. I definitely don't advocate using that viewport trick long term.

Has A Viewport Meta Tag With width Or initial-scale, How do I change the width of a device in HTML? @media screen and (max-width:320px) { body { width: 320px; } /* some other style */ } As you can see, I have to set the body width explicitly to make sure it doesn't show the width I set for desktop in my normal css, which is 920px.

If you want everything to fit on the screen, I highly suggest using percentages rather than pixels. Instead of width: 400px, I suggest:

width: 100%

This ensures that the block takes up a certain percentage regardless of which device you are running on.

I can't see your source code, so I can't give any specific feedback. Hope this helps!

Responsive Web Design Viewport, The viewport is the user's visible area of a web page. To fix this, browsers on those devices scaled down the entire web page to fit the screen. particular viewport width to render well - Since screen dimensions and width in CSS pixels vary  On 1 November, the W3C published an Editor's Draft of CSS Device Adaptation, which allows an author to specify the size, zoom factor, and orientation of browser viewport. Matt Rakow explains.

Just add

<meta name="viewport" content="width=device-width, initial-scale=1.0"> 

after the <html> tag. This will make sure your website covers the device's viewport.

how do you fit a webpage size to fit any screen size, ok i will like to know how do you fit your website size to fit any size because it seems that elements of my website are all around the place whenever i shrink the​  The iPhone resolution (and that of all mobile devices) is less than 640 pixels wide. So usually I’ll say if the screen is less than 700 pixels wide, switch to single column mode. We use this code to check for that: @media (max-width: 700px) { /* PUT CSS HERE TO ALTER WEBSITE TO SINGLE COLUMN */ }

Odds are you have width set to an absolute value, I would change this if you have it in the css:


To something more like this


This type of declaration is a relative value meaning it changes with either the size of the browser or the position/size of other elements. If it doesn't resize, odds are you have it set to an absolute value (using the px keyword).This might be useful for you


Oop apparently someone said the exact thing as I was typing this up RIP, GG Knightsoul

How to scale your website across all mobile devices, max-width: 100% helps size the videos to fit the screen. CSS media queries can be used to set the size based on the viewport dimensions. There  Many tablets and mobile devices don’t always have 1 device pixel per CSS pixel. The iPhone 4, for example, has 2 device pixels per CSS pixel. For reference, you should know that the iPhone 4 has a regular screen layout viewport of 640×960. This means that, in this example, the device-width of the iPhone4 is 320×480.

Add this code will fix your problem.

   @media (max-width: 520px) {
     .menu { width: 100%;}
     .menu li {
        float: none
        height: 32px;
        width: auto;
        padding: 0px 6px;
    #greeting {
        padding-right: 25px;
        padding-left: 25px;
    #banner {
        background-repeat: no-repeat;
        width: 100%;
        height: 200px;
        max-width: 800px;
        background-size: contain;
        background-position: center;
        background-image: url(/Images/home_background.jpeg);

Making your Website fit on any Screen, 2% of internet traffic comes from iOS devices, which is more than what the It is possible to make a website that fits on every screen without CSS3 If you wish to call it as a separate stylesheet, make another CSS file and  But this approach is less effective. If user loads the web site from a mobile device. It takes the width from screens 100%, which is very small amount of space. Another approach can be give minimum width with percentages. . WebContainer { width: 100%; min-width: 1000px; height: auto;} In above scenario web site decreases its web site only upto 1000px.

Adjusting your Websites to Fit all Types of Resolution Using HTML , How to Adjust your WebSite to fit all types of Resolution. type="text/css" media=​"only screen and (max-device-width: 480px) , only screen and  But keep in mind, that 100% width (with no parent) equals the width of your browser window. So while your panels are set to 1050 pixels, “100%” will only be as wide as your browser (or device). .grayslide is set to 100%, so that will only be as wide as your browser.

How to Scale Your Website to Perform on Mobile Devices, Video dimensions can be controlled using JavaScript or CSS. The max-width: 100 percent helps to size the videos to fit the screen. CSS media  Depending on both the browser and the user’s zoom settings, all mobile devices in responsive web design relate to a specific CSS width (known as “device-width”). Find your phone screen dimensions below in our handy list of viewport sizes by device.

Using the viewport meta tag to control layout on mobile browsers , Narrow screen devices (e.g. mobiles) render pages in a virtual of 980px, and then it will be shrunk down to fit into the 640px space. value device-width , which is the width of the screen in CSS pixels at a scale of 100%. The viewport-percentage lengths are relative to the size of the initial containing block. When the height or width of the initial containing block is changed, they are scaled accordingly. So, by using viewport-percentage lengths, HTML elements adjust automatically when the height or width of the screen changes.

  • you should research "responsive design". It doesn't require any framework but it can help give you a kickstart if you employ one. Whatever you decide to do, in order to get a decent result it will probably involve a reasonable amount of change to your CSS and some of your HTML, to be perfectly honest. You could just naively do something like set the width to 100% and leave it at that, but the likelihood is it'll just make the site un-readable on mobile because the text will be too small.
  • width:100% or width:100vw (ViewportWidth%)
  • You might find this article helpful: Responsive Web Design Basics @ Google Developer :D