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

Is it possible for Response.Redirect and OnBeforeUnload to cooperate effectively?

Is there a way to detect if the server-side code has sent a Response.Redirect in an OnBeforeUnload event? I need to alert the user before they navigate away from a page, but I don't want the prompt to appear when the server redirects. I'm dealin ...

Adapting iFrame height to accommodate fluctuating content height in real time (details included)

I have an embedded iframe that contains a form with jQuery validation. When errors occur, the content height of the iframe increases dynamically. Below is the script I use to adjust the height of my iframe based on its content: function doIframe(){ o = d ...

Securing uploaded documents and limiting access to approved individuals

Currently, I am utilizing Multer for file uploads and I am contemplating the ideal approach to secure access to these files post-upload. In my system, there are two user roles: admin and regular user. Users can only upload photos while only admins have ac ...

Validating input using jQuery Validate and implementing cross-domain remote validation with JSONP

Having an issue with jQuery Validate and cross domain remote validation in a unique scenario: PhoneGap mobile app PHP scripts on remote server jQuery 1.9.1 jQuery Mobile 1.4.2 for interface framework Using jQuery Validate 1.12.0 for forms validation plug ...

conceal parent window element upon clicking an image within an iframe

I'm facing a challenge with hiding certain buttons in a parent window when opening a modal by clicking an image inside an iframe. Below is the code snippet that I am using: In the parent window - <iframe id="gallery" src="links/gallery.html" wid ...

Download files from Firebase storage to a user's device

I have a variety of files such as images, videos, and audio stored in my firebase storage. My goal is to provide users with the ability to download these files to their computers by clicking on a download button. After reviewing the firebase documentation ...

Issues with data within a Vue.js pagination component for Bootstrap tables

Currently, my table is failing to display the data retrieved from a rest api (itunes), and it also lacks pagination support. When checking the console, I'm encountering the following error: <table result="[object Object],[object Object],[object Ob ...

Show the Div container when one of the checkboxes is selected

Currently, I have implemented a show/hide functionality for a div element when a checkbox is clicked. The div appears and remains visible until all checkboxes are checked; however, if no checkbox is checked, the div disappears. The issue I am encountering ...

Unable to utilize library post npm import

Recently, I attempted to integrate the flexibility library into my Laravel project. Following the installation with npm i flexibility --save, I required it in my app.js file: require('flexibility/flexibility.js'); ... flexibility(document.docume ...

Is there a way to extract both a and b from the array?

I just started learning programming and I'm currently working on creating an API call to use in another function. However, I've hit a roadblock. I need to extract values for variables a and b separately from the response of this API call: import ...

Invoking Ajax Within Every Loop

I am creating dynamic HTML buttons where, upon pressing each button, I want to make an AJAX call to retrieve a value. However, I am encountering an issue where I get as many console outputs as the number of buttons pressed. Here is my PHP code: if(isset($ ...

JQuery Challenge: Solving Dynamic Modal Issues

I'm in the process of creating a webpage that features multiple divs, each with its own unique image and title. Within each div, there's a button that, when clicked, should grab the specific image and title and display them in a modal. However, I ...

When working with data in Angular, make sure to use any[] instead of any in app.component.html and app.component.ts to avoid causing overload errors

I'm new to working with Angular, specifically using Angular 15. I have a Rest API response that I need to parse and display in the UI using Angular. To achieve this, I employed the use of HttpClient for making GET requests and parsing the responses. ...

How to selectively display specific columns when outputting JSON to a dynamic HTML table?

I'm looking to output specific JSON data in an HTML table with JavaScript. The headers will remain the same, but the JSON content will vary. Currently, I have a working function that generates the entire table using JavaScript: <body> ...

Obtained a ZIP file via CodeSandbox that contains a Vue.JS webpage. However, the index.html file yielded an

I have created my first ever Vue.JS / Vue2Leaflet app. It runs perfectly fine on codesandbox.io. However, when I download the ZIP file and try to open the index.html file, it appears blank. Is there something specific that needs to be done to make it work, ...

`Get the height of a specific element within a FlatList using the index property in React Native`

I'm currently exploring a workaround for the initialScrollIndex issue in FlatList that is not functioning correctly. I attempted to use getItemLayout to address this, but encountered a new problem - my elements inside the FlatList have varying heights ...

Automatic suggestions for my personalized npm module (written in ES6/Babel) in Webstorm

When I utilize the material-ui package in Webstorm, I am able to experience helpful auto-completion using the ctrl+space shortcut: https://i.stack.imgur.com/Pivuw.png I speculated that this feature may be attributed to the inclusion of an index.es.js fil ...

Angular Universal causes SASS imports to malfunction

Check out this sample app that you can download to see the issue in action: https://github.com/chrillewoodz/ng-boilerplate/tree/universal I am currently working on implementing angular universal, but I'm encountering an error with a SCSS import in o ...

Turn off the chrome react DevTools when deploying to production to ensure the

I have successfully browserified my react app for production using gulp and envify to set up NODE_ENV. This has allowed me to remove react warnings, error reporting in the console, and even disable some features like the require of react-addons-perf. Afte ...

What could be causing the appearance of a mysterious grey box hovering in the upper left portion of my image and why is the code only adjusting the size of the grey box instead of the entire

I've been working on embedding some JavaScript into my Showit website to create a drag-and-drop feature that displays a collage/mood board effect. Everything is functioning correctly, but I'm running into issues with resizing the images. There&a ...