Tips for decreasing the size of an individual division within the grid system in Bootstrap

<div class="col-sm-2" style="text-align: right;" >
        mytext1
</div>
<div class="col-sm-2" style="text-align: right;" >
        mytext2
</div>
<div class="col-sm-2" style="text-align: right;" >
        mytext3
</div>

Is there a way to adjust the size of only the second div, without using col-sm-1 or col-sm-2? I need something in between those sizes, like maybe col-sm-1.5. Any suggestions on how to achieve this?

Answer №1

To customize the sizing for bootstrap sm-1 and sm-2 (which correspond to 8.33% and 16.66%), you can define a custom class like this:

.col-sm-1-5 {
  flex: 0 0 12.5%;
  max-width: 12.5%;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c8aaa7a7bcbbbcbaa9b888fce6fce6f9">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" />

<div class="col-sm-1" style="text-align: right;">
  col-sm-1
</div>
<div class="col-sm-1-5" style="text-align: right;">
  col-sm-1-5
</div>
<div class="col-sm-2" style="text-align: right;">
  col-sm-2
</div>

Answer №2

In order to dynamically calculate the width of a column based on the 12 columns in the grid, you can create a custom class.

By dividing 100% by 12, you get the width of one column, which can then be multiplied by 1.5 for customization.

To match Bootstrap's default padding of 15px on both left and right sides for their .col classes, I included padding: 0 15px in the custom class.

A media query is used to reset the column width to 100%, aligning with the behavior of Bootstrap's col-sm classes.

The specific screen widths for each breakpoint utilized by Bootstrap can be referenced in their documentation.

.row {
  width: 100%;
}

.column {
  border: 1px solid black;
  text-align: right;
}

.col-sm-1-half {
  width: calc((100% / 12) * 1.5);
  padding: 0 15px;
}

/* bootstrap sm breakpoint */
@media only screen and (max-width: 576px){
  .col-sm-1-half {
    width: 100%;
  }
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d8bab7b7acabacaab9a898ecf6ecf6e9">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>

<div class="row">
  <div class="column col-sm-2">
    1
  </div>
  <div class="column col-sm-1-half">
    2
  </div>
  <div class="column col-sm-2">
    3
  </div>
</div>

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

Even when the outcome is not what was anticipated, mocha chai still manages to ace the examination

When testing my REST API response with mocha, chai, and express, I set the expected status to 201 but unexpectedly got a passing test result it('janus post', () => { request('https://***') .post('/***') .attach(&a ...

I'm curious about the process behind this. Can I copy a Figma component from a website and transfer it into my

Check out this site for an example: Interested in how uikit.co/explore functions? By hovering over any file, a copy button will appear allowing you to easily paste it into your Figma artboard. Want to know how this works and how to implement it on your o ...

Activate the service function within the identical service

Currently, I am facing an issue while trying to call a function within the same AngularJS service. In my controller, I am able to successfully call the 'geocoding' function without any problems. However, within the 'geocoding' functio ...

Error message: Unchecked runtime error - Unable to retrieve data from the specified URL. The extension manifest must include permission to access this particular host. This issue is occurring in manifest

Can someone help me out? I keep on receiving the error messages Unchecked runtime.lastError: Cannot access contents of url. Extension manifest must request permission to access this host. and Unchecked runtime.lastError: Could not establish connection. Rec ...

Enhance JSON nesting with knockoutJS

I am currently working on updating a JSON object in memory using the knockout.js user interface. However, I have encountered an issue where changes made in the UI do not seem to reflect on the JSON data itself. To troubleshoot this problem, I have added bu ...

Updating HTML content based on an active user session using Node.js/Express - A Step-by-Step Guide

I'm struggling to find a way to remove the login/signup buttons once a user has successfully logged in. The issue lies within my header file that needs some modification. <section class="header"> <div class="wrapper"> <nav ...

The alignment of the textarea is off due to an issue with the md

I'm experiencing an issue with the alignment of options in my form. The md-maxlength attribute is causing one line to be higher than the rest, as shown in the image below. https://i.sstatic.net/3J3Ts.png My goal is to move that specific textarea one ...

What is the best way to display an HTML file in Express when utilizing React as the frontend?

As a newcomer to the world of web development, I'm facing a seemingly simple issue that is consuming much of my time. I have set up an express server to run React on the front end. To achieve this, I use webpack and bundle to parse my react app, and ...

Retrieving information from MongoDB queries using Node.js

I am facing an issue while trying to retrieve data from the find() method and use it outside the method. My goal is to incorporate this data into a JSON response. Unfortunately, my current code is not working as expected and the data is not accessible outs ...

Retrieving data from external JSON files

I implemented this JavaScript code to retrieve JSON data from an external server. The JSON data gets loaded from the server, but I'm unsure how to extract markers from the Google Map using this external JSON data. var map, infowindow; //// // Fet ...

Exploring jQuery Efficiency: Comparing CSS and Animation Techniques

I am trying to steer clear of using the animation property because it tends to be slower compared to CSS3 animations. My query is whether utilizing the css method is faster than the animation property, but still slower than a direct CSS3 animation with tr ...

Transform the text upon hovering over the image, with the text positioned separate from the image

I'm looking for a solution where hovering over images in a grid area will change the text on the left side of the screen to display a predefined description of that image. I've been working on this problem for hours and would appreciate any help. ...

Switch up the font style of the title element

Is it possible to modify the font-family of the title attribute in an input field using either JavaScript or jQuery? <input type="text" title="Enter Your Name" id="txtName" /> ...

Utilizing Three.js in your HTML code

Currently, I am using c9.io as my IDE to write and test code for a website. Despite my efforts to import the code outside of c9.io, it is still not functioning properly. (I am confident that the issue is not with the three.js script itself.) My HTML code c ...

Display the content within the preformatted tag

As a Python and Selenium novice, I am eager to extract the text within the pre tag of the provided snippet using Python Selenium. <body><pre style="word-wrap: break-word; white-space: pre-wrap;"> " Here is some sample text that I need to re ...

Issue with rendering Base64 image array strings in FlatList component in React Native

In my RN App, I am trying to display a FlatList with Image Items but it seems like I have missed something. I am retrieving blob data from my API, converting it to a String using Buffer, and then adding it to an Array. This Array is used to populate the F ...

populating all available space in layouts using bootstrap columns

I am attempting to create a grid layout using bootstrap, but I am facing an issue with positioning one of the columns. I have tried adjusting the placement of the divs and using offsets/pulls, but so far I have not been successful. To explain what I am a ...

Using Higher Order Components in React with TypeScript to pass a component as a prop

Exploring the steps outlined in this guide: https://reacttraining.com/react-router/web/example/auth-workflow. Attempting to replicate the code: const PrivateRoute = ({ component: Component, ...rest }) => ( <Route {...rest} render={props = ...

What is the proper way to utilize document.getElementById() within a standalone js file?

As I dive into learning web development for the first time, I've decided to keep my scripts organized in separate files. However, I'm facing a challenge when trying to access elements from these external files. Below is a snippet of the JavaScri ...

The result of filtering multiple data using checkboxes in Vuetify is not displaying as expected

I am currently working on developing a straightforward task scheduler that includes filtering options using checkboxes. Below is the snippet from my vue file: Within my templates section, <fieldset> <legend>TASK STATUS</legend> ...