What is the best way to adjust the height of an image in a Bootstrap 4 column to ensure that it remains responsive without affecting the size of an embedded video in a neighboring column?

Looking for a layout with an image, embedded video, and text all in one row? The responsive website relies on Bootstrap but needs the items in this row to maintain their order without stacking when the page width is decreased.

The issue arises when an image is in the first column and the embedded video in the second column struggles to resize properly as the page width decreases. It seems like when the row height becomes less than the image height, black bars appear above and below the video, distorting its aspect ratio. This problem persists even though the image adapts its height responsively. Fixing the glitch with the embedded video in the second column when the page width is reduced (especially with an image in the first column) is my main concern.

Here's the code snippet:

<html lang="en">
<!-- More code here -->

The challenge seems to revolve around the image in the first column. When I replace the image with text, the embedded video resizes correctly at any window size.

While adding the "img-fluid" class to the image provides it with a responsive height, the video in the second column has issues resizing when the page width is adjusted. Despite trying various percentage-based height adjustments for both the image and its containing div/column, I haven't found a solution yet.

My goal is to set a percentage-based height for the image in the first column relative to its container. The image should have a responsive height, while the embedded video should scale proportionally without distortion or black bars at any page width.

Additionally, instead of an image, there's a possibility of using vertically rotated text in the first column. However, attempting to rotate text within a Bootstrap column has led to alignment complications.

Answer №1

One way to make the image responsive is by setting its height to 100% of the column's height.

Answer №2

After some experimentation, I discovered that utilizing Bootstrap's embed-responsive class for the initial column (which houses the image) and surrounding the image with a <div> element allows the embedded video in the subsequent column to function correctly.

Interestingly, this method did not work when an anchor was placed around the placeholder image as depicted in the code from my original question. As a result, I have included an updated version of the code below featuring a link to a local image file.

<html lang="en">
<head>
    <title></title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">  
    <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-3 embed-responsive border">
                <div class="embed-responsive-item justify-content-end d-flex ">
                    <img class="mt-auto" style="height: 100%;" src="img/local_image.jpg">
                </div>
            </div>
            <div class="col-6 border embed-responsive embed-responsive-16by9" id="vid">
                <iframe class="embed-responsive-item" src="https://www.youtube.com/embed/kyJUQuaECrg" allowfullscreen></iframe>
            </div>
            <div class="col-3 border d-flex">
                <span class="mt-auto">Some Text</span>
            </div>
        </div>
    </div>
</body>
</html>

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

Showing data from input fields that are generated dynamically - jQuery

Whenever the user clicks on the "ADD" button, a jQuery script creates 2 input fields inside a div. Each input field is assigned a unique ID for the username and address as shown below: <div class="input-group input-group-sm mb-3"> <div ...

"Interactive functionality: Toggling checkboxes with a DIV click

I am trying to set up a simple div container that displays contact information in a formatted list (<ul><li>). Clicking on the div currently takes you to the user's profile page, which is functioning correctly. However, I am facing an iss ...

Choose the checkbox if the tablerow includes specific text

I am working with a table that has two columns. The first column consists of checkboxes and the second column contains attribute names. My goal is to select the checkboxes next to a cell that includes specific text. Below is the structure of my table: &l ...

What is the reason for updating only the cell in the final row?

Having trouble updating individual cells in my form-table, as only the last row gets updated each time. Seeking assistance with resolving this issue and understanding how to update all rows separately. Any help would be greatly appreciated. Thank you, Shay ...

Adjusting the transparency of the background without impacting the text itself

I've been struggling to create a loading screen with no luck. The animation itself looks fine, but the background is causing issues. Every time I try to adjust the opacity, it affects the text as well. @import url('https://fonts.g ...

I am experiencing an issue with my css dropdown menu appearing incorrectly on both Internet Explorer and Firefox

Chrome and Safari are working perfectly fine, but I encountered an issue with IE and FF where the submenu menu appears on the left side of the main navigation. The website in question is cedumilam.php.cs.dixie.edu. Below is the CSS code I am using: # ...

Issue in Opera with the $(window).load(function(){}); script

In order to display the body's main div height correctly after all content (images) have loaded, I utilized a combination of jQuery and CSS. //The CSS used is as follows body {display: none;} /* Function to calculate div block height */ function re ...

Adjusting the height property to zero in the absence of an element

I'm currently working on creating a timeline for changeLogs and populating it with data from an AngularJS controller. The issue I'm facing is that the height of the timeline "Line" is set to 6px. This means that even when there is no data in the ...

How can I achieve a stylish scrolling header similar to a Google Blog for my website?

Google's blog features a unique header design - as you scroll down, the gray bar in the header moves up until it locks at the top of the screen. While CSS's position:fixed can achieve a similar effect, Google seems to have used a combination of p ...

Display HTML components depending on an object's property using AngularJS

Here is the code I have created to display a simple drop down list: var products = [ { "id": 1, "name": "Product 1", "price": 2200, "category": "c1" }, { "id": 2, "name": "Product 2", "p ...

Best Method for Utilizing Selenium Locator for a Navigation Menu

I have been dedicating a significant amount of time to self-learning Selenium. I chose the website "actiTime.com" to practice what I have learned, and as I began automating scripts, I encountered an issue that has baffled me for two days. Since you are exp ...

The run() function in AngularJS inside an IFrame does not execute again when the IFrame is reloaded

In my webpage, there is a "Start Portal" button and an iframe with the id: MyFrame. Both elements are on the same webpage. I use jQuery AJAX to fetch the URL of my AngularJS based portal and then set this URL as the src for the iframe. The code snippet be ...

How to center align a Bootstrap 4 Navbar using CSS

Having trouble center-aligning your Bootstrap 4 navbar in your Angular code base? You're not alone. I too wanted to reduce the gaps between menu items when transitioning from one to another. Below you'll find snippets of my HTML, TS, and CSS: M ...

What is the best way to obtain the id of an HTML element that is generated within jQuery code?

Typically, data is retrieved in HTML by storing the html in the html file. In my case, however, I create the html element inside jQuery. So, how do I call out the div id? How can I replace document.getElementByID ("edit").innerHTML=.... when the element i ...

Looking to display the ng-option in two lines within Angular 6?

How can I display data in a select dropdown with two lines for each option? I am currently using ng-select. <ng-select [(ngModel)]="selectedData" placeholder="Select Data"> <div *ngFor="let data of Data"> <ng-option [value]="da ...

Using media queries in CSS to create responsive designs

<link type="text/css" rel="stylesheet" media="only screen and (max-device-width: 480px)" href="/assets/css/phone.css" /> <link type="text/css" rel="stylesheet" media="only screen and (min-device-width: 768px)" href="/assets/css/tablet.css" /&g ...

I am currently working on creating a timer and I am looking to position these three buttons in a circular formation

I want to create a stopwatch with 3 responsive buttons arranged in a circular layout. I have successfully built a responsive circle and now need help adding the buttons inside the circle next to the timer. To view the code, click here: https://jsfiddle.ne ...

Looking for advice on using media queries to resize my background image - any tips?

I'm struggling to resize my background image using media queries. Can anyone offer suggestions or solutions? I've tried applying the media query for my background image like I do with other elements, and it's not working properly. The issue ...

How to align text to the right in an Android TextView using HTML

I need to display some HTML content in a TextView. I am aware that certain HTML tags are not compatible with Android, so I have turned to a third-party library to incorporate bulletpoints and numbered lists. However, I also require support for right alignm ...

Is there a way to automatically calculate the sum of two boxes and display the result in a separate

I am working with two boxes: one is called AuthorizedAmount and the other is called LessLaborToDate: <div class="col-md-6"> <div class="form-group"> <label>Authorized Amount</label> <div class="input-group"> & ...