Tips on sprucing up the edges of a Bootstrap grid design using row alignment

The layout of the page is built on a simple two-column Bootstrap structure:

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

Using Bootstrap, both columns are displayed in the center of the window with equal margins on the left and right.

:       | column 1    | column 2    |        :

The task is to enhance the margins (the areas between the vertical bar and colon) based on the content within the rows. These enhancements are non-essential elements that may be hidden on smaller screens as part of the responsive design process. This particular aspect has proven to be quite challenging for me.

Initially, adding more columns or nesting containers seemed like viable solutions. However, doing so caused Bootstrap to treat these "decorative" columns as essential content, taking up valuable space on limited screen sizes.

Is there a way to inform Bootstrap that a column is purely decorative and non-essential, to be shown only when space permits?

EDIT

In response to Ahmad Dalao's request for a screenshot, I've put together an example to clarify my question. Please note that I am seeking guidance because I'm unsure how to implement this concept effectively. The image below illustrates two nested containers: the parent container holds the decorative left and right margins, while the child container contains the main content columns.

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

<div class="container-fluid" style="background:white;margin:0;padding:0;">
  <div class="row"  style="margin:0;padding:0;">
    <div class="col-sm-2" style="text-align:right;border: 1px solid blue;margin:0;padding:0;">
       <img src="decoration-left-margin.png">
    </div>
    <div class="col-sm-8"   style="border: 1px solid blue;margin:0;padding:0;">
      <div class="container" style="border: 1px solid green;margin:0;padding:0;">
        <div class="row"  style="margin:0;padding:0;">
          <div class="col-sm-4" style="text-align:left;border: 1px solid orange;margin:0;padding:0;">
            <img src="decoration-left-content.png">
          </div>
          <div class="col-sm-8" style="text-align:right;border: 1px solid orange;margin:0;padding:0;">
            <img src="decoration-right-content.png">
          </div>
        </div>
      </div>
    </div>
    <div class="col-sm-2" style="text-align:left;border: 1px solid blue;margin:0;padding:0;">
       <img src="decoration-right-margin.png">
    </div>
  </div>
</div>

Answer №1

Your scenario includes utilizing .col-sm for the essential columns but neglects to specify the space allocation for the decorative columns.

If we assume that the decorative columns require the same amount of space as the essential columns, the following arrangement should achieve your desired outcome:

<div class="container">
    <div class="row">
        <div class="decorative col-sm d-sm-block d-none"></div>
        <div class="col-sm">
            column 1
        </div>
        <div class="col-sm">
            column 2
        </div>
        <div class="decorative col-sm d-sm-block d-none"></div>
    </div>
</div>

Until a small breakpoint and beyond, these two decorative columns will not occupy any space.

https://i.sstatic.net/74D0d.png

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

Demo: https://jsfiddle.net/davidliang2008/4j1u7q0f/16/

Answer №2

My approach to this was unique. Check out the code example at https://codepen.io/Mikeritteronline/pen/YzqLVmm

<div class="container-fluid">
  <div class="row">
    <div class="col align-self-center d-none d-md-block text-right p-0">
      <img src="//placehold.it/240x48" class="pull-right" alt="">
    </div>
    <div class="col">Lorem ipsum dolor sit amet consectetur adipisicing elit. Corporis sequi suscipit quas nisi quae impedit hic iure aperiam eligendi, nam, nesciunt quaerat dolor ipsam amet temporibus provident, eius architecto soluta?</div>
    <div class="col">
      <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Laborum cumque veritatis eaque eius sed libero deleniti et, dignissimos ipsum. Qui quis doloremque illum saepe aspernatur autem tempora cum, reprehenderit consequatur!</p>
      <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Nulla voluptates culpa voluptatem nobis sapiente ipsum corrupti delectus, consequatur quia temporibus dolore modi quasi libero dicta ratione nostrum soluta. Obcaecati, molestias.</p>
    </div>
    <div class="col align-self-center d-none d-md-block text-left p-0">
      <img src="//placehold.it/240x48" class="pull-left" alt="">
    </div>
  </div>
</div>

CSS is

.pull-right{
  margin-right: -2rem;
}
.pull-left{
  margin-left: -2rem;
}

I opted to hide the decorative columns up until the medium breakpoint. For more information on hiding elements in Bootstrap, visit https://getbootstrap.com/docs/4.5/utilities/display/#hiding-elements

To position the images using negative margins, as Bootstrap lacks built-in utilities for that purpose.

I utilized align-self-center to vertically center the decorator columns. To learn more about vertical alignment in Bootstrap's grid layout, check out https://getbootstrap.com/docs/4.5/layout/grid/#vertical-alignment

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

Using ReactJS and JavaScript to transform an array into a fresh array

I am working with an array that looks like this: var oldArray = [ {number: '12345', alphabet: 'abcde'}, {number: '54321', alphabet: 'abcde'}, {number: '67891', alphabet: 'abcde'}, ...

Apply a coating of white paint and add color to the border

I was struggling to create a form that has a white background color and a green border at the same time. I am using Bootstrap and it seems like I cannot apply both styles simultaneously. Here is the link to the form design I am trying to achieve: . Below ...

Setting the z-index to place an absolutely positioned element below a relatively positioned one

I am currently facing a challenge where I need to position an element under another one that has already been relatively positioned. The blue box must remain relatively positioned due to specific constraints within the website development process. For bet ...

`Can you teach me how to dynamically load HTML elements using input JSON data?`

What is the best way to iterate through an input array of objects? I currently have data for only 2 people included. However, there are more than 50 people's information in the input and I need to loop through all of them. Here is a sample code snip ...

How to Align col-md-5 in the Center Using Bootstrap?

Is anyone else struggling with this dilemma or is it just me? I've been searching everywhere for a solution to my problem but I can't seem to find one. According to the grid system, if you have a column size of col-md-5, centering it should be ...

Angular js is a powerful framework that allows for the seamless transition of views, except for the home

I am currently using the ng-animate module to implement sliding effects for my app views. Each route has its own unique slide animation. Take a look at my simple code below: HTML: <div ng-view ng-animate class="slide"></div> CSS: /*Animatio ...

Creating impenetrable div elements with JavaScript or jQuery

I'm currently working on creating solid blocks using DIVs positioned side by side both horizontally and vertically. I've successfully achieved this when the divs have equal heights. However, an issue arises when a div has larger dimensions; it en ...

Modify the color of the panel header when the button is clicked

I am trying to modify the background color of my panel header using a button that changes the color scheme of my site. The button currently functions on AFO. Below is the stylesheet for the button: .AFO { background-color: #fff;} .AFO h1 { color: #00159d; ...

Adjusting font size, contrast, brightness, and sound levels on a website with the help of jQuery

My client has a new requirement: adding functionality to increase font size, adjust contrast/brightness, and control sound on his website. When clicking on any of the control images, a slider should appear for the user to make adjustments accordingly. Ho ...

What is the process for immediately changing the background color of an input field as soon as text is entered?

I am encountering an issue with the code snippet provided below. My goal is to change the background color of an input field as soon as I start typing something into it. The scenario involves 4 input fields where if the submit button is clicked and any f ...

Discovering the absolute path to @font-face fonts using Firebug

Is it possible to retrieve the absolute URL of a web font specified within an @font-face rule using tools like Firebug? For example: When inspecting the main.css file for a website in Firebug, you may come across this code snippet: @font-face { font ...

"Why does the font on my website look different on my computer before I upload it to my web host? How can I fix

I am currently developing a website and have chosen the font "PT Sans Narrow" for it. Unfortunately, it seems that Chrome and many other browsers do not support this font by default. Is there a way to include the PT Sans Narrow font with the website when ...

Tips on utilizing imacros for extracting image URLs

I am currently experimenting with the use of imacross for web scraping, but I have encountered a roadblock when it comes to extracting image URLs from markdown code like the one provided below. <div class="dpimages-icons-box"> <a href="http: ...

Large padding in the main container of Bootstrap 4

Hey there, this is my third and hopefully final question. I'm having some trouble with my page layout that was supposed to look like this initially: [navbar] [1][2][3] I was aiming to achieve the following effect when res ...

"Design the website with a WYSIWYG editor while preventing users from disrupting the page's

I am considering using an HTML WYSIWYG editor like CKEditor, but I am concerned about the possibility of users submitting HTML code that could alter the layout of the page when rendered. Here is a comparison between two posts: <p><b>This is m ...

Managing the "Accept Cookies" notification using Selenium in JavaScript

As I use Selenium to log in and send messages on a specific website, I am faced with a cookie popup that appears each time. Unfortunately, clicking the accept button to proceed seems to be quite challenging for me. Here is an image of the cookie popup Th ...

What can be done to stop the Datepicker from exiting the Dialog box and causing it to malfunction?

While creating a form inside a dialog box, I encountered an issue with the date picker functionality. Whenever I try to select a date, it disappears and breaks, rendering the last days of the calendar inaccessible. You can view an example of this problem i ...

Updating div visibility based on form content in PHP

I am struggling to find a way to filter a page filled with divs based on form input to determine whether they should be displayed or not. The layout is akin to a collection of articles, where each div showcases an image and some text that links to the comp ...

Tips for capturing an iframe image underneath an HTML5 canvas

I'm attempting to display a webpage on my canvas so that I can make drawings or add notes to it. My goal is to capture a screenshot where the drawing is saved along with the webpage as the background. I tried embedding a URL in an iframe behind the c ...

Including a CSS link in a .css file is an essential step in styling

Can someone guide me on how to reference the Bootstrap link (https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css) in a .css file within an Angular project? ...