limit the width of a Bootstrap container to a maximum width

Is there a way to change the max-width of a bootstrap container without modifying the code?

I attempted to set the max-width of the container to 540px, but it keeps defaulting to 1140px;

Code:

<div class="container-sm">
  <div class="border border-primary">
    <p>This content should be limited to 540px in width</p>
  </div>
</div>

Result:

https://i.sstatic.net/czf7y.png

https://codepen.io/catalingavan/pen/NWGapKa

Answer №1

The size of the bootstrap containers, such as container-sm, container-md, container-lg, and container-xs, adjusts according to the device type and class applied.

For your specific situation with container-sm, I have implemented a custom override:

.container-sm {
    max-width: 540px;
}

You can view the updated code on my modified CodePen here: https://codepen.io/AbhijatSaxena/pen/GRpMWZr

(I also suggest setting max-width for other container types for consistency)

For more information, you can refer to the Bootstrap site at https://i.sstatic.net/7QYOM.png

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

Tips for creating CSS Grid elements that stay fixed to the viewport

I am attempting to achieve a 100vh viewport with multiple responsive overlays on top of it. I have managed to fix the header element on the viewport using position: sticky, but I am encountering issues with making the rest work in the same way. Additional ...

Adjusting the size of icons to fit within a container

I need a div that can display up to 7 icons, depending on certain selections. These icons are from ionicons library. Here is the current code snippet: <div class="item item-text-wrap" style="text-align:center;"> <button class="button" style=" ...

Customizing the color of the navbar dropdown click event in Bootstrap with a bootswatch theme

I am currently struggling to change the color of a navbar dropdown click color. I am working with a theme that alters Bootstrap colors, specifically the Journal theme. To better illustrate the problem, here is a video link: Below is my code: <nav cla ...

Problem with toggler button

I've hit a roadblock with my project, particularly in the navbar area. Being a complete beginner, I'd appreciate an explanation in simple terms. The specific issue I'm facing is that on mobile-sized screens, the Toggler button is present but ...

Tips for creating a radio button that appears consistent across Firefox, Chrome, and IE11

I am looking to create a set of Radio buttons that will display consistently across Chrome, Firefox, and IE 11. My current solution appears to work well in Firefox, but in Chrome, there is a blue box around the buttons, and in IE 11, it seems that the colo ...

What steps do I need to take in order to develop a custom interactive analyzer game using html/css

Hello there, I am on a mission to develop a mobile-friendly version of an analyzer game that I came across on this link - . The current version of the game is built using flash. My goal is to be able to easily customize the colors and images to fit differ ...

Mismatched heights of grid elements

Currently, I am utilizing Tailwind CSS V3 and struggling to set the consistent height of grid items. The only way I can achieve uniform height is by assigning them a height of h-96. However, when I attempt to use breakpoints such as lg:h-80 and md:h-96, th ...

Default display as collapsible. Prefer them to be concealed initially

Looking for help with creating collapsible buttons. Currently, they show and collapse onclick, but I want them to be hidden by default. This is part of a personal website project where I am teaching myself HTML. What do I need to change? I tried using butt ...

designing a dropdown menu in HTML

I'm attempting to customize the icon for an HTML select menu using fontawesome icon fonts. My current code looks like this: <select> <option value="1">1</option> <option value="2">2</option> <option value= ...

Picture hidden beyond the words

I am trying to achieve a layout where an image is displayed behind an H1 tag, with the width of the image matching the width of the text. Here is my code: <div style="display: inline;"> <img src="http://img585.imageshack.us/img585/3989/m744. ...

"I need help configuring a social media icon using Bootstrap 4 - can anyone assist with coding this

Just diving into the world of web development and running into an issue with adding a Facebook icon to my HTML code. Here's what I have so far: <div class="container-fluid padding"> <div class="row text-center padding"&g ...

How can ReactJS conceal text when it wraps to the next line?

I am currently developing a web application that is compatible with both small and large screens. I am facing an issue where when the browser window is resized to be smaller, a title such as "Stackoverflow helps a lot" ends up breaking into the next line. ...

In search of a solution to ensure equal width for all items in a 2x2 grid

I have a CSS grid with two rows and two columns (refer to the code snippet). Is there a way to make all the items in the grid maintain the same width without specifying it individually? Are there any css-grid properties that can ensure consistent widths ...

Exploring the Sidebar Navigation Features of Bootstrap 4

Looking to incorporate a vertical navigation menu on the left side of my webpage, extending the full height of the page. My attempt to achieve this using the Bootstrap grid system resulted in the navigation menu becoming too wide. This issue persisted eve ...

Tips for creating a submission alert using bootstrap and react.js?

As a newcomer to React.js, I am currently exploring how to implement certain functionality in a form. My goal is as follows: 1) I want to delete the records/inputs after the submit button is clicked. Currently, even after submitting the information and s ...

Utilizing @each in Sass to define browser prefixes as variables

We've got a lot of exciting animations on the horizon and I'm on the lookout for a more streamlined solution to cater to all browsers. Something with a hint of sassiness like this would be perfect: @each $browser in '-webkit-', ' ...

Issue with CSS: Parent container disregards child element's width limit

Trying to maintain a 1:1 aspect ratio for a div by using an image. The goal is for the div to fill the available height within a flex-container while the container's width adjusts to fit its content. The square-div displays with correct dimensions, b ...

Mastering the CSS Art of Working with Sprite Images and Their Positioning

I am currently working on an educational project as a front-end developer, where I aim to clone the Google homepage. To achieve this, I am utilizing Google's own sprite and here is the image of the sprite that I am using. https://i.stack.imgur.com/YT ...

The jQuery function triggers in the console upon first click but does not display in the browser. However, it shows up twice in the browser upon

I'm quite puzzled by this issue. In my javascript file, the jQuery functions (including the one located at the end of the page) seem to skip the first click event and respond twice on the second click. I am also utilizing Bootstrap in my project. App ...