Struggling to make the webpage appear full width when resizing

Whenever I resize the browser window, I notice that the header and navigation bar do not fill up the entire width of the browser. This can be seen when shrinking the browser size. Ideally, I would like both the header and navigation bar to stretch till the end of the browser window.

However, everything looks fine when the browser is stretched!

Below is the HTML code snippet:

<body>

<div id="header">
Some text
</div>

<ul id="nav">
<li><a href="index.html">Home</a></li>
<li><a href="work.html">Work</a></li>
<li><a href="about.html">About</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>

</body>

And this is the CSS code for styling:

/* CSS Document */
body {
background:red; 
}

#header{
    margin:0;
    background: white;
    height:90px;
    width:100%;
}


#nav {
    /* margin: 0px auto;*/
     padding-left: 100px;
     background: black;
     height:54px;
}

#nav li {
     float: left;
}

#nav li a {
     color: lime;
     font-size: 20px;
     font-weight: bold;
     line-height: 54px;
     margin-right: 94px;
     text-decoration: none;
}

Your feedback on what could be improved in my setup would be highly appreciated. Currently, I am also utilizing Eric Meyer's reset tool.

Answer №1

Give this a shot

#nav-bar{
    padding:20px;
    background-color: #f1f1f1;
    height:50px;
    min-width:800px;
    width:100%;
}

You can define the min-width:--; here.

Answer №2

Revamp your list styling using percentage units for spacing in your CSS code.

/* CSS Document */
body {
background:red; 
}

#header{
    margin:0;
    background: white;
    height:90px;
    width:100%;
}


#nav {
    /* margin: 0px auto;*/
     padding-left: 10%;
     background: black;
     height:54px;
}

#nav li {
     float: left;
    padding-right:9%;
}

#nav li a {
     color: lime;
     font-size: 20px;
     font-weight: bold;
     line-height: 54px;
     text-decoration: none;
    display:block
}

Check out the live demo here: http://jsfiddle.net/vYgs5/

Answer №3

One potential solution could be to ensure that your website is responsive. While the advice provided by @Naveen is valuable, it's important to also consider implementing responsive CSS styles for various devices. For example:

/* Styles for Smartphones (portrait and landscape) ----------- */
@media only screen 
and (min-device-width : 320px) 
and (max-device-width : 480px) {
/* Styles */
}

/* Styles for Smartphones (landscape) ----------- */
@media only screen 
and (min-width : 321px) {
/* Styles */
}

/* Styles for Smartphones (portrait) ----------- */
@media only screen 
and (max-width : 320px) {
/* Styles */
}

/* Styles for iPads (portrait and landscape) ----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) {
/* Styles */
}

/* Styles for iPads (landscape) ----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape) {
/* Styles */
}

/* Styles for Desktops and laptops ----------- */
@media only screen 
and (min-width : 1224px) {
/* Styles */
}

/* Styles for Large screens ----------- */
@media only screen 
and (min-width : 1824px) {
/* Styles */
}

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

Issues with slideToggle in IE8 caused by CSS in JQuery

I am facing an issue where my div elements are supposed to toggle visibility using jQuery's "slideToggle" function (I'm utilizing jquery-1.2.6.min.js). This functionality is working as expected! However, I am encountering a problem specifically w ...

"Utilizing Bootstrap 4: Understanding the Optimal Times to Implement the 'Row

After studying the fundamental guidelines for Bootstrap 4, a question has arisen in my mind: Under what circumstances should we utilize the .row class in our layout? I came across this example where the .row class was not used in the code. However, the ba ...

The CSS is acting unexpectedly by applying styles to elements that were not intended to be styled

I am trying to style 2 specific elements within a div that has the class promotion, setting their text color to white. .promotion h1, p { color: #FFF; } <section> <article class="promotion grid-col-span-3 text-center"> <h ...

I'm struggling to resolve this error. Can someone please help me figure it out?

` package Xcel; import java.io.FileInputStream; import java.io.IOException; import org.apache.poi.EncryptedDocumentException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.ss.usermodel.Workbook; import org.apac ...

Flashing background colors on a website

Can anyone explain why this code won't alternate the background color of my website between two different colors? <script type="text/javascript"> function blinkit() { intrvl = 0; for (nTimes = 0; nTimes < 3; nTimes++) { intrv ...

Adjusting the width of a product slider based on window size changes using CSS media queries

Currently, I have a functional product slider that I am attempting to adjust the width for smaller viewports, but it is proving to be a challenge. Upon loading the document, the code tallies the width of each product item and initiates slides when buttons ...

Send data to a webpage and instantly navigate to it

When using the JavaScript code below, I am able to successfully send data to a page named "book.php" via the POST method (as indicated by the alert), but when I try to display the received data on book.php, nothing shows up. <script type="text/javascri ...

Modify the color of every element by applying a CSS class

I attempted to change the color of all elements in a certain class, but encountered an error: Unable to convert undefined or null to object This is the code I used: <div class="kolorek" onclick="changeColor('34495e');" style="background-c ...

A step-by-step guide to creating a CSS menu using pure HTML markup

I have been working on the CSS for a menu using some HTML code, but I am stuck and uncertain about my next steps. Here is the CSS I have added so far: #menu-my-integra, ul.sub-menu { list-style: none; padding: 0; margin: 0; } #menu-my-integra li ...

Is it possible to remove filters from image links but still apply filters to links within the same div?

Is there a way to use hue-rotate to change the colors of my text links without affecting my image links? I have tried removing the effect from images only, but haven't been successful. Any suggestions on how to achieve this? I created a JavaScript but ...

What is the most effective way to alter the font within this Bootstrap template?

Check out the source code on Github. I've been attempting to modify the font-family for both h1 and body elements, but it's not working as expected. I must be overlooking something simple, but I can't seem to pinpoint the issue. It's d ...

"Enhance your Vue.js application with the powerful capabilities of vue3-easy

I am currently working on a Vue.js project utilizing the "vue3-easy-data-table" library and following the style recommendations outlined on this particular webpage: Despite attempting to apply the following CSS properties: --easy-table-body-even-row-font ...

Divs gracefully appear one after the other in a sequential manner

I am attempting to showcase a sequence of 4 divs in a row using the ease-in CSS transition feature. I came across this example that demonstrates what I am aiming for: http://jsfiddle.net/57uGQ/enter code here. However, despite my best efforts, I am unable ...

Email design tip: Ensure consistent line heights by adjusting code for Outlook.com to override any default settings. Use the following CSS code: ``

I've been trying to fix this problem for 22 hours now, but as a newcomer, I think it's time to hand it over to the pros. I've been attempting to get rid of the extra line height that Outlook.com adds to emails, but I haven't had any lu ...

What is the method to launch a new window containing multiple tabs using JavaScript?

Is there a way to open a link in a new window that opens multiple tabs simultaneously? I am currently able to open multiple tabs within the same window using the code snippet below: $('a.yourlink').click(function(e) { e.preventDefault(); ...

utilizing the 'v-for' directive for creating a stylish CSS grid

I am having trouble getting these images to display horizontally on the preview instead of vertically. I attempted using display grid in the CSS, but they still show up vertically. Can someone please help me figure out what I am missing? Essentially, when ...

Rendering a prototype and setting its display to none

I have created a slideshow with the following code: <div class="row-3"> <div class="slider-wrapper"> <div class="slider"> <ul class="items"> ...

The page only appears properly after clearing the cache

My floating list menu is behaving oddly in Firefox. It only displays correctly after clearing the cache, but as soon as I refresh the page, the menu breaks again. The links inside the list elements appear wider than the text, even though I haven't se ...

The Vue design is not being reflected as expected

Encountering a peculiar issue where the style in my Vue component is not being compiled and applied alongside the template and script. Here's the code snippet: To achieve an animated slide fade effect on hidden text upon clicking a button, I've ...

What is the reason behind the jQuery only functioning properly on Internet Explorer 8 on this particular page and no other browsers?

I recently created a webpage utilizing jQuery: The functionality on the page should change music images to represent different key signatures when switching from 'Higher Key' to 'Lower Key' in the combo box. While this works perfectly ...