The carousel is set to a height of 100%, with the carousel caption aligned to the middle

CHALLENGE

  1. Is there a way to make the carousel height 100% of the screen?
  2. How can I vertically center the carousel-caption?
  3. How can I align the carousel-caption and carousel-indicators at the same level?

I'm struggling with this issue, any help would be appreciated.

Here is the code snippet I've been working on:

html,
body{
  height: 100%;
}

.carousel-caption{
  top: 60%;
  transform: translateY(-50%);
}

.carousel-indicators li{
  height: 72px !important;
  border-radius: 0px !important;
  width: 192px !important;
  background: url(http://ebitfactory.se/wp-content/uploads/2016/11/photo-1465056836041-7f43ac27dcb5-1920x720.jpeg) !important;
}

.carousel-indicators li:hover{
  transform: scale(1.02);
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">

<main role="main">
  <div id="myCarousel" class="carousel slide" data-ride="carousel">
    <ol class="carousel-indicators">
      <li data-target="#myCarousel" data-slide-to="0" class="active"><img data-slide-to="0" data-target="#myCarousel" src="http://ebitfactory.se/wp-content/uploads/2016/11/photo-1465056836041-7f43ac27dcb5-1920x720.jpeg" alt="" width="192" height="72"></li>
      <li data-target="#myCarousel" data-slide-to="1"></li>
      <li data-target="#myCarousel" data-slide-to="2"></li>
    </ol>
    <div class="carousel-inner h-100">
      <div class="carousel-item active">
        <img src="https://i.imgur.com/wnZPRGU.jpg" alt="" width="100%">
        <div class="container align-middle">
          <div class="carousel-caption text-left">
            <h1>Example headline.</h1>
            <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
            <p><a class="btn btn-lg btn-primary" href="#" role="button">Sign up today</a></p>
          </div>
        </div>
      </div>
      <div class="carousel-item">
        <img src="https://i.imgur.com/wnZPRGU.jpg" alt="" width="100%">
        <div class="container">
          <div class="carousel-caption">
            <h1>Another example headline.</h1>
            <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
            <p><a class="btn btn-lg btn-primary" href="#" role="button">Learn more</a></p>
          </div>
        </div>
      </div>
      <div class="carousel-item">
        <img src="https://i.imgur.com/wnZPRGU.jpg" alt="" width="100%">
        <div class="container">
          <div class="carousel-caption text-right">
            <h1>One more for good measure.</h1>
            <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id bibh ultriplesythe vehicle across the age your lobortis.</p>
            <p><a class="btn btn-lg btn-primary" href="#" role="button">Browse gallery</a></p>
          </div>
        </div>
      </div>
    </div>
  </div>
</main>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>

Any assistance on this matter would be greatly appreciated!

Answer №1

If you want to create a responsive full-screen carousel, consider converting your inline images into background images. Below is a script I used that automatically transforms inline images into background images when the page loads.

Check out the Bootstrap 4 classes and custom CSS I implemented:

$('#demo').find('.carousel-item').each(function() {
  var imgContainer = $(this),
    bkImg = imgContainer.find('img').attr('src');
  imgContainer.css("background-image", 'url("' + bkImg + '")');
});
.carousel-item {
  height: 100vh;
  width: 100%;
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
  padding: 0 15%;
}

.carousel-item.active,
.carousel-item-left,
.carousel-item-right {
  display: flex !important;
  justify-content: center;
  align-items: center;
}

.carousel-item img {
  display: none;
}

.carousel-item h1 {
  color: #fff;
  font-size: 36px;
  padding: 0 10%;
}

.carousel-item p {
  color: #fff;
  margin: 10px 0;
}

.carousel-indicators {
  margin: 0 !important;
  bottom: 7vh !important;
}

.carousel-indicators li {
  height: 20px !important;
  width: 100px !important;
  border-radius: 0px !important;
  opacity: .8 !important;
  background: url("https://picsum.photos/100/40/?gravity=west") center center no-repeat !important;
}

@media screen and (min-width: 992px) {
  .carousel-indicators {
    bottom: auto !important;
    top: 67vh !important;
  }
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">

<div id="demo" class="carousel slide" data-ride="carousel" data-inerval=4000>

  <!-- Indicators -->
  <ul class="carousel-indicators">
    <li data-target="#demo" data-slide-to="0" class="active"></li>
    <li data-target="#demo" data-slide-to="1"></li>
    <li data-target="#demo" data-slide-to="2"></li>
  </ul>

  <!-- The slideshow -->
  <div class="carousel-inner">
    <div class="carousel-item active">
      <div class="slide-content mx-auto">
        <img src="https://i.imgur.com/wnZPRGU.jpg" alt="">
        <h1 class="display-1 text-center">Lorem ipsum dolor sit amet adipisicing</h1>
        <p class="text-center">Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id.</p>
        <div class="text-center">
          <a class="btn btn-md btn-primary" href="#" role="button">Browse gallery</a>
        </div>
      </div>
    </div>
    <div class="carousel-item">
      <div class="slide-content mx-auto">
        <img src="https://i.imgur.com/wnZPRGU.jpg" alt="">
        <h1 class="display-1 text-center">Lorem ipsum dolor sit amet adipisicing</h1>
        <p class="text-center">Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus.</p>
        <div class="text-center">
          <a class="btn btn-md btn-primary" href="#" role="button">Browse gallery</a>
        </div>
      </div>
    </div>
    <div class="carousel-item">
      <div class="slide-content mx-auto">
        <img src="https://i.imgur.com/wnZPRGU.jpg" alt="">
        <h1 class="display-1 text-center">Lorem ipsum dolor sit amet adipisicing</h1>
        <p class="text-center">Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
        <div class="text-center">
          <a class="btn btn-md btn-primary" href="#" role="button">Browse gallery</a>
        </div>
      </div>
    </div>
  </div>

  <!-- Left and right controls -->
  <a class="carousel-control-prev" href="#demo" data-slide="prev">
    <span class="carousel-control-prev-icon"></span>
  </a>
  <a class="carousel-control-next" href="#demo" data-slide="next">
    <span class="carousel-control-next-icon"></span>
  </a>
</div>


<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>

You have the flexibility to write additional CSS, including media queries, to customize the carousel for optimal display across various devices.

Answer №2

To achieve a full-screen carousel, simply set the height to 100vh and use images as background. If you don't follow this method, the images may end up being stretched. Here is how you can do it:

.carousel-item {
    height: 100vh;
    background-image: url(https://i.imgur.com/wnZPRGU.jpg);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

If you prefer to have captions always centered on the screen, you can override the CSS with the following code snippet:

.carousel-caption {
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    max-width: 80%;
}

Answer №3

Instead of using Boostrap carousel, consider utilizing 'owl-carousel' as a better solution for this particular issue. To further enhance your understanding of the concepts mentioned in questions 2 and 3, delve deeper into the topic of 'position' within css.

For additional insights on Question 1

Find more information regarding questions 2 and 3

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

Guide on transferring href parameter from the parent Vue component to the child component

Hey there! I've been working on creating a Vue page, breaking it down into components, and populating it with content from json. It all seems pretty straightforward, but I've hit a snag. Why is the href parameter not showing up in the right place ...

Arrange components with minimal spacing

I am currently working on a design that requires a perfectly aligned table using divs. Here is what I have done so far: My goal is to have the time section placed on the left side of the entire row, while keeping the text right-aligned to avoid creating a ...

What are some tips for using CSS display grid to effectively showcase my HTML content?

Visit my About Me page with custom menu styling Any tips on aligning the body with the grid function to achieve this particular design? ...

Drawing the canvas is taking place prior to the image being fully loaded in JavaScript

Currently, I am in the process of creating a collage using images that are all sized at 174x174 pixels. The images are stored on my server, and while my program can locate them successfully, it requires me to click the "save image" button twice for them to ...

Setting form input values to a new value in Angular 8

Is it possible to reset the value of a form input and then set another value from a service? I would like to store the old value in saveService, reset the service, and change the name attribute of the service to Hello World! Even though I correctly have t ...

Create your own unique Bootstrap 4 build with our custom generator and download it

Is there a tool similar to the alpha/beta bootstrap 3 custom generator for bootstrap 4? I'm looking for something like the one available at Customize and download. https://getbootstrap.com/docs/4.0/customize/ is not currently accessible. ...

What is the best way to showcase custom DataTable filters that are perfectly aligned with each other?

I'm struggling to figure out how to incorporate my own custom filters alongside the default DataTable filters. As far as I can tell, the DataTable's HTML is dynamically generated through JavaScript. I have a custom @Html.DropDownList that I want ...

Ensure that the input group is entirely visible and does not wrap within a table cell

I am facing an issue with an input group placed in a table cell where the button wraps below a certain size. I want to prevent this behavior specifically for this table cell and the rest of the column. The relevant html generated with added javascript elem ...

Steps for triggering an event based on a user-provided time input

I'm developing an AC controlling application that allows users to specify a time for all building AC units to be automatically turned off using HTML, jQuery, and CSS. I need to implement a feature where the system compares the user-entered time with t ...

Protruding button on the surface of the form

I'm struggling with a form layout issue. Here's what it looks like: https://i.sstatic.net/arfJQ.png Removing the mb-3 class doesn't solve the problem, it just removes the spaces between the inputs. How can I make sure the button remains in ...

Obtaining data attributes in Angular 8

I'm working with Angular 8 and I came across an issue. In my code snippet, there are two data attributes assigned to a button element, but only one attribute is showing up. Is this a syntax error or a bug? <button [attr.data-popolamento]="all" [a ...

Tips for incorporating a datepicker into your Angular 2 application

In my HTML file, I have defined the following code: <span id="datepicker" (click)="ShowDate()"> <i class="fa fa-calendar " aria-hidden="true" style="margin-top: 20px;margin-left: 20px;" >< ...

How can I make sure the footer stays at the bottom of the page on shorter pages in my

I am currently working on a website and trying to figure out how to make the footer stick to the bottom of the screen. I attempted a solution from ryanfait but it didn't work with my theme. Another method I tried using absolute positioning placed the ...

Ways to implement CSS styling to every input element excluding inputs located within list items of a specific class

input.not(li.tagit-new >input) { background-color: lightgrey; } <ul id="tagAdministrator" style="width: 505px" class="tagit ui-widget ui-widget-content ui-corner-all"> <li class="tagit-new" style="box-shadow: none;"> <input ty ...

In HTML5, I am trying to figure out the best way to connect my webpage sections to the corresponding navigation links with the help of IDs (such as linking navhome to

I am in the process of redesigning a website to optimize it for mobile devices. Although I have completely restructured the site, I am encountering an issue where the main pages are not displaying properly. The header, navigation menu, sidebars, and a plac ...

Obtaining a collection of distinct values from an observable stream or pipeline

I'm stuck on figuring out how to filter for distinct values while filtering within a .pipe() <mat-form-field class="filterField"> <input formControlName="filterParam2" matInput placeholder="Filter& ...

Getting the value from a dropdown menu and displaying it in a text area

I have 3 functions (radio, textarea, and dropdown) I was able to successfully retrieve the values of radio and textarea into the textarea. However, the drop down functionality is not working as expected. My goal is to display the selected option from the ...

Trouble with Summernote's formatting features

I encountered a similar issue on my desktop and created a fiddle to highlight the problem. When using the summernote editor, I found that I could adjust the font size and family successfully. However, I faced difficulties setting the font to bold, italic, ...

The clock in NextJS/React shifts its position whenever it rerenders

I'm currently working on a clock widget in NextJS using SVG for scalability on large screens. The issue I'm facing is that the numbers on the clock aren't always the same width, causing the widget to shift slightly left or right every second ...

Using Jquery: Removing the strikethrough effect upon the second click!

Currently in the process of learning Jquery and experimenting with using a button to apply a "text-decoration" to a list item upon clicking. However, I encountered an issue where I couldn't figure out how to use the same button to remove the "text-dec ...