Optimize Your Website for Various Screen Sizes

Can anyone assist with centering my webpage on small screen sizes? Everything looks good at the normal width of 989px, but once it shrinks, it shifts to the left and leaves excess white space on the right. I've tried various methods to correct this issue without success.

I'm reaching out for help from all of you now. Hopefully, someone can provide a solution.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style media="screen" type="text/css">
*{
   margin:0;
   padding:0;
}

body{
   text-align:center; /*For IE6 Shenanigans*/
   min-width:989px;
   margin:0;
   padding:0;

}

#header{background:url(/images/header.png) no-repeat;
border:;
padding:50px 0px 50px 0px;
text-indent:-9999px;
width:100%;
background-size:cover;

}
#menu{background:url(/images/nav-slice.png) repeat-x;
border:;
width:100%;
background-size:100%;
padding-bottom:20px;
padding-top:15px;
-moz-box-shadow: 0px 2px 2px 0px #888; 
-webkit-box-shadow: 0px 2px 2px 0px #888;  
box-shadow: 0px 2px 2px 0px #888;  
}

ul{padding:0;
margin:0;
overflow:hidden;
list-style-type:none;

}

li{

float:left;
display:inline-block;
padding-left:17%;/*70 divided by 800*/
padding-right:8%;
font-size:1em;

}

a.ali{text-decoration:none;
color: white;
padding-top:10px;
padding-bottom:0px;
text-align:center;
font-family:helvetica;
font-weight:bold;
font-size:1em;

}

a.ali:hover{color:blue;
}

#content{

padding:180px 0px 0px 0px;

float:left;
width:100%;
margin-top:20px;
margin-left:4.044%;/*40px*/
margin-right:2.022%;/*20px*/
margin-bottom:0px;
}


#footer{background:url(/images/footer-slice.png) repeat-x;
padding:15px 0px 15px 0px;
border:;
float:left;
width:100%;
margin-top:-40px;
}

a.tou{
font-family:arial;
text-size:10px;
color:white;
text-decoration:none;
}

a.tou:hover{
color:blue;
}

p{
font-family:arial;
text-size:10px;
color:white;

}

#wrapper{
margin-left:auto;
margin-right:auto;
width:80%;/*989px*/
max-width:80%;
min-width:989px;
-moz-box-shadow: 0px 0px 5px 5px #888; 
-webkit-box-shadow: 0px 0px 5px 5px #888;  
box-shadow: 0px 0px 5px 5px #888;  
}

.clear {
clear:both;
}

.title{
font-family:myriad pro;
color:#2e4d9b;
position:relative;
bottom:180px;
right:350px;
}

.sales-page{
background:url(/images/sales-page.png) no-repeat;
float:left;
position:relative;
bottom:140px;
left:6%;
padding-top:426px;
width:100%;
max-width:100%;
margin-bottom:-100px;
clear:both;
}

.get-website-now{
background:url(/images/get-website-now.png) no-repeat;
padding-top:40px;
padding-bottom:40px;
padding-left:18.20%;/*180px*/
padding-right:18.20%;
float:left;
position:relative;
bottom:230px;
left:31%;
margin-top:0px;
clear:both;
}
.get-website-now:hover{
opacity:0.9;
}

</style></head><body>

<div id="wrapper">

<div id="header">
<h1>Your Name And Logo</h1> 
</div><!--end header-->
<div id="menu">
<ul>
<li><a class="ali" href="index.html">Home</a></li>
<li><a class="ali" href="products.php">Products</a></li>
<li><a class="ali" href="contact.php">Contact</a></li>

</ul>
</div><!--end menu-->
<div id="content">
<h1 class="title">Home</h1>
<div class="sales-page"></div>
<a href="products.php" class="get-website-now" style=""></a>
</div><!--end content-->

<div id="footer">
<p><a class="tou" target="_blank" href="/terms-and-conditions.html">Terms and Conditions Five80Nine Web Design All Rights Reserved 2013</a></p>
</div><!--end footer-->
<div class="clear"></div>

</div><!--end wrapper-->

</body>
</html>

Visit my site here:

Answer №1

To prevent these types of issues, it's best to avoid using percentages for your width and instead opt for a fixed width on your wrapper. Additionally, as suggested by Macky Nyxzz, adding the following CSS code to your wrapper will center it on any screen resolution:

margin: 0 auto

I have encountered similar problems in the past and this solution worked for me. For more information on how to center a website with CSS, I recommend checking out this resource. Hopefully, this advice is useful for you. :)

UPDATE: To test how your website appears in different screen resolutions, you can use the tool available here.

Answer №2

   #container{
       margin: 0 auto;
    }

By adding 'auto' to the margin property, your div will be centered on all screen resolutions.

Answer №3

After some tinkering, I was able to resolve the issue by inserting a table around the wrapper and adjusting the width until achieving perfect center alignment for the page. This adjustment has successfully centered the page across various screen sizes, including tablets and mobile devices.

If there are any alternative solutions out there, I am open to suggestions. Please share your insights! :)

Answer №4

Ensure all content in the body is wrapped in article tags, then use CSS to center align the text and contain all main tag elements within these new tags. Apply margin: 0 auto; for centering, and ensure footer clear: both. Avoid using margin 0 auto on the footer if it matches the width of your header tags. Lastly, refresh your browser and adjust the size to see your document centered.

Cheers!

Mokista

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The cursor remains positioned below the video within the designated div

I'm currently facing an issue in a project where the cursor div I created stays underneath the video element. No matter what I do, I can't seem to bring it to the front. Even setting a z-index on the video tag hasn't helped. Can someone plea ...

Using AngularJS to create a form and showcase JSON information

My code is below: PizzaStore.html: <!DOCTYPE html> <html ng-app="PizzaApp"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Delicious pizza for all!</title> ...

Use jQuery to extract data from the URL instead of relying on PHP

http://h3gsat.altervista.org/DettagliCompleto.php?id=4567 I attempted to extract the id parameter without success. I am attempting to accomplish this using JavaScript (jQuery) instead of PHP, but I am unsure of how to proceed. ...

The Gulp task is not being recognized when I open the project in Visual Studio Code

Whenever I open gulp, I encounter an error related to minifying css and js files using gulp tasks. Despite my efforts to find a solution, the problem remains unresolved. Error Message: assert.js:374 throw err; ^ AssertionError [ERR_ASSERTION]: Task fu ...

Personalize the style of ordered lists

Greetings! I am attempting to customize the style of an ordered list like the one shown in the image on another website. However, instead of the circle used in that picture, I want to use a different CSS Image like the one (without text) shown here I&apo ...

What is the best way to utilize Rselenium's findElement() function in order to target an xpath based on its text content

Despite researching similar questions on stack overflow, I have not been able to make my code work. Here is the initial code I am working with: library(RSelenium) library(rvest) remote_driver <- RSelenium::remoteDriver( remoteServerAddr = "local ...

What are the steps to execute a file on localhost using an HTML page?

Currently, I have an HTML file that leverages the Google Calendar API javascript to read the next event on my calendar. The functionality works flawlessly when manually inserting a specific URL in a browser address window, which triggers a GET request in a ...

Utilizing Ajax to dynamically update the content of a div element

As a newcomer to Ajax, I am trying to use xmlhttprequest to dynamically change the content of a div by fetching HTML from different URLs. However, my code doesn't seem to be working as expected. Can someone help me identify what I might be doing wrong ...

Slider UI handle in jQuery sliding out of the div container

Could you assist me with a technical issue I am facing? I need to know how and where to prevent the .ui-slider-handle from exceeding the div when it reaches 100%. Feel free to check out the live preview at https://codepen.io/Melwee/pen/Exjwoyo I have inc ...

Why does the Autofocus Attribute in HTML5 fail to work specifically in FireFox when <Form><input> elements are dynamically loaded using Ajax?

While testing the form that I loaded via ajax, I noticed an issue with autofocus on the "c_name" field in Firefox. When I access the form directly, the autofocus feature works as expected, but when loading it with ajax, it doesn't seem to work. Surpri ...

Avoiding line breaks when using an :after pseudo element

I am trying to style external links by adding a pseudo :after element right after the link itself, but I'm having trouble getting it to work on the same line. Here is the CSS code I have: a:not([href*="domain"])::after { content: url(data:image/svg+ ...

Tips for Keeping a Responsive Image at the Forefront of a Text-Image Layout as You Scroll

I'm currently in the process of creating a website where text appears on the left side with an accompanying image on the right. The challenge I'm encountering is ensuring that as users scroll, the image adjusts dynamically based on the associated ...

Button group malfunctions on smaller screens

After integrating a button group into my new website, I noticed that the first two buttons stop functioning properly on smaller screens. Surprisingly, if I remove the text-center div, all buttons cease to work entirely. Despite attempting various solution ...

I'm having issues with my navigation bar, and the border on the right side is not functioning correctly

I've been struggling to get the right border positioned between each section of my nav bar. I've tried wrapping each word in a separate span, but it doesn't seem to cooperate. The borders end up on the side and are too small to fill the enti ...

The d3.select function is failing to update the chart on the website

I am facing a challenge in updating data in a d3 chart with the click on an HTML object #id. After successfully coding it in jsfiddle, I encountered issues when implementing it on a web page. The scenario involves a simple leaflet map where the chart is d ...

Steps to Import an Image from a Subdirectory:

Currently, I am working on C# and HTML. While working on a view page, I encountered an issue when trying to load images from subfolders. When attempting to load an image from the immediate folder, it opens correctly. For example: <img data-u="image" s ...

Sending Data in Angular JS

Looking for guidance on Angular JS as a newcomer. I have set up a form on my index.html page, and when the user fills in the details and hits submit, I want it to redirect to a details.html page where all the filled-in information can be displayed. HTML ...

Using Html to differentiate input based on type

Looking for input on the code snippet below: <table class="details-table" *ngIf="animal && animaldata"> <tr *ngFor="let attribute of animaldata.Attributes"> <td class="details-property">{{ attribute.AttributeLabel }}& ...

Avoid activating the hover state

Is there a way to prevent a button, div, or li from hovering if it already has an active status using CSS? #list-of-tests .item-test:hover:not(.active) { background-color: #4d5f75; border: solid 1px #4d5f75; } #list-of-tests .item-test:active { ...

swapping between two lines within a div

i'm developing a new music app and I am in need of the following chord progression: Am F G Am Ab Gdim A# Hello these are just placeholder lyrics for demonstration purposes, hey hey hello which should look li ...