What is the best way to make sure the background color of a container stretches across the full width of the screen?

I am currently learning HTML and CSS, and as a practice project, I am working on building a portfolio webpage. In the image provided, there are two containers, and I am facing an issue with the space on the sides when changing the background color. Despite trying different adjustments to padding and margin, I have been unsuccessful in solving the problem.

Does anyone have any suggestions on how to fix this issue?

https://i.stack.imgur.com/SfKOI.png

html,
body {
  font-family: ;
  margin: 0 auto;
  text-transform: lowercase;
}

.container {
  max-width: 940px;
  margin: 0 auto;
  padding: 0 !important;
}

.nav {
  float: right;
  display: inline;
  margin: 0 auto;
  list-style: none;
}

.nav li {
  list-style: none;
  display: inline;
  padding-top: 0;
  padding-left: 10px;
}

.nav>li>a {
  padding: 0px !important;
  color: black;
}

a:hover {
  background-color: yellow;
}

.header {
  width: 100%;
  display: inline-block;
  padding: 10px 0 0 0;
  margin: 0 auto;
}

.header h1 {
  font-size: 20px;
  margin: 0 auto;
  display: inline-block;
}

.header .nav {
  padding-left: 10px;
}

.supporting h1 {
  border-left: 1px solid black;
  padding: 10px;
  margin: 0 auto;
  display: inline-block;
  position: absolute;
  top: 25%;
}

.supporting .container {
  background-color: white;
  height: 500px;
  width: 100%;
}

.work .container {
  height: 500px;
  margin: 0 auto;
  background: rgba(225, 225, 225, .8)
}
<html>

<head>
  <link href="style.css" rel="stylesheet">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="js/main.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>

<body>

  <div class="container">
    <div class="header">
      <h1 class="logo">header</h1>
      <ul class="nav nav-pills">
        <li>
          <a href="#">Projects</a>
        </li>
        <li>
          <a href="#">Photography</a>
        </li>
        <li>
          <a href="#">blog</a>
        </li>
      </ul>
    </div>

    <div class="supporting">
      <div class="container">
        <h1>hi.</h1>
      </div>
    </div>

    <div class="work">
      <div class="container">
        <h1>work</h1>
      </div>
    </div>

Answer №1

When utilizing .container in Bootstrap, it comes with a predefined width. You have two options here, firstly, you can opt for using .container-fluid instead of .container to create a full-width container (just remove some padding).

Alternatively, you can enclose .container within .container-fluid

<div class = "container-fluid">

    <div class ="container">
        content is placed here
    </div>

</div>

Next, in your css, assign the background color to .container-fluid rather than .container

div.container-fluid{

    padding-left:0px;
    padding-right:0px;
    background-color:red;
}

Answer №2

If you want to learn more about managing full width containers in Bootstrap, I recommend checking out the documentation on container-fluid. It's a great resource to understand the bootstrap way of handling these types of containers.

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

I would like to retrieve an array of objects containing state and count information from this data in ReactJS

I have a dataset stored in an array of objects as follows [{name,state},{name,state},{name,state},{name,state},{name,state}]. I am interested in extracting the state data along with the number of people belonging to each state. To achieve this, I would l ...

I'm running into an InvalidSelectorError and I could use some assistance in properly defining

As I gaze upon a massive dom tree, my task using NodeJS/Selenium is to locate an element by the title attribute within an anchor tag and then click on the associated href. Despite being a newcomer to regex, I am encountering numerous errors already. Below ...

I require assistance in understanding how to successfully implement ParseINT with (row.find)

enter image description hereHow To Utilize ParseINT Using row.find(). I Attempted This Code But It Doesn't Work. This is My Code : function update_qty() { var row2 = $(this).parents('.item-row'); var price2 = row2.find(parseInt($ ...

AngularJS does not allow empty spaces in textarea inputs

I am working on a form that includes a textarea element for users to input descriptions, however it does not allow any empty spaces. Users can only input alphanumeric and numeric characters, but no spaces. <textarea class="form-control" rows="4" maxl ...

Issue: When calling setState(...), you must provide either an object containing the state variables to update or a function that will return an object with the updated

Encountering an error in the else section with this.state.incorrect + 1 and this.state.correct + 1 I've come across a similar issue that wasn't resolved by visiting this link: React Native: setState(...): takes an object of state variables to up ...

Acquire JSON data structures using Node.js

I've been struggling to find a solution using just keywords - endless scrolling, yet all I can find are tutorials on getting data from JSON structure, rather than getting data structure from JSON. If you're unsure what my end goal is, here are s ...

Problem Encountered with Navigation Bar following the Cloning and File Transfer in a React (Next) Project

I cloned the repository and transferred the files using these commands: 1. git clone https://github.com/adrianhajdin/portfolio.git 2. cd portfolio 3. mv * .. Upon executing npm run dev, everything appears fine, but upon clicking on the About button or ...

Refresh a section of the page including any necessary scripts

I am currently working on refreshing a specific section with the code snippet below... jQuery('#account_alert').replaceWith("<div id='account_alert'><div class='msg success'>" + data.message + "</div></di ...

Display a collection of objects using Jade / Pug syntax

Struggling to find resources on Pug / Jade templating, turning to this platform for help. I've been diving into documentation on iterations along with consulting this helpful link. Working with Node.js, Express, and pug for a school project - a mock ...

Tips for incorporating a return statement within a network request function that is already returning information pertaining to the request

Is there a way to retrieve the data extracted from within newReq.on('response', (response) => {? var request = require('request'); const cheerio = require('cheerio'); const { app, net, BrowserWindow } = require('elect ...

When attempting to run the npm install mathjs command, an error is displayed

Trying to install mathjs using npm but encountering an error: npm install mathjs The error message received is as follows: npm WARN tar TAR_ENTRY_ERROR UNKNOWN: unknown error, write npm WARN tar TAR_ENTRY_ERROR UNKNOWN: unknown error, write npm WARN tar T ...

Error in Chrome: Text container's height is not fully extended to 100%

I'm encountering an issue with achieving 100% height on a child container in Google Chrome, although it works perfectly fine on Firefox. Here is the URL: http://linco.com.py/beta/multiplaza/cartelera.php The styling for the main container is as fol ...

When the page is refreshed, the route fails to load the data

My Vue.JS website is quite simple, utilizing VueX and Vue-Router. I have defined two routes: '#/' and '#/account/' These routes are filled with components from .vue files, loaded dynamically upon page load using http-vue-loader (to avo ...

Creating a jQuery-powered dynamic select field in Rails 3

After implementing the dynamic select functionality from this example on GitHub (GitHub Link), I successfully integrated dynamic selection for car models in my form for adding a new car. The form now filters car models based on the selected car name, and i ...

Utilizing TypeORM to selectively choose data in OneToMany relationships

I am looking to create a TypeORM query that pulls data from the database. Specifically, I want to retrieve all clients who have made a purchase but have not initiated a return. Here is the structure of the database: Clients: Id (Int, primary column) Purc ...

Utilize Jquery to trigger Controller Action

My goal is to refresh a specific 'div' when a user adds an item to the shopping cart. I have some jQuery code that should execute on the click event. It should trigger a post action (which is functioning correctly) and then reload everything with ...

Struggling to make comparisons with numerical data from MongoDB in an ExpressJS route

I am currently developing a website using Node.js, EJS template, MongoDB, and Express. I am working on implementing search functionality on my page using forms, but I am encountering a small issue. The problem is related to a logical issue in the search f ...

Conceal or reveal form elements based on input selection

In my current HTML form generated by PHP, I have multiple instances of the following structure: function show(elem, show){ var elements = elem.parentNode.parentNode.parentNode.getElementsByClassName("hidden"); var i; for(i=0; i<eleme ...

Retrieve JSON from a JSP page and access the data using AJAX

Is there a way to automatically fill a form in a JSP page based on the field codigo_caso? When this field is blurred, I want to send a JSON-like String to another JSP that retrieves the necessary data to complete the form. I have tested the page and it su ...

Employ the parameter within the main object

I currently have this code snippet in my function: add(messenger) { switch (messenger) { case 'skype': this.messengers = _.assign(this.messengers, {skype: ''}) break case 'telegram': this.messenge ...