Search code examples
htmlcsstwitter-bootstrapresponsive-designcarousel

Bootstrap 4 Carousel with solid color in background and Image on right and text on left


Pardon me if I am asking something silly, but I have a requirement to create a full page slider with solid color as background and some text on left side and an image on right. Something like Google's Gmail Page. Currently the result I want is

enter image description here

I have used Bootstrap 4's Carousel

enter image description here

I have modified it slightly and made its background grey as its in Google's image. Now I want the text to be left aligned and have a responsive auto resizeable image on the right (Or even if I can have an image adjusted on the top of the text only) which is also responsive when viewed on mobile. Something like

enter image description here.

I am using this fiddle and I have modified the code as

<div class="carousel-item" style="background-color: #eff0f1">
        <div class="carousel-caption d-none d-md-block">
          <h2 class="display-4">First Slide</h2>
          <p class="lead">This is a description for the first slide.</p>
        </div>
      </div>

<style>
    .carousel-item {
        background-color: #eeeeee; /*Solid grey background*/
        }
    .carousel-caption {
        color: black;
        }
</style>

Solution

  • Remove d-none class from carousel-caption and try this way :

    .carousel-item {
      height: 100vh;
      min-height: 350px;
      background: no-repeat center center scroll;
      -webkit-background-size: cover;
      -moz-background-size: cover;
      -o-background-size: cover;
      background-size: cover;
    }
    .text_part{
    	display: none;
    }
    @media (max-width: 575px){
    	.text_part{
    	display: block;
    }
    .left_part{
    	display: none;
    }
    }
      <section class="text_part">
        <div class="text">
         <h2 >your text</h2>
       </div>
     </section>
    
     <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
      <ol class="carousel-indicators">
        <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
        <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
        <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
      </ol>
      <div class="carousel-inner" role="listbox">
        <!-- Slide One - Set the background image for this slide in the line below -->
        <div class="carousel-item active" style="background-color: gray">
          <div class="carousel-caption  d-md-block">
            <div class="row">
              <div class="col-md-6 left_part">
                your text
              </div>
              <div class="col-md-6 col-sm-12">
               img
              </div>
            </div>
          </div>
        </div>
        <!-- Slide Two - Set the background image for this slide in the line below -->
        <div class="carousel-item" style="background-color: pink">
          <div class="carousel-caption  d-md-block">
            <div class="row">
              <div class="col-md-6 left_part">
                your text
              </div>
              <div class="col-md-6 col-sm-12">
               img
              </div>
            </div>
          </div>
        </div>
        <!-- Slide Three - Set the background image for this slide in the line below -->
        <div class="carousel-item" style="background-color: green">
         <div class="carousel-caption  d-md-block">
            <div class="row">
              <div class="col-md-6 left_part">
                your text
              </div>
              <div class="col-md-6 col-sm-12">
               img
              </div>
            </div>
          </div>
        </div>
      </div>
      <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
        <span class="carousel-control-prev-icon" aria-hidden="true"></span>
        <span class="sr-only">Previous</span>
      </a>
      <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
        <span class="carousel-control-next-icon" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
      </a>
    </div>