How To Change Background Image Height And Width In Css
If you want to engage first-time visitors on your website, yous take about x to 20 seconds. To inject some life into your folio content, you might want to endeavor adding a background video with CSS. Video backgrounds have up the unabridged width and height of the viewport (in other words, the visible page area) and add some visual flair to boost engagement. Over this video, you tin can place your featured page content — after all, it is simply a background, and your content is most important. Video backgrounds may seem like a fancy characteristic, but they're really easy to implement if yous know some CSS. In this guide, we'll show you how to add together a simple fullscreen video groundwork to your webpage, which you can tweak and suit to your needs. To show you how to create video backgrounds for your site, we'll share some code that you can re-create to alter for your needs. We'll as well come across the code in action with some responsive video background CodePen modules. Let's start with our HTML. First, we'll place a video on our page with the <video> tag and several attributes. All of these attributes are of import for the background to work as intended, so let's go through each one: <video> tags commonly include the controls attribute as well. Yet, we've left it out because nosotros don't want users pausing the video or skipping around. After our video chemical element, permit's add some HTML filler content to encounter how text appears confronting our video background. With the HTML washed, permit's handle the CSS business. To plough our normal video into a background video, add the post-obit CSS: Let's get through each of these rules to sympathise what they do: Next, nosotros'll add some styling for our other page content. For accessibility, brand certain text placed over video provides ample color dissimilarity with the groundwork: h1 { h2 { font-size: 3rem; } At this point, the video background will display nicely. But, nosotros haven't deemed for mobile devices still. It's ordinarily a skilful thought to prevent motorcar-playing videos on mobile, since the information needed to play them is significant and users didn't request to play the video in the first place. Instead, we'll add a media query that substitutes the video with our poster epitome on screens 750 pixels wide or smaller. When we combine everything, we get a sleek video background that scales with the screen and displays an epitome on mobile devices. (Note: Click hither to see the example with the video playing.) See the Pen Video Background 1 by Christina Perricone (@hubspot) on CodePen. If yous need more aid learning how to make this lawmaking work for your site, check out this CSS groundwork YouTube video tutorial: We've already put some headings on the folio to see how content looks against a video background. Still, your folio will probably contain more content than a video background and some championship text. So, let'southward add a <master> section to our case that appears when the user scrolls down. This element will comprehend the video to bring the focus to your main content. (Notation: Click here to run into the example with the video playing.) Encounter the Pen Video Background 2 by Christina Perricone (@hubspot) on CodePen. We've given our <main> element a background colour to cover up the video, as well as a top margin in viewport height units. This mode, the main content volition announced as soon as the user starts scrolling. Life is short, and nobody wants to waste matter their fourth dimension on a run-of-the-mill webpage. With only a few lines of CSS, we've created a full-folio video background template that you can customize for your audience. Using a site's background for a video might non exist the ideal choice for every website, and are ordinarily a no-keep mobile websites due to their impact on mobile performance. However, if washed well, video backgrounds can make quite an touch, and there's no demand to even button play. Editor'south notation: This mail service was originally published in June 2021 and has been updated for comprehensiveness. How to Create a Fullscreen Video Groundwork With CSS
<video id="background-video" autoplay loop muted poster="https://assets.codepen.io/6093409/river.jpg">
<source src="https://avails.codepen.io/6093409/river.mp4" blazon="video/mp4">
</video>
<h1>THIS IS A RIVER.</h1>
<h2>How purple.</h2>
#background-video {
width: 100vw;
height: 100vh;
object-fit: cover;
position: fixed;
left: 0;
right: 0;
acme: 0;
bottom: 0;
z-index: -1;
}
h1, h2 {
color: white;
font-family: Trebuchet MS;
font-weight: assuming;
text-align: middle;
}
font-size: 6rem;
margin-top: 30vh;
}
@media (max-width: 750px) {
#background-video { display: none; }
body {
background: url("https://assets.codepen.io/6093409/river.jpg") no-repeat;
groundwork-size: cover;
}
}
Add More than Page Content
A CSS Video Groundwork to Engage Your Audience
How To Change Background Image Height And Width In Css,
Source: https://blog.hubspot.com/website/video-background-css
Posted by: warrendanythas.blogspot.com
0 Response to "How To Change Background Image Height And Width In Css"
Post a Comment