Adjusting video size in carousel (Bootstrap 4.0)

My school project requires me to create a website with a video slider, and I decided to use Bootstrap 4.0 for this task. I have successfully implemented a template from Bootstrap, but I am facing an issue with the video not fitting properly within the slider. Currently, the video displays in full width but is cut off in terms of height. I want the video to fit perfectly within the slider, with only arrows on the sides for navigation. This is how it looks right now: The width is fine, but the height is not visible.

What I aim to achieve is this: I want the video to fill the entire slider both in width and height, adjusting as the window size changes.

Here is the CSS code I am currently using:

/* 
 * My Custom CSS
 */

@charset "UTF-8";

/* Body */
body {
  width: 50%;
  margin: auto;
}

.carousel-item {
  height: 65vh;
  min-height: 300px;
  background: no-repeat center center scroll;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

.carousel-item iframe {
  margin-top: 55px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.tales {}

.iframe {
  max-height: 40% !important;
}

Answer №1

To begin, the layout needs to be adjusted. Ensure that all content within the body is contained within a container, row, and col-12.

The carousel-related code should specifically be placed inside the col-12. This arrangement ensures that the carousel aligns with the width of the nav, with space on both sides.

The controllers have an absolute position. Two of their parent elements use relative positioning. If you require more insight into CSS positioning, refer to this informative post.

There are various methods for moving the controllers outside of the carousel design.

Method 1

  1. Place the controller code below the container.

<div class="container">
  <div class="row">
    <div class="col-12">

    </div>
  </div>
</div>

<a class="carousel-control-prev" href="#video-carousel-example2" role="button" data-slide="prev">
  <span class="carousel-control-prev-icon bg-danger" aria-hidden="true"></span>
  <span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#video-carousel-example2" role="button" data-slide="next">
  <span class="carousel-control-next-icon bg-danger" aria-hidden="true"></span>
  <span class="sr-only">Next</span>
</a>

  1. Enclose all the aforementioned code within another element having the position-relative class.

<div class="position-relative">
  <div class="container">
    <div class="row">
      <div class="col-12">




      </div>
    </div>
  </div>

  <a class="carousel-control-prev" href="#video-carousel-example2" role="button" data-slide="prev">
    <span class="carousel-control-prev-icon bg-danger" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="carousel-control-next" href="#video-carousel-example2" role="button" data-slide="next">
    <span class="carousel-control-next-icon bg-danger" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>

</div>

Refer to this pen for further clarification.

Method 2

You can modify the position property of the carousel and the col-12 by using the following code snippet. Both will now be relatively positioned.

.position-initial {
  position: initial !important;
}

<div class="postion-relative">
  <div class="container">
    <div class="row">
      <header class="col-12 position-initial">
        <!--Carousel Wrapper-->
        <div id="video-carousel-example2" class="carousel slide carousel-fade position-initial" data-ride="carousel">

        </div>
      </header>

    </div>
  </div>
</div>

Now, with the div containing the position-relative class occupying full width and the controllers being absolutely positioned, the controllers remain within the div's full width.

Visit this pen for additional insights.

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

the script is run only one time

I have developed a unique web component and incorporated it in two distinct sections like this. <div class="sub_container"> <label>Users in Debt</label> <input placeholder="Search by user name" class="input_style ...

Tips for fashionable dressing &

Can you provide some insights on how to format the &amp; symbol in this HTML snippet? <a>Ian</a> &amp; <a>Jim</a> ...

Height specification in Tailwind Grid

Hi there! I'm currently working on implementing a grid system in NextJS using Tailwind CSS. However, I've hit a roadblock when it comes to automatically sizing the grids to fit the parent element. Let me illustrate my issue with two images below ...

Troubleshooting Alignment Problems within Bootstrap Containers

As I embark on my journey of constructing my inaugural website using Bootstrap 4, a wave of questions has flooded my mind. These queries either remain unanswered or beckon for further clarification. Shall we dive into them? Is it considered standard pr ...

What causes jquery-ui resizable to set the width of the div with the "alsoResize" property?

I have created a series of divs structured like this: <div id="body_container"> <div id="top_body"> </div> <div id="bottom_body"> </div> </div> Additionally, I have implemented the following funct ...

Is it possible to operate a mobile site automatically alongside a desktop site?

I'm currently working on a website that looks fantastic on desktop, but doesn't quite function properly when viewed on mobile devices. I'm curious if there is a method or system I could implement to automatically load the mobile version of t ...

execute operations on a separate webpage

Currently, I am facing a challenge while developing an application that allows regular users to modify data that is typically only accessible through an admin panel. My application effectively filters out any sensitive information; however, once the data i ...

Two different background colors adorn the Table and Body, adding a touch of visual

Hi everyone, I have a basic question regarding the styling of a webpage. I want the body of the page to have one color while having the table in the center with a different color. I've tried specifying different colors for the body and table in CSS, b ...

Incorporate JSON and JavaScript into your website template

Currently, I am in the process of developing my online resume using a free template that I found and downloaded. The template incorporates bootstrap and showcases a progress bar indicating my skills. However, I want to take it a step further by dynamically ...

What could be causing a hydration error when utilizing a table in Next.js?

When attempting to use the tr tag in my code, I encountered an error message that reads: Unhandled Runtime Error Error: Hydration failed because the initial UI does not match what was rendered on the server. import React from 'react' import {useS ...

What is the best way to create space between three columns in Bootstrap?

Despite my efforts to find a solution on Stackoverflow, I have not been able to locate exactly what I need. I am trying to evenly space and center three columns across my page. However, when I assign col-md-4 to each column, they end up too close together ...

Bootstrap side navigation bars are an essential tool for creating

Is there a way to change the hamburger icon in Bootstrap's navbar-toggle to an X button? I want the side nav to slide to the left when clicked, and also collapse when clicking inside the red rectangle. Thank you. https://i.sstatic.net/nQMGs.png Code ...

The form transmits the URL parameter rather than executing an update

I'm having trouble with my code and can't seem to figure out why it's behaving this way. When I try to update a recordset, the page reloads upon hitting the submit button and multiple URL parameters appear in the address bar. There are two ...

The contents within the div element exceed the width of its parent element

Hey there, I'm currently working on a Rails application to showcase some links in a horizontal layout. The links are indeed displaying horizontally without wrapping, just as intended. However, I've noticed that the containing div is wider than th ...

Is the CSS scale activated by mouseover or click?

My CSS code successfully scales images, but the issue is that it affects every image on the page. I am looking for a solution to apply this CSS only when the user hovers over or clicks on an image. The challenge is that images are added by non-technical w ...

Error encountered: popper.js throwing an unexpected token export SyntaxError

Error in Angular: When using popper.js with bootstrap 4, I'm encountering a SyntaxError with Unexpected token export. The error is showing up in the browser console. I tried changing the reference location for popper.min.js but it didn't work. ...

Changing the order of rows and columns with CSS3 and DOM manipulation

I have implemented the following CSS code to alternate the background color of li elements. However, I am facing an issue where I need the CSS styling to remain consistent even if the rows have the .hidden class applied to them (with .hidden class having d ...

What could be causing my Ionic button to not initialize in the expected state while using ngIf with a boolean property connected to an Ionic checkbox?

I'm currently in the process of setting up a list of ingredients with checkboxes and conditional buttons, but I'm facing some challenges with the default state. Ideally, I only want the button to be visible when the checkbox is unchecked so that ...

The navigation bar is not showing up at the top of my webpage as expected, instead, it is displaying

1 I attempted to build a model Google site to enhance my HTML and CSS skills, but I encountered an unusual issue where my navigation menu is showing up inside my image div, even though it was created before that. I have given backgrounds to the navs and i ...

Change the type of button in the Jquery UI dialog form to be submit

I'm struggling with my Ui dialog form using jquery. The Submit and Cancel buttons are currently set to type="button", but I want to change the type of the submit button to "submit". Does anyone know how I can achieve this? I've tried multiple ti ...