mirror of
https://github.com/phuoc-ng/csslayout.git
synced 2025-08-10 16:14:19 +02:00
feat: Video background
This commit is contained in:
8
contents/_includes/patterns/video-background.njk
Normal file
8
contents/_includes/patterns/video-background.njk
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<div class="video-background">
|
||||||
|
<div class="video-background__inner">
|
||||||
|
<video class="video-background__video" src="/assets/video-background-demo.mp4" autoplay loop muted></video>
|
||||||
|
</div>
|
||||||
|
<div class="video-background__content">
|
||||||
|
{% lines "hor", 5 %}
|
||||||
|
</div>
|
||||||
|
</div>
|
@@ -175,6 +175,12 @@ eleventyExcludeFromCollections: true
|
|||||||
<div class="pattern__title">Voting</div>
|
<div class="pattern__title">Voting</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="pattern__item">
|
||||||
|
<a class="pattern__link" href="/video-background/">
|
||||||
|
<div class="pattern__cover">{% include "patterns/video-background.njk" %}</div>
|
||||||
|
<div class="pattern__title">Video background</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
78
contents/video-background.md
Normal file
78
contents/video-background.md
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
---
|
||||||
|
layout: layouts/post.njk
|
||||||
|
title: Video background
|
||||||
|
description: Add video background with CSS flexbox
|
||||||
|
keywords: css flexbox, object fit cover
|
||||||
|
---
|
||||||
|
|
||||||
|
In this pattern, the video is displayed in the background.
|
||||||
|
|
||||||
|
## HTML
|
||||||
|
|
||||||
|
```html
|
||||||
|
<div class="video-background">
|
||||||
|
<!-- The video container -->
|
||||||
|
<div class="video-background__inner">
|
||||||
|
<video class="video-background__video" src="...">
|
||||||
|
...
|
||||||
|
</video>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- The content -->
|
||||||
|
<div class="video-background__content">
|
||||||
|
...
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
```
|
||||||
|
|
||||||
|
## CSS
|
||||||
|
|
||||||
|
```css
|
||||||
|
.video-background {
|
||||||
|
/* Used to position the video and content */
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.video-background__inner {
|
||||||
|
/* Positioned at the top left corner */
|
||||||
|
left: 0px;
|
||||||
|
position: absolute;
|
||||||
|
top: 0px;
|
||||||
|
|
||||||
|
/* Take full size */
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
/* Hide the scrollbar */
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.video-background__video {
|
||||||
|
object-fit: cover;
|
||||||
|
|
||||||
|
/* Take full width */
|
||||||
|
height: 100%;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.video-background__content {
|
||||||
|
/* Positioned at the top left corner */
|
||||||
|
left: 0px;
|
||||||
|
position: absolute;
|
||||||
|
top: 0px;
|
||||||
|
|
||||||
|
/* Take full size */
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
/* Center the content */
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
{% demo %}
|
||||||
|
{% include "patterns/video-background.njk" %}
|
||||||
|
{% enddemo %}
|
@@ -1,155 +0,0 @@
|
|||||||
import * as React from 'react';
|
|
||||||
import Head from 'next/head';
|
|
||||||
import { Spacer } from '@1milligram/design';
|
|
||||||
|
|
||||||
import { RelatedPatterns } from '../../components/RelatedPatterns';
|
|
||||||
import { Pattern } from '../../constants/Pattern';
|
|
||||||
import { PatternLayout } from '../../layouts/PatternLayout';
|
|
||||||
import Block from '../../placeholders/Block';
|
|
||||||
import BrowserFrame from '../../placeholders/BrowserFrame';
|
|
||||||
|
|
||||||
const Details: React.FC<{}> = () => {
|
|
||||||
return (
|
|
||||||
<PatternLayout pattern={Pattern.VideoBackground}>
|
|
||||||
<Head>
|
|
||||||
<meta name="description" content="Add video background with CSS flexbox" />
|
|
||||||
<meta name="og:description" content="Add video background with CSS flexbox" />
|
|
||||||
<meta name="twitter:description" content="Add video background with CSS flexbox" />
|
|
||||||
<meta name="keywords" content="css flexbox, object fit cover" />
|
|
||||||
</Head>
|
|
||||||
<div style={{ lineHeight: 1.5, marginBottom: '16px' }}>
|
|
||||||
In this pattern, the video is displayed in the background.
|
|
||||||
</div>
|
|
||||||
<BrowserFrame
|
|
||||||
html={`
|
|
||||||
<div class="container">
|
|
||||||
<!-- The video container -->
|
|
||||||
<div class="container__wrapper">
|
|
||||||
<video class="container__video" src="...">
|
|
||||||
...
|
|
||||||
</video>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- The content -->
|
|
||||||
<div class="container__content">
|
|
||||||
...
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`}
|
|
||||||
css={`
|
|
||||||
.container {
|
|
||||||
/* Used to position the video and content */
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.container__wrapper {
|
|
||||||
/* Positioned at the top left corner */
|
|
||||||
left: 0px;
|
|
||||||
position: absolute;
|
|
||||||
top: 0px;
|
|
||||||
|
|
||||||
/* Take full size */
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
|
|
||||||
/* Hide the scrollbar */
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.container__video {
|
|
||||||
object-fit: cover;
|
|
||||||
|
|
||||||
/* Center the video */
|
|
||||||
left: 50%;
|
|
||||||
position: absolute;
|
|
||||||
top: 50%;
|
|
||||||
transform: translate(-50%, -50%);
|
|
||||||
|
|
||||||
/* Take full width */
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.container__content {
|
|
||||||
/* Positioned at the top left corner */
|
|
||||||
left: 0px;
|
|
||||||
position: absolute;
|
|
||||||
top: 0px;
|
|
||||||
|
|
||||||
/* Take full size */
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
|
|
||||||
/* Center the content */
|
|
||||||
align-items: center;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
`}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
alignItems: 'center',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
height: '100%',
|
|
||||||
justifyContent: 'center',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
height: '100%',
|
|
||||||
position: 'relative',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
height: '100%',
|
|
||||||
left: 0,
|
|
||||||
overflow: 'hidden',
|
|
||||||
position: 'absolute',
|
|
||||||
top: 0,
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<video
|
|
||||||
style={{
|
|
||||||
objectFit: 'cover',
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
autoPlay={true}
|
|
||||||
loop={true}
|
|
||||||
muted={true}
|
|
||||||
playsInline={true}
|
|
||||||
src="/assets/video-background-demo.mp4"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
alignItems: 'center',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
height: '100%',
|
|
||||||
justifyContent: 'center',
|
|
||||||
left: 0,
|
|
||||||
position: 'absolute',
|
|
||||||
top: 0,
|
|
||||||
width: '100%',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ width: '250px' }}>
|
|
||||||
<Block backgroundColor="#fff" justify="center" numberOfBlocks={10} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</BrowserFrame>
|
|
||||||
<Spacer size="extraLarge" />
|
|
||||||
<RelatedPatterns patterns={[Pattern.FullBackground, Pattern.OverlayPlayButton]} />
|
|
||||||
</PatternLayout>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Details;
|
|
@@ -1,34 +0,0 @@
|
|||||||
import * as React from 'react';
|
|
||||||
|
|
||||||
import Frame from '../../placeholders/Frame';
|
|
||||||
import Line from '../../placeholders/Line';
|
|
||||||
|
|
||||||
const Cover: React.FC<{}> = () => {
|
|
||||||
return (
|
|
||||||
<Frame>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
alignItems: 'center',
|
|
||||||
backgroundColor: 'rgba(0, 0, 0, 0.25)',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
height: '100%',
|
|
||||||
justifyContent: 'center',
|
|
||||||
padding: '8px',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style={{ marginBottom: '4px', width: '80%' }}>
|
|
||||||
<Line backgroundColor="#fff" />
|
|
||||||
</div>
|
|
||||||
<div style={{ marginBottom: '4px', width: '60%' }}>
|
|
||||||
<Line backgroundColor="#fff" />
|
|
||||||
</div>
|
|
||||||
<div style={{ width: '40%' }}>
|
|
||||||
<Line backgroundColor="#fff" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Frame>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Cover;
|
|
@@ -36,6 +36,7 @@
|
|||||||
@import './patterns/fixed-at-side';
|
@import './patterns/fixed-at-side';
|
||||||
@import './patterns/full-background';
|
@import './patterns/full-background';
|
||||||
@import './patterns/initial-avatar';
|
@import './patterns/initial-avatar';
|
||||||
|
@import './patterns/video-background';
|
||||||
@import './patterns/voting';
|
@import './patterns/voting';
|
||||||
@import './patterns/watermark';
|
@import './patterns/watermark';
|
||||||
|
|
||||||
|
46
styles/patterns/_video-background.scss
Normal file
46
styles/patterns/_video-background.scss
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
.video-background {
|
||||||
|
/* Used to position the video and content */
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.video-background__inner {
|
||||||
|
/* Positioned at the top left corner */
|
||||||
|
left: 0px;
|
||||||
|
position: absolute;
|
||||||
|
top: 0px;
|
||||||
|
|
||||||
|
/* Take full size */
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
/* Hide the scrollbar */
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.video-background__video {
|
||||||
|
object-fit: cover;
|
||||||
|
|
||||||
|
/* Take full width */
|
||||||
|
height: 100%;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.video-background__content {
|
||||||
|
/* Positioned at the top left corner */
|
||||||
|
left: 0px;
|
||||||
|
position: absolute;
|
||||||
|
top: 0px;
|
||||||
|
|
||||||
|
/* Take full size */
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
/* Center the content */
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
Reference in New Issue
Block a user