how to make a responsive vertical video on html css? - html

I've to insert a vertical video on my website built using html css. the video must be in left side and it should be responsive. This code is displaying the vertical video on left side but on mobile it is not responsive. what I've to change here to make it responsive.
<div class="vert_video">
<video width="320" height="540" controls>
<source src="vertical_video.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
When i change width to 100% it shows the video on entire screen which looks weird on desktop. help me to make this video responsive.

I think you should add vert_video class to video element.
<div>
<video class="vert_video" controls>
<source src="vertical_video.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
Then, add media queries to your css file. In your media queries, you can set max-width or width, which would be useful for you.
/*this query will apply for the devices those have width smaller than 480px*/
#media (max-width: 480px) {
.vert_video {
width: 100%;
height: 100%;
}
}
.vert_video {
width: 75%;
height: 75%;
}

you can use this property in css to set your video's width and height based on device width and length
#media only screen and (max-width: 520px){
/* change the width and height of your video here using video property or the video containing class
it will update the width and height as soon the width of device will go less
than 520px, most of cell phones have width less than 520px(you can change
that too)
*/
}

Related

Video too large for mobile browser

I have a video on one of my html pages, and I love the dimensions for it on desktop, but on mobile its way too large, and is extending the screen.
I know this is fixable but I'm a bit confused in the solution I've looked a few up and am still confused.
<video width="900" height="450" autoplay loop controls >
<source src="images/Demo.mov" type="video/mp4">
Your browser does not support the video tag.
</video>
video{
max-width:900px;
width:100%;
}
<video height="450" autoplay loop controls >
<source src="images/Demo.mov" type="video/mp4">
Your browser does not support the video tag.
</video>
below CSS might help you.
video{
max-width:900px;
width:100%;
}
Remove the width and height attributes inside the HTML.
<video autoplay loop controls >
<source src="images/Demo.mov" type="video/mp4">
Your browser does not support the video tag.
</video>
Use CSS media queries to style the video frame. Example:
#media only screen and (max-width: 600px) {
video {
width: 900px;
height: 450px;
}
}
See the first line of the CSS code. There stands max-width: 600px. This is the maximal width of your screen. 600px are small devices.
Disclaimer: the CSS code is pseudo code. Play with the numbers to fit it into your screen and for mobile use percentage instead of pixels.
If you use width: 100%; it will be responsive to any screen size.
Using the CSS code multiple times with other screen sizes, you could support tablet or computer screens.
P.S.: Use mp4 files instead of mov files. It's more widely supported by the browsers.

is there any way to fit video into single screen for all device and for all browser

i have video at banner and i want is that vedio should fit into single screen for all device and for all browser the the probleis that its look smaller in height in chrome but looks larger in safari
.banner{
position: relative;
}
video {
width: 100%;
}
<div className="banner">
<div className="spread-video">
<video playsInline muted autoPlay loop src={BannerVideo1} type='video/mp4'/>
</div>
</div>
Use Media Queries.
.spread-video{
#media(max-width: 768px) {
/*Styles to be executed when screen is narrower than 768px*/
}
}
Media queries are used for responsive web development, and are highly customizable. The above is just an example of using the max-width style property to deterime which styles need to be applied. You can use multiple media queries in one class to cover what needs to be covered.

How can i change the width and height of an image inside a <source> element?

For example:
<picture>
<source media="(min-width:650px)" srcset="mycat.jpg">
<source media="min-width:460px)" srcset="burncar.jpg">
<img src="burncar2.jpg" style="width:auto;">
</picture>
Now, the srcset image loads in full size. How do i change its size? I tried adding "width" and "height" within the element, but it doesn't work. I tried adding a Class inside the element and then target it in CSS to change the size, but again it didn't work. Why? And how do i change the size of the pictures?
You can achieve this with #media in CSS matching your source media min-width. Look at what I did in this example. Here's the jsfiddle for you to play around with the screen size. https://jsfiddle.net/ukwhn8p1/4/
#media (min-width: 460px) {
.pictures {
width: 25%;
}
}
#media (min-width: 650px) {
.pictures {
width: auto;
}
}
<picture>
<source media="(min-width:650px)" srcset="https://www.w3schools.com/tags/img_white_flower.jpg">
<source class="flower" media="(min-width:460px)" srcset="https://www.w3schools.com/tags/img_pink_flowers.jpg">
<img class="pictures" src="https://www.w3schools.com/html/img_girl.jpg" style="">
</picture>
What i tend to do to size images is to put a <div class="image_container"> around the image. Setting the width for the container makes the picture to always load at that width.
Sometimes 'weird' behavior can turn up due to weird image heights, but that tends to only be the case with images you can't control the source of (aka. some internet image from a link to it, or some upload). Same is obviously true if you only set the height.
Setting both the width and height can distort an image, as it is made to fit the size of the parent (aka. the image_container).
Cool thing about this though, is that you can set min and max widths for the container and get pretty decent control over the reactivity of the design based upon view or window size.
If you can control the actual source of the image (aka. you control the initial width and height), or you can account for deviations in either width or the height in your design. This works satisfactory.

HTML5 Video Has Dark Gradient on the Bottom that doesn't fit the container

I have a <video> tag in my HTML, that looks like this:
<video control>
<source src="[video_url].webm" type="video/webm">
<source src="[video_url].mp4" type="video/mp4">
<p>Your browser does not support this type of video</p>
</video>
This video is hosted on Cloudinary, and I'm doing an inline transform with the src to get a specific dimension (w_450,h_350).
The video by itself looks fine, however I have a media query where I shrink the video by 100px in both width and height to fit smaller screen sizes
#media screen and (max-width: 1000px) {
video { width: 350px; height: 250px }
}
And as you can see, the video container has a shadow that overflows past the width and height of the new container size. If I click play on the video, the box shadow persists.
How do I make the box-shadow for the controls fit the actual size of the container?
Rather than applying height width to the tag you should enclose it within a
<div>
<video control>
<source src="[video_url].webm" type="video/webm">
<source src="[video_url].mp4" type="video/mp4">
<p>Your browser does not support this type of video</p>
</video>
</div>
And then apply your css to the
#media screen and (max-width: 1000px)
{
div{ width: 350px; height: 250px }
video{ width: 100%; height: 100% }
}

html crops height video to height 100vh, video to fullscreen

I am struggling with a stupid little thing. Working on this site:
(sorry for the slow server, school stuff you know)
The video you'll see is on height vh100, which is what i want. When I have this video on the max height of your browser the width of the video is not fullscreen.
The code I have now:
HTML
<!-- video -->
<video id="moodvideo" autoplay loop>
<source src="moodvideo.mp4" type='video/mp4'>
</video>
CSS
/* Video */
video {
height: 100vh;
width: 100vw;
}
What I am trying to achieve is the video on full screen, width 100wh and height 100vh. If the height (of the video with width 100wh) is bigger then the height 100vh, I want the video to crop so it will be on fullscreen view on the max width and height your browser. By cropping, I don't bother to missing some of the video (50px from the bottom or so), fullscreen in width and height is more important to me.
Now, I already searched and tried a lot before asking you guys, things like; vw100/vh100, min-height/width 100, add the movie in a div, div to 100 vh/vw, and some scripts I found but nothing really works...
You could use the jquery videoBG plugin: http://syddev.com/jquery.videoBG/
Or you could add the following code: https://jsfiddle.net/wcv2ak9p/1/
The alternative image is displayed when the browser doesn't support the video.
HTML
<video id="moodvideo" autoplay loop>
<source src="moodvideo.mp4" type='video/mp4'>
<img id="alternative" src="alternative.jpg" />
</video>
CSS
#moodvideo, #alternative {
width: 100vw; /* Could also use width: 100%; */
height: 100vh;
object-fit: cover;
position: fixed; /* Change position to absolute if you don't want it to take up the whole page */
left: 0px;
top: 0px;
z-index: -1;
}