Is there a way for me to adjust column widths in bootstrap using only CSS, without being able to modify the HTML code?

<div class="col-12 col-md-7">column md-7</div>
<div class="col-12 col-md-1">spacer md-1</div>
<div class="col-12 col-md-4">column md-4</div>

Recently, I took on a volunteering opportunity to revamp a webpage for an upcoming conference focusing on accessibility. To my surprise, the organizers had utilized a "drag and drop" page builder that lacked the functionality to edit subpages easily. One of the crucial changes required was to adjust the width of certain columns on the page to enhance readability. Particularly, the speaker bios in the md-4 column appeared too narrow.

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

My task involved utilizing the "Add custom CSS functionality" to manipulate the column widths effectively. However, I encountered a challenge while attempting to increase the width of the third column exclusively using CSS.

.col-12.col-md-7 { max-width:30%; }
.col-12.col-md-4 { flex-grow:5 !important; }
.col-12.col-md-4 { max-width:70% !important; }

Although these CSS adjustments successfully expanded the third column on regular screens, the layout failed to adapt on mobile devices where the 30% width proved inadequate for the first column. This issue prompted me to seek advice on optimizing the column width adjustments across all screen sizes.

Answer №1

On a regular screen, the third column expands nicely, but on mobile, it falls apart because the 30% width is too small for the first column.

Could using media queries solve this issue? Bootstrap 4 utilizes various media queries including the ones in your CSS:

@media (min-width: 1200px) {
  .col-12.col-md-7 { max-width:30%; }
  .col-12.col-md-4 { flex-grow:5 !important; }
  .col-12.col-md-4 { max-width:70% !important; }
}

@media (min-width: 576px) {
  .col-12.col-md-7 { max-width: 60%; } /* perhaps 60% fits better */
  .col-12.col-md-4 { flex-grow:5 !important; } /* change other classes accordingly */
  .col-12.col-md-4 { max-width:70% !important; }
}

Answer №2

If inline css isn't your thing, you can create separate classes for each column. By doing this, you can easily target and modify individual columns with css. It may require a bit more effort, especially if you want to make changes for mobile view using @media queries. This method allows you to customize each column size according to your preferences.

Here is an example in HTML:

<div class="col-12 col-md-7 my-col1">column md-7</div>
<div class="col-12 col-md-1 my-col2">spacer md-1</div>
<div class="col-12 col-md-4 my-col3">column md-4</div>

CSS:

.my-col3 {
   // add your styles here
 }

If you prefer to handle column sizes using Bootstrap instead of css alone, delve deeper into the column properties. You can specify how much space each column should occupy in different screen sizes without the need for extra css styling. Utilize Bootstrap's responsive features to tailor the appearance for mobile and tablet devices as well. In essence, adjusting responsiveness based on column dimensions would be a more strategic approach.

Answer №3

To create a responsive layout, enclose everything in a container-fluid. Next, assign a unique class to each column and adjust the width using CSS. Utilize the @media query to customize the layout for different screen sizes.

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 closing the mobile navigation bar on your device after clicking

Currently developing a website and in need of assistance with the mobile device navbar functionality. Essentially, I am looking to close the navigation when a specific link, such as "Destaques", is clicked. All I require is to remove the class "opened" upo ...

What is the best way to include a subscript (small letter) beneath a word using html and css bootstrap 5?

Is it possible to add a small letter (sub) below a word in HTML and CSS? I have included a screenshot for reference. I want to display "Max 100, Min 1" just like shown in the image. Here is my code: <input type="text" class="textarea" ...

Getting rid of the excess white space below the footer caused by concealed elements

In my design, I have three columns. The rightmost column is filled with 'Divs' containing collapsed information that can be scrolled through using the mouse wheel. The overflow in the center is hidden. The width of all three columns is set to 760 ...

Creating a hanging indent for bullets in CSS by using em units

I am trying to create hanging indents for 'bullets' by indenting wrapped lines after the initial prefix (e.g. "1. " or "1a). " Take a look at this example of HTML: <html><body> <div style="text-indent: -3em; padding-left: 3em;"&g ...

Sending loop data as a parameter from JavaScript to AJAX through a Bootstrap modal

Below is my code that retrieves records from a loop using JavaScript. It seems to be working well, however, there is an issue with the looped buttons that are supposed to alert the users_id in a Bootstrap Modal popup. The problem I am facing is that when ...

Mastering Bootstrap: Achieving flawless column stacking in succession

I am currently integrating bootstrap into my existing HTML code, but I only require it in two specific sections to avoid rewriting the entire code. Everything looks fine on my 1080p screen as intended. However, when I resize the screen slightly The titl ...

Adjust the Bootstrap 4 grid to a col-6 by resizing it to col-sm-3 and include spacing between the

Hey there! So I'm currently working with BS4 Beta and trying to create a grid that is 4 columns wide on full screen, but resizes down to 2 columns on smaller screens. I've used <div class="row mb-3"> to add space between the images. However ...

arranging fashionable divs side by side

I am currently working on a website and I want to include four circles that stand next to each other with a margin of approximately 50px between them. I managed to position one circle correctly, but when I try to add more circles, they do not display prope ...

Using TestCafe selectors to target a classname that has multiple matching nodes

I need help finding a TestCafe selector that can target an element with the same class name that appears multiple times in my HTML code. Here's what I have tried so far: https://i.sstatic.net/ZS691.png Despite trying various selectors, I have been u ...

Creating nested tabs using vanilla JavaScript, no need for jQuery

I am currently working on implementing tabs using a JavaScript function. The issue I am facing is that when I try to have tabs within one of the tabs, everything disappears every time I click on one of the inner tabs. This happens because the JavaScript fu ...

What is the method for inserting or passing a city value as a result into the input field with the value attribute set

This code is functioning properly, but the city it generates needs to be registered in #city How can I pass the value #city into an input field? value="cityname" <input id="city" name="input" value="cityname" /> <script> $(document).read ...

Steps for altering the primary color in PrimeNG__Changing the primary color

What is the most effective way to modify the default primary color for primeNG (saga-blue theme)? Altering --primary-color does not have the desired effect, as elements in node_modules/..../theme.css are styled using the main color hex rather than '-- ...

Excessive CSS Padding on Tablets and Mobile Devices

I recently completed this website based on a PSD design, using basic CSS techniques. However, I am encountering an issue with unwanted padding on the sides of the site when viewed on mobile devices and tablets. I would like the left and right edges of the ...

Let's explore a way to make the button text wrap onto multiple lines for smaller screens when using Bootstrap 4.0

I am encountering an issue with the layout of my asp.net mvc core web application + bootstrap 4.0 FAQ section. The problem is that the question description overflows the screen on small screens, while the answer text aligns properly. I need a solution to m ...

Proper application of article, aside, and header elements

Can someone help me with my page template setup? I have a sidebar on the left and main content area on the right. I'm wondering if I am using the article, aside, and header tags correctly. Also, should I attach classes/ids to html5 elements or is that ...

What is the reason for not being able to utilize the same ID more than once?

This snippet of code may not be complete, but it effectively addresses the issue at hand. <body onload="init()"> <nav> <h1 style="font-family:Helvetica;"> <ul class="nav"> <li ><a href="#">Me ...

Background image for numerical input field

I am currently working on customizing a form that includes a Number field, image button, and an image. My goal is to change the background of the number field to be a similar image. Below is the HTML code I have been using: <form name="form1" id="form1 ...

Tips for choosing specific CSS selectors from a variety of different stylesheets

Currently, I am using two different stylesheets - Bootstrap 4.0 and Materialize 4.0. My challenge is selecting specific selectors from both stylesheets but overriding conflicting styles. For instance, I would like to apply the header navigation style fro ...

How can I modify the navbar-collapse in Bootstrap to alter the background color of the entire navbar when it is shown or open on a mobile screen?

Can anyone tell me how to change the background color of the navbar when the navbar-collapse is displayed? I want one background color when the navbar-collapse is shown and a different color when it's collapsed. Is there a way to achieve this using C ...

Utilizing Bootstrap, Jquery, and Node.js for web development

I am seeking clarification on the process for running these two commands: npm install jquery npm install boostrap After adding the dependencies to my package.json file, I then include them in my app.js file using the code: var $ = require('jquery&a ...