How to display DIV to the left of another DIV using Bootstrap

IEnumerable
:

I want to create a page (HTML) in a checkerboard style, so the first row has the image to the left of the content and the second row has the image to the right of the content.

Semantically, I can change the structure of the HTML to achieve this but is there a way to do this purely with CSS + Bootstrap 4 so the HTML doe not need to change.

I originally had a class "left-img" and "right-img" to achieve this but with no success.

Currently I have this in my CSS, where every event element.

.checker:nth-child(even) .img-wrapper {
    float:right;
}
.checker:nth-child(odd) .img-wrapper {
    float:left;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>



<div class="row checker">
    <div class="col-lg-6">
        <div class="">
            <h2>The Title</h2>  
            <div class="">
                some text
            </div>
        </div>
    </div>
    <div class="col-lg-6 img-wrapper">
        <img src="https://via.placeholder.com/140x100" alt="">
    </div>
</div>
<div class="row checker">
    <div class="col-lg-6">
        <div class="">
            <h2>The Title</h2>  
            <div class="">
                some text
            </div>
        </div>
    </div>
    <div class="col-lg-6 img-wrapper">
        <img src="https://via.placeholder.com/140x100" alt="">
    </div>
</div>

Full example

My codepen https://codepen.io/s-mcdonald/pen/qBZvwyX?editors=1100

Mehedi Hasan Siam
:

you have to just add display: flow-root!important; in your .checker:nth-of-type(even)

.checker .img-wrapper img {
    width:100%;
    height:auto;
}

/* Set the default behaviour */
.checker .img-wrapper {
    padding: 0px!important
}
.checker .text-wrapper {
    padding: 0px!important
}

/* Help determin if we have the right widget */
.checker:nth-of-type(even) {
    background-color:#eeeeee;
    display: flow-root!important;
}


//margin 0 to row
.checker {
  margin-left: 0px!important;
  margin-right: 0px!important;
}
//padding 0 to col
.col-lg-6 {
  padding: 0px!important;
}
h2, .text {
  padding: 12px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  
  <div class="row checker">
        <div class="col-lg-6 text-wrapper">
            <h2>A Title</h2>
            <div class="">
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
              incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis 
              nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 
              consequat. Duis aute irure dolor in reprehenderit in voluptate.
            </div>
        </div>
        <div class="col-lg-6 img-wrapper">
          <img src="https://cdn.jpegmini.com/user/images/slider_puffin_jpegmini_mobile.jpg" alt="">
        </div>      
    </div>

  <div class="row checker">
        <div class="col-lg-6 text-wrapper">
            <h2>A Title</h2>
            <div class="">
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
              incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis 
              nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 
              consequat. Duis aute irure dolor in reprehenderit in voluptate.
            </div>
        </div>
        <div class="col-lg-6 img-wrapper">
          <img src="https://cdn.jpegmini.com/user/images/slider_puffin_jpegmini_mobile.jpg" alt="">
        </div>      
    </div>
  
  <div class="row checker">
        <div class="col-lg-6 text-wrapper">
            <h2>A Title</h2>
            <div class="text">
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
              incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis 
              nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 
              consequat. Duis aute irure dolor in reprehenderit in voluptate.
            </div>
        </div>
        <div class="col-lg-6 img-wrapper">
          <img src="https://cdn.jpegmini.com/user/images/slider_puffin_jpegmini_mobile.jpg" alt="">
        </div>      
    </div>
  
  <div class="row checker">
        <div class="col-lg-6 text-wrapper">
            <h2>A Title</h2>
            <div class="text">
              Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
              incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis 
              nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 
              consequat. Duis aute irure dolor in reprehenderit in voluptate.
            </div>
        </div>
        <div class="col-lg-6 img-wrapper">
          <img src="https://cdn.jpegmini.com/user/images/slider_puffin_jpegmini_mobile.jpg" alt="">
        </div>      
    </div>
  
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to align a div to the left and another div to the center?

From Dev

how to display navigationMenu div left side of the slider

From Dev

How to display image in div from right to left

From Dev

How to position a div left to another div and top fixed to body?

From Dev

How to center one div and have another div float left to it?

From Dev

how to make a div left position according to another div?

From Dev

Div overlapping another div -Bootstrap

From Dev

how to force a div to display next to another element

From Dev

how to display another html file in div

From Dev

How to get div to touch left,using flexbox?

From Dev

How to display a div next to another div with no width defined?

From Dev

How to display a div when hovering over another div

From Dev

How to display a div next to another div with no width defined?

From Dev

How do I display a div right next to another div?

From Dev

How to set min-height to div which is in another div in Bootstrap?

From Dev

How to avoid a div overlapping another fixed div in Bootstrap?

From Dev

Display form values in another div(display) using jquery on submit

From Dev

Div centering within another Div - left aligned?

From Dev

How to make a div flush with the left margin when inside a Bootstrap container

From Dev

How to make a div flush with the left margin when inside a Bootstrap container

From Dev

How can I display a div if a user is using a browser not supported by Twitter Bootstrap

From Dev

How can I display a div on hover of another element using only CSS

From Dev

In Bootstrap3, on button click make one div display and another div hide

From Dev

Using Bootstrap, how can I create multiple fullscreen div's to stack on one another

From Dev

Using Bootstrap, how can I create multiple fullscreen div's to stack on one another

From Dev

How to display a div on hover of button using css

From Dev

How to display Image in Div using Angular Js

From Dev

If a Select All option is Checked then display a div using bootstrap multiselect

From Dev

How to fit the text inputs in div using Bootstrap?

Related Related

  1. 1

    How to align a div to the left and another div to the center?

  2. 2

    how to display navigationMenu div left side of the slider

  3. 3

    How to display image in div from right to left

  4. 4

    How to position a div left to another div and top fixed to body?

  5. 5

    How to center one div and have another div float left to it?

  6. 6

    how to make a div left position according to another div?

  7. 7

    Div overlapping another div -Bootstrap

  8. 8

    how to force a div to display next to another element

  9. 9

    how to display another html file in div

  10. 10

    How to get div to touch left,using flexbox?

  11. 11

    How to display a div next to another div with no width defined?

  12. 12

    How to display a div when hovering over another div

  13. 13

    How to display a div next to another div with no width defined?

  14. 14

    How do I display a div right next to another div?

  15. 15

    How to set min-height to div which is in another div in Bootstrap?

  16. 16

    How to avoid a div overlapping another fixed div in Bootstrap?

  17. 17

    Display form values in another div(display) using jquery on submit

  18. 18

    Div centering within another Div - left aligned?

  19. 19

    How to make a div flush with the left margin when inside a Bootstrap container

  20. 20

    How to make a div flush with the left margin when inside a Bootstrap container

  21. 21

    How can I display a div if a user is using a browser not supported by Twitter Bootstrap

  22. 22

    How can I display a div on hover of another element using only CSS

  23. 23

    In Bootstrap3, on button click make one div display and another div hide

  24. 24

    Using Bootstrap, how can I create multiple fullscreen div's to stack on one another

  25. 25

    Using Bootstrap, how can I create multiple fullscreen div's to stack on one another

  26. 26

    How to display a div on hover of button using css

  27. 27

    How to display Image in Div using Angular Js

  28. 28

    If a Select All option is Checked then display a div using bootstrap multiselect

  29. 29

    How to fit the text inputs in div using Bootstrap?

HotTag

Archive