I have two images, one I need for landscape orientation and one for portrait.
Using <picture>, i can use standard media queries, but <picture> is not supported on Safari, so i want to use <img srcset>. I can't find any information, how to adress portrait orientation for any device in srcset.
Any help?
You can't use srcset for art direction. Use <picture> and picturefill instead.
safari now supports <picture> . Here is code to display different images for portrait and landscape modes.
<picture>
<source media="(orientation: landscape)" srcset="landscape.jpg">
<source media="(orientation: portrait)" srcset="portrait.jpg">
<img src="fallback-image.jpg">
</picture>
Related
I have view port ~1200px and picture container has 180px. This code:
<picture>
<img srcset="img_180.jpg 180w, img_350.jpg 350w" src="img_350.jpg" alt="">
</picture>
loads img_350.jpg. Why it happens if image container is 180px?
Okey, maybe I have to set sizes attribute. My picture container is 180px if view port is > 576px, else it has 100% width. So this code:
<picture>
<img sizes="(min-width: 576px) 180px, 100vw" srcset="img_180.jpg 180w, img_350.jpg 350w" src="img_350.jpg" alt="">
</picture>
loads both img_180.jpg and img_350.jpg. How to fix this? I need to load img_180.jpg only if user has > 576px view port, else load img_350.jpg, because if <= 576 px picture container has 100% width.
You might think because img_350.jpg loads automatically from src, but that's not right, because I added <source ... type="image/webp"> and it loaded img_180.webp and img_350.webp (no .jpg).
https://jsfiddle.net/wLprbk7j/
This is because you have both src and srcset defined. Remove src attribute. This will let browsers calculate the src based on srcset and media queries. Browser will then automatically load the correct image.
As a fallback, remember to include picturefill.js
I have a simple HTML5 audio player that I would like to make responsive in Bootstrap.
<div class="col-sm-4 col-sm-offset-4">
<audio controls style="width: 600px;">
<source src="sample.mp3">
</audio>
</div>
Is there a way to make the div containing this audio player responsive no matter what content is in it or at least a class or something to make the audio player responsive? Hoping to not have to use an external library if possible.
Thanks!
I suggest to use width:100% and max-width:600px.
When you make the window smaller in a desktop browser you will not see it the same way as on a real mobile device, but the audio element on mobile devices (i.e. iOS, Android) is definitely going to be smaller anyways - you don't have much influence on its apprearance. Together with those settings it should adapt to just about any situation properly.
(You just might want to add a second source tag with the audio in ogg format and also add the file format in the source tag/s, see https://www.w3schools.com/tags/tag_audio.asp)
Try:
<div class="col-sm-4 col-sm-offset-4 embed-responsive embed-responsive-4by3">
<audio controls class="embed-responsive-item">
<source src="sample.mp3">
</audio>
</div>
Ref: http://getbootstrap.com/components/#responsive-embed
I'm having 2 problems with media queries and HTML5.
The below code in the <body> section of an html file, is in a div that's given an id name of social_networks.
Problems
1) delicious_old.jpg does not show on devices whose screen width is upto 375px.
Tested with Chrome 36.0.1985.135 on an LG L20.
2) delicious.jpg does not show on devices whose screen width is from 375px to 2560px.
Tested with Firefox in Ubuntu 14.01 - 15 inch monitor.
I've search on SO, and Google and read lots of articles and questions but not come across one yet that solve them.
Code:
<figure>
<!-- low-res, default -->
<source src="/resources/delicious_old.jpg" media="(min-device-width: 0px) and (max-device-width: 375px)">
<!-- medium-res -->
<source src="/resources/delicious.jpg" media="(min-device-width: 375px) and (max-device-width: 2560px)">
<!-- Fallback content -->
<!--<img src="/resources/delicious.jpg" alt="Add to Delicious">-->
</figure>
Above code updated following comments.
Please advise
I went to this discussion from 2012:
How to load different video for mobile devices and desktop web version?
because I was having the same problem. My mp4, webm and ogg videos of 7MB or so work fine on my desktop computer but hang up miserably on my Android smartphone.
#Subhajit gave this sample code that he had tried unsuccessfully:
<video controls>
<source src="mySmallVideo.webm" type="video/webm" media="all and (max-width:600px)">
<source src="myVideo.webm" type="video/webm">
</video>
and was referred to a stackoverflow discussion on the best way to detect a handheld device.
But that only gave advice for detecting when the site was being viewed on a mobile device. Nobody offered alternative code to his sample, for showing a smaller version of the video after a mobile device was detected.
My responsive site CSS code has #media (max-width: media queries. The one for mobile devices is set at 500px. How could I modify the sample code of #Subhajit to show a smaller version of a video, perhaps referencing the media query #media (max-width: 500px) coding in my CSS file?
I'd rather not use mobile detection, commercial video players, or online storage sites.
Thanks, #Fabio Here is my code so far from your first suggestion:
<video controls>
<source src="portfolioVideos/testMovieWEnd480x270.mp4.mp4" type="video/mp4" media="all and (max-width: 500px)">
<source src="portfolioVideos/testMovieWEnd480x270.webmsd.webm" type="video/webm" media="all and (max-width: 500px)">
<source src="portfolioVideos/testMovieWEnd720x405.mp4.mp4" type="video/mp4">
<source src="portfolioVideos/testMovieWEnd720x405.webmsd.webm" type="video/webm">
I made two five-second "movies," consisting of a "test pattern" still which ends with a "the end" superimposed on it. The big movie for computer screens is 720x405 pixels and labeled "for 'puter." The small one for mobile screens is 480x270 pixels and is labeled "for mobile." When I alternate window sizes in Firefox and Safari (and refresh), they actually bring up the proper version. Chrome only shows the mobile version. (Reversing the order in the coded only makes everything worse.)
The mobile version also comes up when I enter the video html in Mobile Phone Emulator. But when I call it up on my Android smartphone, the vid is so minascule I can't read which version it is, or even click on it.
I looked at that the Chris Coyier page you recommended, but I couldn't figure it out. How would I search for more on this jQuery code? Thanks for previous and any possible follow.
I tried taking a couple of new tacks on this problem.
First, I tried using a jquery "window width" method and an if/else conditional to bring either a small or large version of the video into an iframe.
$(document).ready(function () {
if ($(window).width() < 550) {
<iframe src=... width="480" height="270"></iframe>
}
else {
<iframe src=... width="720" height="405"></iframe>
}
});
</script>
That didn't work. Safari and Chrome both give me an "Unexpected token '<'" error, which I understand "happens when you're including or posting to a file which doesn't exist." These files exist and work when opened directly. I tried using absolute urls, as recommended by #amenadiel, but that didn't work either.
Second, I tried "window location" with an if/else conditional.
$(document).ready(function () {
if ($(window).width() < 330) {
window.location.href = ...;
}
else {
window.location.href = ...;
}
});
This works when tested in the various simulated devices and window sizes on two online emulators. But it doesn't work on my Android smartphone. There, just a tiny, empty, unclickable video window in the upper left of the screen.
I may have answered my own question.
I found here:
https://github.com/etianen/html5media/wiki/embedding-video
this super simple code:
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
</head>
<body>
<video poster="poster.jpg" width="618" height="347" controls preload>
<source src="video.mp4" media="only screen and (min-device-width: 568px)"></source>
<source src="video.iphone.mp4" media="only screen and (max-device-width: 568px)"></source>
</video>
which seems, miraculously, to have worked. Check out this page,
http://willsoper.net/videoPortfolio.html
which contains two videos, each with a large and small version.
Try the "Test Pattern" one on the right first; it's only ten seconds long. The larger version is labeled "for 'puter" and the smaller one, "for Mobi." On my Samsung Galaxy Android in vertical position, the "Mobi" version appears. If I hit the back button, turn the phone to horizontal, and try it again, the larger, "'puter" version appears.
The video on the left, with the man, also has a small and large version and seems to work the same way. It is much longer and on my smartphone it sometimes re-buffers briefly once or twice.
Ironically, my previous coding worked in online emulators but not on my actual smartphone. This one works on my smartphone but not on the emulators.
I'd appreciate knowing what others, especially #Fabio , experience and how I might improve on the code.
well, Frist add class to each video
I have two videos with different size
<div class="fullscreen-video-wrap" height="800px">
<video id="video" class="vidbig" src="./picture/ThisEgypt.mp4" autoplay="true" loop="true" muted="false" width="100%" ></video>
<video id="video" class="vid-mobi" src="./picture/Dolphin.mp4" autoplay="true" loop="true" muted="false" width="100%" ></video>
</div>
and on css media query
#media only screen and (min-width: 900px){
.vid-mobi{
display: none;}
}
#media only screen and (max-width: 900px){
.vidbig {
display: none;
}
}
Well, you have 2 options:
1) Serving video based on media queries just as you mention. You simply set different sizes based on the device width, like this:
<video>
<source src="video-ipad.mp4" type="video/mp4" media="all and (max-width: 768px)">
<source src="video-mobi.mp4" type="video/webm" media="all and (max-width: 768px)">
<source src="video-mobi.mp4" type="video/mp4" media="all and (max-width: 480px)">
<source src="video-mobi.webm" type="video/webm" media="all and (max-width: 480px)">
<source src="video.mp4" type="video/mp4">
<source src="video.webm" type="video/webm">
</video>
You can also use some JQuery screen detection as shown on this page
var mainVideo = $('#the-video');
if ($(window).width() < 1200 && medQualVersion) {
mainVideo.append("<source type='video/mp4' src='" + medQualVersionSrc + "' />");
} else {
mainVideo.append("<source type='video/mp4' src='" + highQualVersionSrc + "' />");
}
mainVideo.append("<source type='video/webm' src='" + webMSrc + "' />");
// Wait until sources are appended to call MediaElements.js
mainVideo.mediaelementplayer();
The second option is to simply server high quality video and resize it, like this:
video{max-width:100%; height:auto}
this way is bullet proof and always work, not to mention you serve better quality video. But of course, you'll have the data transfer issue, so for big videos I'd recommend method 1 .
Is it possible to cross-browser style the controls of a browser-native video such as video from HTML5's video tag?
I do not understand if it is possible or not, I can't find anything other than this article but it seem uses Javascript.
I would like to make the controls bar fit the video width; as you can see from the image attached, the controls bar excedes the video width.
HTML for the above image
<div class="video centered-content">
<a class="circle-canvas close-video" href="javascript:void(0)" id="video-close" rel="tooltipTOP" data-original-title="close">X</a>
<video width="63%" height="60%" id="video" class="video" controls>
<source src="<?php echo base_static_url();?>media/video.mp4">
<source src="<?php echo base_static_url();?>media/video.ogv">
<source src="<?php echo base_static_url();?>media/video.webm">
</video>
</a>
</div>
Here is a good example for styling native player controls(just tested in Chrome): https://codepen.io/BainjaminLafalize/pen/GiJwn
To change the width of the player controls bar:
video::-webkit-media-controls-panel {
width: 40px;
}
You can style native controls in some browsers, using shadow DOM. Enable shadow dom in debug inspector settings:
http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom/
HTML5 Video Controls - make larger?
You could style the shadow DOM, but you need to look at every browser individually and a browser update could destroy your styling.
I recommend taking a look at MediaElement.js which gives you cross-browser controls that can be styled using CSS and are already accessibility-optimized.
Or if you only need a few controls anyway, build your own: https://developer.mozilla.org/en-US/docs/Web/Guide/Audio_and_video_delivery/Video_player_styling_basics