Expansive Background with Immovable Content Width (CSS)

Once again, I'm faced with a new day and a new question. My current dilemma involves setting different full-width background colors for each section while keeping the content fixed. I've hit a roadblock in figuring this out - whenever I set a width, my background adjusts but the content stays fixed. On the other hand, if I don't specify a width, the background looks great but the content doesn't fit properly. Any assistance would be greatly appreciated.

P.S. Today marks my first full month working with HTML and CSS, so I welcome any feedback or critiques on my code. I'm eager to improve, so all help is valuable to me.

body,html{
margin: 0;
padding: 0;
background-color: yellow;
height: 100%;
}
img{
max-width: 100%;
}
/*******
Nav Bar
*******/ 

header{
background-image:url(https://sunsetstation.sclv.com/~/media/Images/Page-Background-Images/Sunset/SS_Dining_VivaSalsa2.jpg?h=630&la=en&w=1080);
margin: 0;
height:100%;
margin-bottom: 85px;
background-size: cover;
background-repeat: no-repeat;
} 
.header-title{
float:left;
text-decoration: none;
color: green;
font-size: 60px;
font-family: 'Monoton', cursive;
font-weight: bolder;
} 
  
#nav-bar{
float: right;
margin: 0;
} 
#nav-bar li{
text-decoration: none;
float: left;
list-style-type: none;
} 
.nav-link{
float: left;
text-decoration: none;
text-transform: uppercase;
padding: 25px 0;
width: 140px;
transition: .25s color linear,.5s background-color linear;
text-align: center;
color: green;
font-weight: bolder;
} 

/*******
About
*******/ 

#wrapper{
width: 1200px;
margin: 25px auto;
} 
.our-story figure{
float: left;
width: 50%;
margin-top: 8px;
} 
.our-story h1{
margin:18px auto;
font-family: 'Pacifico', cursive;
font-size: 4em;
color: green;
} 
.our-story p{
line-height: 2.5em;
margin: 0;
font-family: 'Open Sans', sans-serif;
font-size: 20px;
font-weight: bolder;
}

/*************
Our Specials
*************/ 

#wrapper-two{
background-color: #b2ff00;
} 
#wrapper-two h1{
text-align: center;
font-size: 4em;
font-family: 'Pacifico', cursive;
}

/*************
pseudo classes
**************/ 

.header-title:hover,
.header-title:focus{
transform: rotate(360deg);
transition: 1s all linear;
} 
.nav-link:hover,
.nav-link:active,
.nav-link:focus{
background-color: lightgreen;
color: white;
} 
.our-story figure:hover{
transform: scale(1.15);
}

/**********
Clearfix
**********/ 

.clearfix:after,
.clearfix:before {
content:" ";
display:table;
clear:both;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="tiempo-de-taco.css">
<title>Tiempo De Taco</title>
</head>
<body>
 <header class="clearfix">
<nav>
 <h1><a href="#" class="header-title">Tiempo De Taco</a></h1>
 <ul id="nav-bar">
 <li><a href="#" class="nav-link">Home&... (truncated)

Answer №1

To achieve the desired result, it is recommended to utilize padding in conjunction with box-sizing: border-box if you wish to constrain the size of the inner container within the parent element.

Additionally, include text-align: center in both #wrapper and #wrapper-two and eliminate float: left; from .specials

For a visual reference, please refer to the following code snippet:

Hope this guidance proves useful!

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

Content move to the left with Material UI's shifting capabilities

Is anyone experiencing an issue with Material UI dropdown Select and Modals causing the content to shift to the left? I attempted using position: absolute on both the Select element and MenuItems, but unfortunately the content still shifted. Has anyone e ...

Find the height of the viewport using jQuery, subtracting (n) pixels

Apologies if the topic seems puzzling, I couldn't find a better way to explain it. I utilized jQuery to adjust the height of a div to match the size of the viewport. var slidevh = function() { var bheight = $(window).height(); $(".container" ...

How can a Vue.js toggle button dynamically change based on the combined state of two checkboxes?

My current project involves implementing a toggle feature that allows users to enable a day and then select between AM or PM using checkboxes. One issue I'm facing is how to de-toggle the button if a user unchecks both AM and PM options. Check out t ...

Swapping out a character on a webpage using jQuery

Can someone help me remove the colon from this code snippet on my webpage? <h1><b>Headline:</b> something</h1> I'm looking for a simple solution using jQuery, as I am a beginner in JavaScript. Please include the complete code ...

Is it normal not to see </head> and <body> tags in the page source code?

Looking at the source code of the page, you'll find something like this: <link rel="stylesheet" href="http://..."> <!-- analytics --> <script> ... Make sure the closing </head> tag and the opening <body> tag are positio ...

Steps for positioning an image to overlap the background image

Do I need JavaScript or is HTML and CSS sufficient? If so, should I utilize position or other properties for that? If my description is unclear, a visual demonstration in the form of an image might help. ...

The alignment in Firefox and Google Chrome does not appear to be consistent

The appearance of the content is correct in Google Chrome but incorrect in Firefox. Does anyone have any suggestions on how to fix this for Firefox? ...

Is it possible to create a column break within a CSS multicolumn design?

My text content sprawls over a CSS multicolumn layout with two, three, or four columns, utilizing CSS hyphenation. Sometimes, I want to terminate the text in one column early to allow the next paragraph to begin at the top of the next column. Is there a s ...

What is the best way to preserve the updated sequence of a list that can be re-ordered?

I've been tasked with making a re-orderable list for my apprenticeship project. After incorporating drag and drop functionality using Jquery UI, I managed to display the index of each item. However, saving the new order back to the database has prov ...

Populating a bootstrap grid with dynamic video content to enhance the visual appeal

I am currently working on a website grid that showcases new announcements and blog posts. In the design, I have a large column (col-sm-8 taking up 2/3 of the page) where I would like to include an introductory video to showcase our work. Despite trying va ...

Tips for creating animated navigation buttons that guide users to specific sections within interior pages

Recently, a client approached me with an interesting challenge: They want a homepage design that features the navigation loading in a specific location. However, once a user clicks on one of the nav buttons, they would like the entire navigation to anima ...

Is it possible to remove content from a Content Editable container?

JSFiddle <div contenteditable="true"> <p>Trying out editing capabilities of this paragraph.</p> <figure> <img src="http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/ima ...

Ways to dynamically activate an anchor tag's click event using JavaScript?

I'm having trouble triggering an already written click event for an anchor tag using JavaScript. Can someone help me figure out how to do this? I have the following anchor tag: <a id="memberid">Data Member</a> <script> $("#memb ...

Resizable icon next to inline element caused width adjustment

I have a group of individuals listed, each with two elements side by side: a "contact me" button (an 'a' element with a fontawesome icon) and a tag displaying the user type (span element). Some users do not have a tag, and when there is one prese ...

Unable to align divs horizontally

On my webpage, I have set up two divs - Box1 and Box2. Within Box2, there are two nested divs called Box2-1 and Box2-2. However, when I view the page, Box1 and Box2 do not align side-by-side as expected. Instead, Box1 moves downwards and lines up with the ...

What are the steps to gather user data and generate a roster of individuals currently online?

I am currently working on a way to gather information about the users who are currently logged into my website. Here's how it works: When a user enters my website, they have the option to choose a nickname using an input box. Then, there are five diff ...

Expansive Offspring Division stretching to the Entire Vertical Length of its Guardian Division

I'm attempting to achieve full coverage of the parent div section by my child div section. Take a look at the Example URL (specifically where the Canadian Flag Stand Up Paddle Boarders are located) towards the bottom: Essentially, when I set the widt ...

What is the reason for it being shown vertically?

The content is showing up differently for me than it should. I've attempted to use line breaks (br tags) and compare the code, but it looks identical to the tutorial I am following. I'm puzzled as to why it's displaying differently when we a ...

How to Fix a Non-Functional Navbar Toggler in Bootstrap 4

I'm currently practicing my skills in Bootstrap 4 by rebuilding my website with it. However, I've run into an issue with the responsive navigation bar's toggler not working properly. Can anyone provide guidance on how to fix this? Thank you! ...

Gradient Border on CSS Button

I'm trying to create a button with a silver-ish border and gradient like the one in the picture. I've managed everything except for the border, which is giving me some trouble. Here's the current CSS code I'm using for the button. http ...