Setting a restricted maximum width for content layout in CSS/Bootstrap

One thing I've noticed is that many websites, including SO, do not expand to the full width of the screen. Instead, they often have a fixed-width content column or set a max-width property for it. The Merriam-Webster dictionary website is a prime example of the latter approach.

Can this type of layout be achieved using Bootstrap? I was able to restrict the width of the content column within a col-8-md div, but now there is a significant gap between the content and the right sidebar on larger displays.

Check out the live demo: https://codepen.io/anon/pen/dNprzm

HTML code snippet:

<div class="row">
<div class="col-md-8">
  <div class="content-block">
     CONTENT
  </div>
</div>
<div class="col-md-4 right-bar">
  RIGHT_BAR
</div>
</div>

CSS code snippet:

.content-block {
   height: 1000px;
   max-width: 1000px;
   background-color: lightgreen;
   margin-left: auto;
   margin-right: auto;
}

.right-bar {
   background-color: pink;
   width: 400px;
}

Answer №1

If I've interpreted your inquiry correctly, you simply wish to ensure that your content has a fixed width while eliminating the extra space on the right side when viewed on larger screens?

Delete the margin-right: auto; property. When the screen size exceeds 1000px, it attempts to "center" your .content-block

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

When using the "top" property in position-absolute, the child element may exceed the boundaries of the parent element

My child element is overflowing its parent when I apply "top: random pixel" to it. It seems to be using the top position relative to the body of the page. // HTML <div class="movie-list"> <div class = "inn ...

Enhance the input field with letter control

Here is a snippet of my HTML code for inputs: <form class="form" id="firstForm" novalidate="novalidate"> <div class="tab-content"> <div class="tab-pane active" id="vtab1"> <div class="form-group" ...

The removal of classList.remove() only eliminates the class itself, not its contents

My goal is to add one class and remove another class when the start quiz button is clicked. While the 'info_box' class is successfully added, the 'start_btn' class does not get removed; it just changes position (from flex to no flex). T ...

calculation of progress bar advancement

I want to make the progress bar in my game responsive to changes in the winning score. Currently, it moves from 0% to 100%, which is equivalent to 100 points - the default winning score. But I need the progress bar to adjust accordingly based on the user-i ...

Error in altering element width dimension

For my Bootstrap card project, I have some specific rules in mind: The card should have a minimum width of 250px (card #1 - looks good) If the first line exceeds 250px in length, the card should increase its width without wrapping the line (card #2 - widt ...

Adding an <a> tag to Flickity: Step by step guide

Is there a way to incorporate tags into a Flickity image slider without affecting its functionality? Here's the code snippet I have for the slider: <div class="carousel" data-flickity='{ "imagesLoaded": true, "percentPosition": false, "auto ...

Are there any other default light colors in CSS aside from "gray"?

Seeking recommendations for background color combinations. The more suggestions, the better! Thank you :) ...

apply white-space:nowrap to a single column in a datatable

I am facing a challenge with my bootstrap datatable where one row (Product) contains a large amount of data and currently expands downwards, taking up a lot of space. https://i.sstatic.net/BryzM.png My goal is to make the Product column expand to the rig ...

Utilizing Electron to save editable user data in a .txt file

I am making an electron app that converts data from .txt files to Javascript arrays. This data is stored inside a folder called faces in the main directory. I also have a button in my app which, when clicked opens file explorer at the faces folder so the u ...

Modify picture properties when listbox is altered using jQuery

I need to set up a unique album gallery display where different folders are selected based on the item chosen in a selectbox. Below is the HTML code: <select name="album" id="album" onChange="changeimage();"> <option value="0" selected disab ...

The Cordova advanced HTTP POST request functionality is not functioning as expected

I'm currently in the process of connecting my backend to a cordova application, and at this early stage of development, I'm attempting to test it in the browser. Unfortunately, I'm facing an issue with the post request not working, as well a ...

Ways to extract the directive's value specific to my scenario

I'm currently working on developing a directive for my Angular app, and I need to find a way to pass a value to my controller. Here's what I have so far: controllers.directive('checkBox', function() { return { restrict: &a ...

Trigger a function upon browsing an image in angular-bootstrap-lightbox

Currently, I am utilizing angular-bootstrap-lightbox and have the need to implement a callback function that triggers when the image is altered. In particular, for the mobile view, when a user swipes left or right, I aim to capture both the image ID and t ...

Enlargen div or unordered list according to content exceeding limits

What is the best way to ensure a div expands when it contains a lot of content? Code Example (HTML): <div class="content"> Content goes here <br /> Content goes here <br /> Content goes here <br /> Content goes her ...

Manipulating graphics with CSS - dynamically linking Divs

I'm attempting to create a unique design by connecting a series of dynamically generated content divs with CSS. The goal is to have a curved line every three divs, complete with an arrow image at the end and an additional line to separate the contents ...

Fixed position not being maintained after clicking the button

Looking for some help with a fixed header issue on my website. The header is supposed to stay at the top while scrolling, which works well. However, when I switch to responsive view, click the menu button, and then go back to desktop view, none of the po ...

Is dividing a container into equal sections possible with flexbox?

Is there a way to create an HTML/CSS structure that divides a fixed-size container into three sections horizontally? The first section should expand based on its content, while the remaining two sections should evenly split the leftover space, with scrollb ...

Arrange the Elements of Select Options

I am currently facing an issue with organizing the elements in my select list. I have two interconnected lists, one containing a list of "models" which I have successfully sorted using the following function: var sel = $('#model'); var opts_lis ...

Customize the height of the Angular Material autocomplete dropdown to meet your needs

Context I have been working on a customized autocomplete feature using Angular Material, and I need to adjust the height of the dropdown results box for better visibility. Exploration After conducting some research, I discovered that Angular Material cu ...

The issue of duplicate backgrounds appearing on the burger menu when adjusting the height

There seems to be an issue with my burgermenu; when I attempt to adjust the height, the background-color ends up duplicating. .bm-menu { background-color: rgba(255, 255, 255, 0.9); height: 60vh; position: fixed; transition: top 0.3s; to ...