how do I replicate this #media screen effect in html & css? - html

I have a video in my html that I ideally do not want to play on tablet & mobile device browsers, just desktops. I've come across this site "https://www.myprovence.fr" that mirrors this exactly.
As you can see on the landing page they have a video in the header that when scaled down to a specific breaking point, displays an image (the background image I'm guessing), this is not such a big feat. However, I loaded this site on mobile safari in the iPad Pro simulator from Xcode, & it too instead of showing the actual video, has the image:
As we know, the iPad Pro screen size is well beyond 2000px, so i doubt a #media screen method was used. so how did they create this effect where the video only plays on desktop browsers?
Here is my html:
<div class="second-section">
<video class="rocky" autoplay="true" loop>
<source src="rocky_2.mp4" type="video/mp4">
<source src="rocky_2.webm" type="video/webm">
</video>
<div class="overlay"></div>
</div>
and my css:
.second-section {
position: relative;
height: 100vh;
background-color: #CD9B9B;
background-position: center;
background-size: cover;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-shadow: 0 1px 3px rgba(0,0,0,.8);
text-align: center;
overflow: hidden;
}
.rocky {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 1;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
background: transparent;
object-fit: contain;
}
any solutions?

So it seems i've been able to target desktop browsers through a media query based on resolution not screen size. Here is the query:
#media only screen and (-webkit-min-device-pixel-ratio:1.5),only screen and (min-resolution:144dpi) {
.rocky {
display: none;
}
}
by doing this, the video doesn't play on iPads/iPhone browsers but still does on desktop browsers. To be honest I can't fully wrap my head around the pro's and con's of using this method, so if someone can provide input your more than welcome :)

Related

How to provide adaptive full-width images with CSS background-image — or otherwise?

My site has full-width hero images. There are currently served as a CSS background-image with a single image URL that is 2000px wide. Loading one or more of these images on a small device is definitely sub-optimal. I would like to serve a 2000px image, a 1440px image, a 992px image, etc to improve page loading time on mobile.
It seems that I can use -webkit-image-set and image-set, but these only take dpi and 1x, 2x, etc. sizes, so that won't help in this case, as I understand it because this won't ever show smaller images on smaller screens. Alternately, I could serve different images with a media query, but that gets complicated fast if you want to serve images based on viewport and if a device is 2x or 3x. Or I could switch to a img tag instead and use srcset, but I have not been able to find a solution to get a full width image that scales both up and down and fills a fixed height. It seems like this should be possible with object-fit: cover, but no combination of max-width, height, max-height, etc that I have tried has worked.
Here's an example of the CSS background-image that I'm trying to make adaptive:
.hero {
display: block;
min-height: 80px;
width: 100%;
float: left;
position: relative;
padding: 0;
-webkit-background-size: cover;
background-size: cover;
background-position: center center;
background-image: url("https://place-hold.it/500x100");
}
<div style="width: 500px;"> <!-- for this example, is 100% on our page -->
<a class="hero"></a>
</div>
This is on Wordpress with Boostrap.
Here is how you can do that with a picture tag. I like using this tag because i think it gives you more control over the breakpoints.
Look it up here:
https://www.w3schools.com/tags/tag_picture.asp
/* Basic styling for body. not important */
body,
html {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
/* The parent container needs to have position:relative */
.example-container {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
color: #fff;
}
/* The content element needs position:relative, and z-index higher than the BG element */
.example-content {
position: relative;
z-index: 10;
margin: 0;
}
/* The picture element */
.image-full,
.image-full img {
display: block;
/* Absolute position the element with full width/height, and a low z-index */
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
/* Object-fit:cover will make the image fill the space */
object-fit: cover;
object-position: center;
}
<div class="example-container">
<h2 class="example-content">Content goes here</h2>
<picture class="image-full">
<source media="(min-width:1200px)" srcset="https://i.picsum.photos/id/1002/4312/2868.jpg?hmac=5LlLE-NY9oMnmIQp7ms6IfdvSUQOzP_O3DPMWmyNxwo">
<source media="(min-width:500px)" srcset="https://i.picsum.photos/id/10/2500/1667.jpg?hmac=J04WWC_ebchx3WwzbM-Z4_KC_LeLBWr5LZMaAkWkF68">
<img src="https://i.picsum.photos/id/100/2500/1656.jpg?hmac=gWyN-7ZB32rkAjMhKXQgdHOIBRHyTSgzuOK6U0vXb1w">
</picture>
</div>

Bootstrap4 compatibility with IE and Edge - Nav dropdown and video tag issues

I've made my first website, and I've run into some issues that I cannot solve myself.
The website is Bootstrap 4.
https://jsfiddle.net/NUJ88/cn2bdrw1/ <-- My nav
1: My main issue is compatibility with IE and Edge (Possibly also Firefox). Everything works fine in Chrome.
When I open it in IE11 the nav dropdowns aren't target-able and wont stay open on click. How do I solve this?
2: My second issue is the fullscreen html5 video function, which wont display on IE11 or Edge.
HTML:
<video autoplay muted loop id="homeVideo">
<source src="./local-source-mp4-file" type="video/mp4"; codecs="H.264/MPEG-4">
Your browser does not support HTML5 video.
</video>
CSS:
#homeVideo {
position: relative;
width: auto;
min-width: 100%;
height: auto;
background: transparent url(video-bg.jpg) no-repeat;
background-size: cover;
}
video {
display: block;
}
.video-container {
width: 100%;
max-height: 600px;
overflow: hidden;
position: fixed;
top: 0;
right: 0;
z-index: -100;
This will do the job. The css is responsive so the video keeps its 16:9 ratio on all screen formats. It is not possible to have full width and full height because a video is 16:9 and many screens are not.
If you do not support Opera older then version 25 then you can remove the type="video/ogg" line. All modern browsers support type="video/mp4".
Note that the width="320" height="180" in the <video> tag are doing nothing. The css sets width and responsive height.
The styling of the <video> is terrible. For example, it is not possible to change icons, change button shape, etc. etc. For syling, a Javascript player is required, lik jPlayer http://jplayer.org
Trying to automatically execute the video to full screen (like the full screen button on the video player) is not possible. Even with the Javascript 'requestFullscreen' method it will result in an error Video API can only be initiated by a user gesture. In other words, the full screen can only be started by the website visitor with, for example, a button in the html.
<body>
<div class="videoContainer">
<video width="320" height="180" autoplay controls muted>
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
<source src="https://www.w3schools.com/html/mov_bbb.ogg" type="video/ogg">
</video>
</div>
</body>
with this css to keep the 16:9 ratio on all screen formats
*, *::before, *::after {
box-sizing: border-box;
}
body {
margin: 0;
}
.videoContainer {
display: block;
width: 100%; /* width of video */
position: relative;
margin: 0;
padding: 0;
overflow: hidden;
}
.videoContainer::before {
display: block;
content: "";
padding-top: 56.25%; /* keep 16:9 ratio */
}
.videoContainer video {
position: absolute;
top: 0; bottom: 0; left: 0;
width: 100%;
height: 100%;
border: 0;
}

Video is overflow on mobile only

Trying to create a corner radius video using a container.
Works great on any browser on desktop, and on mobile video is overflow the container.
.videoC {
width: 70vw;
height: auto;
margin-top: 2%;
margin-left: calc(15vw - 4px);
border-radius: 10vw;
border-style: solid;
border-color: white;
border-width: 8px;
overflow: hidden !important;
}
.video {
width: 100%;
height: auto;
object-fit: contain;
}
<div class="videoC">
<video class="video" loop="loop" muted autoplay defaultMuted playsinline oncontextmenu="return false;" src="xxx"></video>
</div>
on mobile iOS safari, the video corners overflow.
Turns out to be a Safari bug, solution, is it add this to the parent :
transform: translate3d(0, 0, 0);
and it worked.
you need to create a mobile version of your site.
you can use:
#media only screen and (max-width: 600px){
//
}
where:
#media is the css rule of css--
only screen and() is for set a "limit" of your rule
--max-width if for set the maximum width for your rule

Margin White Stripe

Im having trouble getting rid of what it appears to be a margin error?...i've already tried setting margin and padding values as 0 but i keep getting that line, should i downsize the video or something?
I inserted the background video on a div tag. Is the video just out of place?
/* Default to hide the video on all devices */
#video{display:none}
/* Default to display the image on all devices */
#videosubstitute{display:block;width:auto;height:100%;}
html, body {
height: 100%;
margin: 0;
}
/*START VIDEO
==================================================*/
#fullScreenDiv{
width:100vh;
min-height: 100vh;
/* Set the height to match that of the viewport. */
height: 100vh;
width: auto;
padding:0!important;
margin: 0!important;
background-color: black;
position: relative;
}
#video{
width: 100vw;
height: auto;
object-fit: cover;
left: 0px;
top: 0px;
z-index: 1;
volume: .02;
}
#media (min-aspect-ratio: 16/9) {
#video{
height: 150%;
top: -100%;
}
#videosubstitute{
display:block;
width: 100%;
height: auto;}
}
#media (max-aspect-ratio: 16/9) {
#video {
width: 150%;
left: -100%;
}
#videosubstitute{display:block;width:auto;height:100%;}
}
/*if there is 992 pixels or more, then display the video but hide the image*/
#media only screen and (min-width : 992px) {
#video{display:block;}
#videosubstitute{display:none}
}
/* The container for our text and stuff */
#messageBox{
position: absolute; top: 0; left: 0;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height:100%;
}
/*END VIDEO
==================================================*/
<div id="fullScreenDiv" class="table-cell">
<img src="https://www.imi21.com/wp-content/uploads/2016/11/t12.jpg" id="videosubstitute" alt="Full screen background video"></img>
<div id="videoDiv">
<video preload="preload" id="video" autoplay="autoplay" loop="loop">
<!-- Note: Replacing the following sources that are local:
<source src="img/mc10.webm" type="video/webm"></source>
<source src="img/mc10.mp4" type="video/mp4"></source> -->
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4"></source>
</video>
</div>
</div>
This line seems off:
width:100vh;
vh means percent of the screen height. Probably a bad idea to use that as width.
Are you really sure you want the video to be cut off at the sides of the screen? Wouldn't it be better to have a black background and let the video fill the available space without stretching? E.g. fill: contain

Video tag to fill 100% div regardless of ratios

I am tying to have a video tag to fill 100% of a div:
a) it doesn't need to keep the ratios(otherwise we need to use the overflow:none);
b) fill a div, not the whole background;
c) it would be a plus to be responsible. Now it is as long as you re-size window diagonally. Keeping height and re-sizing horizontally cuts the video.
I have tried dozens if not hundreds of alternative, and all of them keep the initial video ratio.
it works in the fidlle .... maybe because the screen is small, maybe because fiddle is a better browser...
<body>
<div class="wrapper">
<div class="header">
.....
</div>
<div class="out-video">
<video autoplay loop poster="mel.jpg" id="bgvid" width="100%" height="100%">
<source src="http://www.mysite.braaasil.com/video/mel.webm" type="video/webm">
<source src="http://www.mysite.braaasil.com/video/mel.mp4" type="video/mp4">
</video>
</div>
</div>
The site is here but as I try the solutions, it will change... There is a right and left sidebar empty. I would like the video to fill the whole width. When it covers the div, the height change and the video does not show in full. I would like something like the background-size 100% 100% that stretches the images to the end of the div, but it does not work for video.
Thank you for any suggestion in advance.
PS. It seems that android family does not play the video!
l
Use object-fit css property, though there is no support for IE, but it's still quite reasonable to be used for <video>, <img> tags.
Check CanIUse for Browser Support, and CSS-Tricks for usage.
Example:
/** If parent has some defined width/height */
.video-element {
width: 100%;
height: 100%;
object-fit: cover;
}
You can use a solution like this one. Ratio dont change, but you may lose the right part of the video.
video#bgvid {
position: absolute;
z-index: 0;
background: url(mel.jpg) no-repeat;
background-size: 100% 100%;
top: 0px;
left: 0px; /* fixed to left. Replace it by right if you want.*/
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
}
The video will be fix to top left corner. If you want to improve it, I think you will need some JavaScript.
Edit :
Just a find a solution with JQuery who can fit your need : simulate background-size:cover on <video> or <img>
Demo
Simple CSS inheit
video {
width: inherit;
height: inherit;
}
div {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: black;
}
Try this
HTML:
<div id="MainBanner">
<video autoplay muted loop>
<source src="something-nice.mp4" type="video/mp4">
</video>
<div class="content">
<h1>Heading</h1>
<p>Some Content</p>
</div>
</div>
Less:
#MainBanner {
position: relative;
height: 100vh;
overflow: hidden;
video {
background: url(cover.jpg) no-repeat;
top: 0px;
left: 0px;
min-width: 100%;
min-height: 100%;
}
.content {
position: absolute;
padding: 20px;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
color: #f1f1f1;
width: 100%;
}
}