How to Float Columns to the Right in Bootstrap 3

Before delving deeper into the issue, I'd like to outline some basic requirements for how I envision this being accomplished, if possible.

a) Due to modifying the Woocommerce template which utilizes Bootstrap 3, I am unable to simply switch to Bootstrap 4 even though it would greatly benefit me.

b) I am open to using any technique or custom code as long as it functions properly, even if it falls outside of the Bootstrap 3 framework's scope.

Here is the fiddle link: https://jsfiddle.net/wL1kjc0y/

I want to make the product list more dynamic by floating the product name, text, and button to the right side for odd items, while keeping the image on the left. Similarly, for even items, I want to float the image to the right and the text contents to the left.

I have used a div with 'col-lg-6' for text contents and another 'col-lg-6' for the image. However, applying the '.pull-right' class to the div wrapping Product contents does not work as intended. Since Bootstrap 3 doesn't utilize flexbox, I added the following code:

.d-flex {
    display: flex !important;
}

To ensure proper vertical centering for text. Unfortunately, 'float: right;' does not work on flex elements. Hence, I'm unsure if my desired outcome is achievable. Deleting the '.d-flex' class definition allows me to use the '.pull-right' class, but then vertical text centering is lost.

You can view an example where the '.d-flex' class is removed and the '.pull-right' class is applied to the first item here: https://jsfiddle.net/7guxfa5o/1/

Ultimately, it seems I have two incomplete options: Have columns floated to the right but lose vertical centering, or maintain vertical centering without being able to float the columns.

The JavaScript portion can be disregarded, as it primarily detects Medium-sized browser window dimensions and applies formatting and styling rules accordingly.

I would greatly appreciate any alternative solutions or suggestions for other approaches to try.

Answer №1

According to my interpretation, you are seeking to rearrange your items in a different order on larger screens. Have you considered arranging them alternately directly in the HTML code? Please view the demo and inform me if that aligns with your requirements.

<div class="container-fluid">
  <div class="row" style="background-color: #DDC1C1">
    <div class="col-lg-12 product_cat_col">
      <div class="col-lg-6 pull-right" style="margin: auto;">
        <p><label class="label label-danger">SOLD OUT</label></p>
        <h3 class="title40 lora-font font-bold black">
          Asun Inhalator "Energy + B12" </h3>
        <img class="product_cat_img hidden" src="https://asun.lt/wp-content/uploads/asun-inhaliatorius-energy-b12.png">
        <div class="title18 black product_cat_text">
          <div class="woocommerce-product-details__short-description">

            <strong>Asun Inhalator "Energy + B12"</strong> Exquisite Asun inhaler containing two active ingredients for maximum effectiveness. The invigorating watermelon-flavored "Energy + B12" inhaler dispels bad mood and boosts energy reserves. A deficiency of vitamin
            B12 can manifest in various negative symptoms, including chronic fatigue, mood disorders, or even depression. Taurine plays a crucial role in vitamin B12 synthesis. Inhalation ensures rapid and quality absorption of substances avoiding contact with the digestive tract. Active ingredients entering the body do not burden internal organs and lungs, instead going straight into the bloodstream.

          </div>
          <div class="woosb-wrap woosb-bundled">
            <div class="woosb-before-text woosb-text"></div>
          </div>
          &nbsp;
        </div>
        <a class="shop-button bg-white" href="https://asun.lt/inhaliatoriai/asun-inhaliatorius-energy-b12/">Learn more</a>
      </div>
      <div class="col-lg-6 col-md-12" style="margin: auto;">
        <img class="product_cat_img_second" src="https://asun.lt/wp-content/uploads/asun-inhaliatorius-energy-b12.png">
      </div>
    </div>
  </div>
  <div class="row" style="background-color: #d6d7d8">
    <div class="col-lg-12 product_cat_col d-flex">
      ...
      (The rest of the content has been truncated for brevity.)

</div>

Solution 2) By utilizing CSS, it is feasible to define two classes for moving elements left and right specifically for lg screens.

@media screen and (min-width: 992px) {
 .shift-right{
   right:-50%;
  }
 .shift-left{
  left:-50%;
  }
}

For a functional demonstration, refer to this fiddle using CSS

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

JQUERY function fails to execute following the invocation of an array

There is an array named NAME being created. Weirdly, the code seems to be functioning fine for alert('test1') but encounters an issue when reaching alert('test2') $(document).on('submit','form',function() { ...

Click event from Angular Material menu is triggered twice on mobile devices

After implementing a basic angular material side menu from the demo, I noticed that all click events are being fired twice on the entire page when viewed in mobile browsers. This issue can even be replicated in the Chrome emulator. (To reproduce, enable th ...

Utilizing OrientDB in a SailsJS Application: A Step-by-Step Guide

I'm diving into the world of NodeJS and SailsJS after working with Rails and PHP. I'm interested in integrating SailsJS with OrientDB, but I'm unsure of the best approach to take. I've come across two options so far, but the available ...

Python on the server side generating a downloadable zip file

After passing a parameter from my client to a python script on the server through a GET request, the script initiates a process that results in the creation of a zip file. However, upon making an AJAX call in my client-side JavaScript, I am only able to co ...

What methods does Angular use to display custom HTML tags in IE9/10 without causing any issues for the browser?

Exploring web components and utilizing customElements.define tends to cause issues in IE9/10. I've noticed that Angular is compatible with IE9/10, and upon inspecting the DOM tree, it seems like Angular successfully displays the custom element tags. ...

When a variable has been declared but not yet assigned a value, what is the default state of its value?

Recently, I challenged myself with a simple coding exercise to reverse a string: function FirstReverse(str) { var newStr; for (var i = str.length - 1; i >= 0; i--) { console.log(str.charAt(i)); var newStr = newStr + str.charAt(i); } ret ...

EBUSY: Unable to access resource due to being busy or locked, unable to retrieve information from 'C:hiberfil.sys'

I am running into an issue while attempting to publish an npm package. The error message I keep receiving is causing me some trouble. Does anyone have any suggestions on how I can resolve this? Your help would be greatly appreciated! Thank you in advance ...

What is the best way to contain content within a container while still extending its background to full width in CSS?

I'm currently working on a design that resembles: https://i.sstatic.net/hc5kv.jpg In this design, the red lines represent the sides of the container. I have enclosed the content section within a container div as follows: .container { width: 1200px; ...

Maintain consistent distance between checkboxes and their corresponding labels

I have a set of 10 checkboxes that look like this: [] Arts [] Dance [] Karate [] Volleyball [] Basketball Currently, I am using the following CSS styles: #tagstype_tags .tag_select { padding-left: 240px !important; width: 500px !impor ...

parallax scrolling can be a bit bumpy

While working on a website, I've incorporated a slight parallax effect that is functioning almost perfectly. However, I've noticed that the foreground divs tend to jump a little when scrolling down the page. At the top of the page, there is a di ...

What is the best way to position the bottom block?

I'm trying to create a template that looks like the image below: https://i.sstatic.net/m6q0s.png I managed to position the top square correctly, but I'm having trouble aligning the bottom one - I can't seem to move it to the bottom left co ...

Issue with React: Table sorting not updating with useEffect or event handling?

I have been working on a table (check it out here); The main task of this table is to display rows of data received from props through its child component. I am facing a problem: The useEffect function is not triggering the desired function when there is ...

Generating an interactive button click feature within a cell of a data table

Can someone help me figure out why I am getting a SyntaxError when trying to trigger a function in a datatable cell using an onclick event on a button? The button is successfully created, but the error occurs when clicking it. The problem seems to lie wit ...

Enable the event listener for the newly created element

I am attempting to attach an event listener to this HTML element that is being created with an API call handleProducts() function handleProducts() { var display = document.getElementById("display") var url = "http://127.0.0.1:800 ...

Guide: Creating a dynamic dropdown where the first selection must be made from the options in the second dropdown

My goal is to create a dynamic dropdown menu using data from MySQL tables. I want the user to select an option from the first dropdown before being able to choose from the second dropdown. I am attempting to pass the selected option value from the first dr ...

Tips for making slanted lines using CSS

Can this image be created using CSS and/or Bootstrap 4? https://i.sstatic.net/ajzk6.png ...

What is the trick to have a CSS element overflow the boundaries of its containing div entirely?

Currently, I have a JS Fiddle project where I am attempting to achieve a specific effect. In the project, there is a circle positioned at the center of a div. When the script runs, the circle expands evenly in all directions until it reaches the borders on ...

Retrieve all scope variables included in the query parameters

Looking to extract variables from the URL and assign them to scope variables. The URL format might be altered, but for example: http://example.com?opt.val=true&eg=foobar The controller code in consideration is as follows: m.controller('maps&apo ...

Is the uib-tooltip custom trigger malfunctioning?

One of the challenges I am currently facing involves implementing a tooltip on an input field. Here is my current implementation: <input id="test" uib-tooltip="my tootip" tooltip-trigger="customEvent" ng-model="test" /> I have been attempting to di ...

Create a division element with an image that can be dragged around

I'm having trouble making a div element draggable. Inside the div, there is an img and some text that acts as a label for the image. The issue is that when I begin dragging by clicking on the img, it's the img that gets dragged instead of the par ...