Ensuring flexibility in video display when resizing the browser

I am facing an issue with the main video on my website, where it shows a green background when resized. I suspect that the problem lies in the aspect ratio of the video. However, my main question is: Is it possible to make the height of the video responsive so that it fits the entire video container?

Here's a screenshot of how my video looks when resized:

https://i.sstatic.net/IjFSh.png

As you can see from the image, there are unwanted margins at the top and bottom when resizing the video. The background turns green because of the "bg-success" class in Bootstrap.

bg-success

I have also tried setting the video as a responsive item using the "embed-responsive-item" class, but it didn't work as expected. Instead, it caused the video to occupy more than just the browser height.

embed-responsive-item

Below is the code snippet along with a link to the corresponding CodePen:

HTML

<main class="d-flex w-100 h-100vh">
    <aside class="sidebar">
        <div class="col h-100vh d-flex flex-column justify-content-between">
            <div>
                <h1>Title</h1>
                <hr />
            </div>
            <footer>
                <p class="text-center">
                    <a href="index.html">Home</a>

                </p>
            </footer>
        </div>
    </aside>
    <section class="workspace bg-success flex-fill">
        <div class="video-container h-100vh d-flex flex-column">
                <video autoplay loop class="main-video" controls="controls">
                  <source id="source_video" src="" type="video/mp4">
                </video>

            <div class="video-showcase">
                <div class="row no-gutters">
                    <div class="col-sm-3">
                        <div class="embed-responsive embed-responsive-16by9">
                            <video autoplay loop class="embed-responsive-item" controls="controls" onclick="firstVideo()">
                              <source src="" type="video/mp4">
                            </video>
                        </div>
                    </div>
                    <div class="col-sm-3">
                        <div class="embed-responsive embed-responsive-16by9">
                            <video autoplay loop class="embed-responsive-item" controls="controls" onclick="secondVideo()">
                              <source src="" type="video/mp4">
                            </video>
                        </div>
                    </div>
                    <div class="col-sm-3">
                        <div class="embed-responsive embed-responsive-16by9">
                            <video autoplay loop class="embed-responsive-item" controls="controls" onclick="thirdVideo()">
                              <source src="" type="video/mp4">
                            </video>
                        </div>
                    </div>
                    <div class="col-sm-3">
                        <div align="center" class="embed-responsive embed-responsive-16by9">
                            <video autoplay loop class="embed-responsive-item" controls="controls" onclick="fourthVideo()">
                              <source src="" type="video/mp4">
                            </video>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</main>

CSS

.h-100vh {
    height: 100vh;
}

.main-video {
    width: 100%;
    flex: 1 0 0;

}

.sidebar {
    flex: 0 0 300px;


}

@media (max-width: 575px) {

    .sidebar{

        position: absolute;
        top: 0;
        left: 0;
        width: 90%;
        max-width: 300px;
        transform: translateX(-100%);
    }
    .main-video{

        flex: 0 0 56.25%;
    }
    }

Answer №1

I was able to resolve the issue by including the following code:

object-fit: fill;

This not only fixed the main video display but also addressed additional errors that surfaced after implementing the above code. Below is the updated code snippet:

HTML

<main class="d-flex w-100 h-100vh">
        <aside class="col-md-2 d-none d-md-block bg-light sidebar">
            <div class="col h-100vh d-flex flex-column justify-content-between">
                <div id="header-div">
                    <h1>Simple Text</h1>
                    <hr />
                    <p id="sidebar-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 velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br> <br>


                    </p>
                </div>
                <footer>
                    <p class="text-center">
                        <a href="index.html">Home</a>
                        <a id="lang_selected"><b>English</b></a>
                        <a href="es/irma.html">Español</a>
                    </p>
                </footer>
            </div>
        </aside>
        <section class="workspace bg-dark flex-fill">
            <div class="video-container h-100vh d-flex flex-column">
                <video autoplay loop class="main-video" controls="controls">
                    <source id="source_video" src="" type="video/mp4">
                </video>

                <div class="video-showcase">
                    <div class="row no-gutters">
                        <div class="col-sm-3">
                            <div class="embed-responsive embed-responsive-16by9">
                                <video autoplay loop class="embed-responsive-item" controls="controls" onclick="firstVideo()">
                                    <source src="" type="video/mp4">
                                </video>
                            </div>
                        </div>
                        <div class="col-sm-3">
                            <div class="embed-responsive embed-responsive-16by9">
                                <video autoplay loop class="embed-responsive-item" controls="controls" onclick="secondVideo()">
                                    <source src="" type="video/mp4">
                                </video>
                            </div>
                        </div>
                        <div class="col-sm-3">
                            <div class="embed-responsive embed-responsive-16by9">
                                <video autoplay loop class="embed-responsive-item" controls="controls" onclick="thirdVideo()">
                                    <source src="" type="video/mp4">
                                </video>
                            </div>
                        </div>
                        <div class="col-sm-3">
                            <div align="center" class="embed-responsive embed-responsive-16by9">
                                <video autoplay loop class="embed-responsive-item" controls="controls" onclick="fourthVideo()">
                                    <source src="" type="video/mp4">
                                </video>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </main>

CSS

html, body{

    overflow:hidden;
}
.h-100vh {
    height: 100vh;
}

.main-video {
    width: 100% !important;
    object-fit: fill;
    flex: 1 0 0;
}

.video-container {

    overflow:auto;
}

.sidebar {
    flex: 0 0 300px;
    overflow:auto;

}

#header-div{

    word-wrap:break-word;
}

@media (max-width: 575px) {

    .sidebar {
        position: absolute;
        top: 0;
        left: 0;
        width: 90%;
        max-width: 300px;
        transform: translateX(-100%);

    }

    .main-video {
        flex: 0 0 56.25%;
    }
}

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 struggles to process large response

I am currently developing an application that sends requests to a URL and parses the table found in the HTML response using jQuery. While this method works well for smaller amounts of HTML code, it runs into issues with larger datasets. The problem arises ...

The items are misaligned in a horizontal position

The 4 divs are styled with a width of 23% and displayed using inline-block. They have a fixed height of 220px and no margin applied. However, the issue arises as they are not aligning horizontally Despite attempting to adjust the height and width paramete ...

Adaptive icon menu with submenus

I'm looking to create an icon menu with a submenu that expands upon click using HTML and CSS. Here's the design I have in mind I want the submenu to appear on the next row of the responsive div, as shown in the image above. However, the issue I& ...

What causes the vertical width of the clickable area on a range input to be larger than anticipated?

The vertical width of the clickable area (track) on the range input appears larger than expected in my Chrome browser (version 102.0.5005.63). Interestingly, it displays correctly in the code snippet. Is this a bug specific to Chrome? <div id="di ...

The fixed navigation bar is causing the content to shift downward

I am currently working on designing a two-layered navbar structure. The top layer contains essential company information such as phone number, email address, social media links, and more. The second layer serves as the main navbar, designed to be sticky a ...

Using PHP to nest a table within HTML and populate it with numbers ranging from 1 to 100

I am struggling with a practice question that involves creating a table using PHP nested in HTML. I need some help fixing it and understanding where I went wrong. The task is simple: generate numbers from 1 to 100 in a table, with each row containing 10 n ...

Increase the width of paragraph by adding white-space padding

I am attempting to control the number of characters in a paragraph to a specific limit. If the text is shorter, I want to add whitespace padding, and if it exceeds the limit, I will truncate it with an ellipsis. All containers containing paragraphs should ...

What is the best way to incorporate custom buttons and Bootstrap buttons into various pages within a React application?

As I follow a tutorial, I aim to maintain their stylish approach for Buttons and Navbars while also incorporating Bootstrap for components like buttons. However, when I import Bootstrap Buttons, their styling seems to disappear. Is there a way to rectify t ...

In the realm of web development, the Phoenix library introduces the concept

Is there a way to combine a dynamic classname and a static one effectively? <div class=<%="#{getClass(app.status)} two" %> What happens is <div class="one" two> Instead of the desired output of <div class="one t ...

Navigation Icons Menu

I need to customize my navigation by adding a special area on the right side with just three icons: basket, search, and wishlist. Can anyone suggest the best approach to achieve this? I am currently using the Divi theme for my website. Furthermore, I atte ...

What is the best way to enhance the smoothness of transitioning to a different section on the same page in React by clicking an anchor tag (<a>

Background My current method involves an immediate jump to another section without any smooth transition. This is how I implement it: <a href="#go_middle">Go Middle</a> <div id="go_middle"&‌​gt;Hello There</div> ...

Pop-up website opening with fixed dimensions error

On my webpage, I have a terminal where you can type commands and receive output. For example, typing "/unsolvedproblems" displays a list of unsolved problems with a hyperlink. I've been trying to make the hyperlink open in a popup window with a fixed ...

What is the method to display a caret in regular HTML text with the use of JavaScript?

Currently, I am studying JavaScript and aiming to develop a typing game similar to typeracer.com. The goal of the game is to type accurately and quickly without errors. In this game, users input text into a box, and JavaScript then compares their inputs w ...

Show on smartphones, conceal on desktops - Activation/URL

I'm attempting to create a click-to-call link on my website using the following: <a class="mobile-only" href="tel:+534306464456"><p class="">Click Here to call us</p></a> I want this link to only show up on mobile devices, sp ...

Display "No results found" on the auto-complete search list when the specified element does not exist

If the element does not exist in the "ul list," I want my search code (autocomplete on an input field) to display a message like "no match found" as a div tag or some other form of notification. How can I achieve this? Do I need to implement a different ...

Ways to eliminate additional container padding within flexbox

I'm struggling with understanding flexbox and couldn't find any clear explanation on the W3 page about how to remove the extra spacing between containers. For example, in one of their demos, I'm unsure how to achieve a layout similar to lef ...

Conceal a div using jQuery when clicked

I am facing an issue with my script where I need to make a div close only after clicking on a link, instead of anywhere outside the div. http://jsfiddle.net/N4pbP/ $(function() { $('#hidden').hide().click(function(e) { e.stopPropagation() ...

Using the Table-multiple-sort feature in boostrap-table is not functioning properly when there are multiple tables present on a single page

I have implemented bootstrap-table along with the extension table-multiple-sort. The issue I am facing is when I include two tables on a single page (with the second table within a modal window), the multisort feature does not seem to work on the second ta ...

data-icon not displaying correctly in Firefox and Chrome browsers

Can anyone explain why this code works in Safari, but not in Firefox and Chrome? Here is the HTML: <input type="search" placeholder="Search" id="search" name="search" id="s" data-icon="s"> And here is the CSS: #search[data-icon]:before { font ...

What is preventing this hover from activating the text animation?

Looking to create a hover effect in an CMS platform that only allows internal CSS styling. Despite the absence of a head tag, this CMS recognizes style tags and automatically inserts them into the template. After attempting to export as HTML to troublesho ...