Video background in a DIV with an image stuck to the bottom is not functioning correctly as intended

Currently, I am working on a layout at the top of a page that includes a div with images and a video background. However, I'm encountering difficulties in getting it to work properly. Initially, everything seemed fine in my first version until issues arose when attempting to make it compatible with different browser window widths. The setup is as follows:

https://i.sstatic.net/iuD3A.jpg

Blue - DIV with video background, green - images, green with orange border - image intended to stick to the bottom of the video, half of its height extending beyond the video area, and gray - regular page content.

The two problems I've encountered are the inability to find a way for the image (with an orange border) to consistently stay at the bottom of the video while partially extending beyond the video's bounds. It needs to maintain this position regardless of screen width changes. Also, the background of the video-containing DIV does not stretch to match the browser width like the video itself. I want it to be constantly covered by the video, adjusting size accordingly.

If anyone has suggestions on how to rectify these issues to achieve the desired outcome, please share!

Here is the relevant code snippet (page width on js fiddle may need adjustment for issue observation):

https://jsfiddle.net/yLmryL48/3/

See below for the detailed CSS code utilized:

body {margin: 0px;}
#video_box {
 width:100%;
 position:relative; height:720px;
 background: url("http://i.imgur.com/X3mb6AD.jpg"); -webkit-background-size: cover; 
-moz-background-size: cover;  -o-background-size: cover;  background-size: cover;}
#video_overlays {position:absolute; text-align:center; width:100%;}
#vt_logo, #vt_url { display:block;}
... // Additional CSS code continues here

Answer №1

The dimensions of the video element are maintaining its aspect ratio, which is why it doesn't fill the entire div. If you want to stretch it, you can utilize CSS's object-fit. To crop an image and cut off 50% vertically, you can use translateY(50%)

CSS:

body {
  margin: 0px;
}
#ccontainer {
  position:relative;
  width:100%;
  height:550px;
  background: url("http://i.imgur.com/X3mb6AD.jpg");
  background-size: cover;
  -webkit-background-size: cover; 
  -moz-background-size: cover;
  -o-background-size: cover;
}
#cvideo, #videooverlays {
  position:absolute;
  top:0;
  left:0;
}
#cvideo, #videooverlays, video {
  width:100%;
  height:100%;
}
video {
  image-fit:fill;
  object-fit:fill;
}
#vid_top {
  position:relative;
  top:50px;
  width:100%;
  height: auto;
}
#vt_logo {float:left; margin-left:50px;}
#vt_url {float:right; margin-right:50px;}
#slogan {position:relative; top:70px; width:100%; height:auto; text-align:center;}
#slogan img {
  width:50%;
}
#slogan2 {position:relative; top:70px; width:100%; height:auto; text-align:center;}
#slogan2 img {
  width:50%;
}
#icons {position:absolute; bottom:0; width:100%; height:auto; text-align:center;}
#icons img {width:70%;transform:translateY(50%);}
#lipsum {width: 60%;  margin: 0 auto;}

HTML:

<div id="ccontainer">
<div id="cvideo">
  <video preload="preload" autoplay="autoplay" loop="loop" muted poster="http://i.imgur.com/X3mb6AD.jpg"> 
    <source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
    Your browser does not support HTML5 video.
  </video>
</div>
<div id="videooverlays">
  <div id="vid_top">
            <div id="vt_logo">
                <img src="http://i.imgur.com/Od0DZBj.png">
            </div>  
            <div id="vt_url">   
                <img src="http://i.imgur.com/ns80hYp.png">
            </div>
      <div style="clear:both;"></div>
      <div id="slogan">
        <img src="http://i.imgur.com/JrOXRf2.png">
      </div>
      <div id="slogan2">
        <img src="http://i.imgur.com/7mRLS9s.png">
      </div>
    </div>
        <div id="icons">
            <img src="http://i.imgur.com/XEEAcQx.png">
        </div>
    </div>
</div>
<div id="lipsum">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut eu tortor mi. Etiam bibendum pellentesque dignissim. Cras eu massa elit. Ut sit amet metus porta, hendrerit mauris at, elementum massa. Duis malesuada ac odio id faucibus. Mauris malesuada elementum dui luctus tempor. Integer in lacus vel risus dignissim vehicula eget vel purus. Sed non sollicitudin arcu. Cras ac ligula at nisl vulputate fringilla et non est. Etiam placerat volutpat eros id facilisis. Nunc sollicitudin ipsum ipsum, vestibulum rutrum sem dapibus quis.
</p>
... (additional lorem ipsum text)
</div>

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 updating a table row upon clicking the edit button in an Angular 12 template-driven form

Currently, I have set up a table where the data can be edited by clicking on a hyperlink and then saving the changes with a button. The issue I am facing is that when I click on the edit link, all rows become editable instead of just the specific row I cli ...

What is the best way to retrieve the global styles.scss file from the assets folder for privacy, legal, and conditions pages

I have a static page called terms.html located at: $PROJECT_ROOT/src/assets/html/terms.html In addition, my global styles (used by all components) are found at: $PROJECT_ROOT/src/styles.scss To include the static html file in a component, I use the fol ...

Utilize HTML code within a .php file without it being parsed

When I include HTML code in my PHP file, the HTML code doesn't get interpreted and just appears as text in the browser. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8> <title>Document</title> ...

Issue with image preview functionality in dialog modal when loading content via ajax request

<table id="result"> <a href='#' class='pop'><span class='fa fa-eye'><img src='image link here' style='display:none'></a> </table> The hyperlink above is designed to open ...

What could be the reason behind the jPlayer video not playing?

$("#jPlayer").jPlayer({ ready: function () { $(this).jPlayer("setMedia", { flv: 'http://st1.blive.kg/storage/flv7/2/249162.70951.flv' }); }, swfPath: "/js/Jpl ...

Building an HTML Form for Requests

Having some trouble creating an HTML form, particularly with resizing the Fieldset and legend elements. As a novice programmer, I am practicing building HTML forms. My goal is to have the form adjust its size based on the window without displacing the cont ...

Firefox causing line-height problem

Having an issue with styling a search button in Firefox. The input submit is created using an iconic font, white background, and border-radius as shown below: display: block; width: 60px; height: 60px; line-height: 60px !important; padding: 0; background: ...

When a user clicks on the product id field, I would like to add my data underneath the table and then conduct a search

When adding data to a table, I noticed that it is being added at the top instead of below the table, I implemented a search feature where the user can enter a product id, but I cannot seem to locate the error in my code, Is there a way to add a search fiel ...

Error encountered when submitting HTML form containing file input: ERR_CONNECTION_RESET

I'm encountering an issue while trying to upload an image using an HTML form. Once I submit the form, after approximately 3-5 seconds, I receive the following error on the browser: ERR_CONNECTION_RESET The problem seems to arise with images larger ...

Struggling to access the content enclosed within label tags within a jQuery AJAX function

Here is my jQuery/AJAX code: $("button#submit").click(function () { var form = $('#pick-status-form'); var selectedStatusID = form.find('input[name=statusesList]:checked').val(); $.ajax({ type: "GET", url ...

What is the best way to align this in the middle on iOS?

Screenshot Greetings, I am facing an issue with centering an element on Apple devices. In the screenshots provided, you can see how it appears on iOS, Android, and a Windows PC. Despite trying various methods, I have been unable to solve the problem. Can ...

When you add the measurements of two images to the top bar, you get the viewport size

Requirement 1: A top bar measuring 46px in height Reqirement 2: One photo positioned at the top and another at the bottom I have attempted the techniques mentioned on How to resize an image to fit in the browser window?. However, the images still appear ...

Ways to widen a selected drop-down menu outside the dialog box containing it

I'm working with a Html.DropDownList that has been styled using Chosen within a jQuery UI dialog. As the list of items is quite long, when it's opened, it gets cut off by the border of the dialog window. Is there a way to extend the dropdown por ...

Help needed with CSS menu dropdown problem

Hello everyone, I am currently working on creating a menu for the top navigation of my website. My goal is to have a list of items appear below the menu when hovering over it with the mouse. Right now, I am testing this on a local HTML file before impleme ...

Tips for capitalizing the first letter of a directory

I want to automatically convert all directories in the URI to lowercase if the user types them in uppercase. For example, https://example.com/hOmE should be converted to https://example.com/home. ...

Optimizing Textpaths Placement within SVG Elements

Check out this sample fiddle. (Make sure to view it in Firefox) Any suggestions on how I can adjust the positioning of my textpath within my SVG so that it isn't hidden? I attempted to include x and y attributes in both the svg and text tags, but the ...

Tips for adding a search button within the input field

My goal is to incorporate a circular search button at the end of an input field, but I'm struggling with the logic to achieve this. I am using Font Awesome to display the icons. .search-box { outline: none; padding: 7px; padding-left: 10px; ...

The Firefox parent was not appearing on the screen

I'm facing an issue with Firefox not displaying my website properly. It seems to be struggling with the styling of a parent div. Have a look at these images. Here is how it's supposed to appear: My website in Chrome/IE http://www.lackeycomputing ...

Arranging Divs with Right Float Alignment

I am running into issues trying to align and float certain divs properly. Currently, I have two divs with images that are displaying correctly, and now I need to add two more divs with images that behave in the same way. Even though I attempted to use th ...

Photo on vertical display

I have been working on displaying dynamic photos from a backend file and looping through them. I have successfully displayed the images vertically using CSS. vertical-align: middle; However, when I tried to add a photo name for each image, the positionin ...