How to make responsive video background in DIV container with dynamic height? - css

I've been looking for a way to create a video background (preferably an HTML5 / CSS-only solution) for a header DIV on a little micro-site.
Obviously, there are a lot of resources on how to do this if you want a fixed background (position:fixed;) that'll apply to the entire page or if your DIV has a fixed height, but I want to apply it to a single DIV (within the Bootstrap framework, coincidentally) with a dynamic height attribute.
It would have a min-height value of 100vh, but the DIV's height should be able to be larger depending on the content within it (in this scenario, I have a couple of introductory paragraphs that would likely require some scroll on smaller screens).
I kind of got it half way there with my original approach, but a little bit of my video extends beyond the container DIV and giving the container an overflow:hidden; attribute doesn't help.
Here's a CodePen with the code below + Bootstrap so that you can see what I'm talking about in action.
Screenshot of the video extending into the next DIV, just in case.
This is essentially the pertinant code to my 90% of the way there option... (it looks like the video takes the 100% width this way, but it doesn't crop the height to the container):
<div class="content contain-header">
<div class="container">
<div class="row main-header">
<video autoplay loop poster="images/clouds.jpg" id="bgvid">
<source src="images/clouds.webmhd.webm" type="video/webm" />
<source src="images/clouds.mp4" type="video/mp4" />
</video>
<div class="col-md-2 col-xs-1">
</div>
<div class="col-md-8 col-xs-10">
<img src="images/logo.svg" class="header-logo" />
<h1 id="header-you">Wow</h1>
<p>Business model canvas rockstar user experience founders handshake. Startup responsive web design bootstrapping first mover advantage disruptive crowdfunding. User experience iteration seed money rockstar holy grail deployment prototype gen-z backing influencer handshake success. Virality growth hacking innovator product management iPad.</p>
<p>Crowdsource marketing non-disclosure agreement graphical user interface bootstrapping market research & development:</p>
<p class="punch">Stratup Ipsum!</p>
<p class="continue"><span class="glyphicon glyphicon-menu-down"></span></p>
</div>
<div class="col-md-2 col-xs-1">
</div>
</div>
</div>
</div>
And the relevant CSS, in SCSS format (+Bootstrap v3.3.5):
.contain-header {
background-color: rgba(0, 0, 0, 0.6);
.main-header {
min-height:100vh;
display:block;
color:$color-white;
video#bgvid {
position:absolute;
top:50%;
left:50%;
min-width:100%;
min-height:100%;
width:auto;
height:auto;
z-index:-100;
-ms-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
-webkit-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
background: url(../images/clouds.jpg) no-repeat;
background-size: cover;
}
video {
display:block;
}
.header-logo {
max-width:40%;
height:auto;
margin:0 auto;
display:block;
padding-top:20px;
}
h1#header-you {
text-transform:uppercase;
text-align:center;
font-family:$tultra;
}
p {
font-size:2rem;
}
p.punch {
font-size:2.3rem;
text-align:center;
margin-top:30px;
}
.continue {
text-align:center;
padding-top:20px;
padding-bottom:40px;
a, a:visited {
color:$color-white;
text-decoration:none;
}
a:hover {
color:$color-gray-icons;
text-decoration:none;
}
}
#media screen and (max-width: 767px) {
p {
font-size:1.4rem;
}
p.punch {
font-size:1.8rem;
}
}
}
}

Try adding this to the start of your styles
.contain-header {
position: relative;
overflow: hidden;
background-color: rgba(0, 0, 0, 0.6);
...
The position relative on the contain-header means that the video min-height, min-width etc. is relative to it.

Related

multiple images in div

Could not find anything on this for the life of me. I simply want to display 1 little icon, multiple times on the same row,
But want to rotate each instance a bit more then the last one. So by the end of the row, the last icon is completely flipped compared to the first icon.
Here is my attempt: (thanks)
<div class="container">
<p class="one">I don't</p><p class="two">really want </p><p class="three">any</p><p class="four">words here</p>
</div>
<style>
p.one {
float:left;
image: url("http://www.itel.am/assets/ico/iconsForSocials/gl.png");
}
p.two {
float:right;
background-image: url("http://www.itel.am/assets/ico/iconsForSocials/gl.png");
transform: rotate(60deg);
}
p.three {
float:right;
background-image: url("http://www.itel.am/assets/ico/iconsForSocials/gl.png");
transform: rotate(120deg);
}
p.four {
float:right;
background-image: url("http://www.itel.am/assets/ico/iconsForSocials/gl.png");
transform: rotate(180deg);
}
</style>
Positioning system in a row can be achieved with 2 ways. The first and easy way is bootstrap grid system , so your problem could be solved like this
<div class="container-fluid">
<div class="col-sm-3">img</div>
<div class="col-sm-3">img</div>
<div class="col-sm-3">img</div>
<div class="col-sm-3">img</div>
</div>
Replace the img keyword i wrote with your images and transform them as you like inside css and you will be all set.
The second and more advanced way to place images in a row inside a div is position css attribute.
position:relative;
top:40px;
left:70px;
This will place the element in a specific place relative to its parent , so then you could place them wherever you want.
There are definitely more ways to do this like flexbox and more , but i totally recommend using bootstrap grid system because its easy to use and most of all responsive!
I think you should separate the text from rotating. something like this
<div class="container">
<p><span class="one"></span>I don't</p>
<p><span class="two"></span>really want </p>
<p><span class="three"></span>any</p>
<p><span class="four"></span>words here</p>
</div>
and in css use image as background image
.container {width:100%}
.container p { float:left; margin:0 20px}
.container p span {
width:20px; height:20px; display:block;
background: url("http://www.itel.am/assets/ico/iconsForSocials/gl.png") no-repeat left center; float:left;
}
.two { transform: rotate(60deg); }
.three { transform: rotate(120deg); }
.four { transform: rotate(180deg); }
here is the working sample

How can I make this image responsive to page size without the text on it moving

So my page looks fine in a desktop, but when I look at it through any other device, (phone, tablet) the text on the page has moved lower into the other content. Is there a way to make it so that the text shrinks as the image does?
Here is my HTML:
<div class="hero">
<img src="resources/assets/home_header.png" alt="youth futures header"/>
<div class="text">
<h1>Hi</h1>
<p class="textstyle2">14 WARM BEDS. YOUTH 12-17.<br/>YOUR TEMPORARY HOME:)</p>
</div>
</div>
Here is the CSS:
.hero {
width:1280px;
margin:0rem auto;
position: relative;
}
.text {
position: absolute;
top:50%;
left:0;
padding:1rem;
transform:translateY(-50%);
text-align:center !important;
margin: 0px 197px 103px 531px;
}
use media queries to reduce the font sizes on small screens
https://www.w3schools.com/css/css_rwd_mediaqueries.asp

scaling an HTML layout

Let's say I have an html div (or some such element) featuring miscellaneous nested elements. I want to be able to design my layout using pixel positioning and pixel sizes (not percentages) and then scale up the resulting UI to fit the screen (while maintaining its aspect ratio).
So my question is how can I scale up an arbitrary html element and it's children while maintaining their layout?
Here's an example of a UI that I might want to scale up: http://jsfiddle.net/8dodovmn/2/
<div id="myUI" style="width:400px; height:300px; background-color:blue; position:relative;">
<div style="border:1px solid red; position:absolute;left:100px; top: 100px; width:100px; height:100px; text-align:center;">
<button style="height:50px; margin-top:20px;">Submit</button>
</div>
</div>
A CSS scale transform seemed like a good idea, but it doesn't work:
http://jsfiddle.net/Lqozzpmg/1/ The layout of the elements is not preserved.
#myUI
{
-webkit-transform: scale(2); /* Doesn't work, though it seems like it should. Layout of nested elements is not maintained */
}
Try adding a containing element so the #myUI element can be positioned in relation to it, then change your CSS a tiny bit. See fiddle here or text below
HTML
<div id="box">
<div id="myUI" style="width:400px; height:300px; background-color:blue; position:relative;">
<div style="border:1px solid red; position:absolute;left:100px; top: 100px; width:100px; height:100px; text-align:center;">
<button style="height:50px; margin-top:20px;">Submit</button>
</div>
</div>
</div>
CSS CODE
#box {
width:50vw;
height:50vh;
text-align:center;
}
#myUI {
transform: translateY(-50%);
-webkit-transform:translateY(-50%);
top:50%;
transform: scale(2);
/* Doesn't work, though it seems like it should. Layout of nested elements is not maintained */
transform-origin: 0%;
}
As you may imagine, the #box size is for demo purposes, you can use anything you want. You don't need to use viewport sizes either, I just used them just to show a not so commonly used CSS measure, but again, use what you like

How to make a liquid, centered, image with a caption overlay?

I'm trying with CSS to display an image centered with a caption overlay, and a liquid capability when the browser window is too small (shrink to fit).
My current best attempt looks like the following HTML (using Google's logo as sample image)
<div align="center">
<div class="container">
<img src="http://www.google.fr/images/logos/ps_logo2.png" class="picture" />
<h3 class="caption">Image Caption</h3>
</div>
</div>
with the following CSS
.container {
position : relative;
max-width : 364px;
}
.picture {
border-radius:0.5em;
box-shadow: 0px 0px 0.5em #000000;
max-width:364px;
}
.caption {
position:absolute;
padding:0.25em;
top:1em; left:0; right:0;
color:black;
background-color:rgba(0,0,0,0.2);
text-align:center;
}
However, if it behaves centered as I want it to be for large browser windows, it doesn't shrink for small browser windows...
Also I don't need IE support, a WebKit-specific (iPhone/Android) would be enough, and I would like to avoid JavaScript if possible.
JSFiddle ready-to play with version http://jsfiddle.net/kWH3C/1/
Just set the max-width to the container instead of the image and tell the image to be width:100%
http://jsfiddle.net/Madmartigan/kWH3C/5/
<div class="container">
<img src="http://www.google.fr/images/logos/ps_logo2.png" class="picture" />
<h3 class="caption">Image Caption</h3>
</div>
.container {
position : relative;
max-width : 364px;
margin:0 auto;
}
.picture {
border-radius:0.5em;
box-shadow: 0px 0px 0.5em #000000;
width:100%;
}
.caption {
position:absolute;
padding:0.25em;
top:1em; left:0; right:0;
color:black;
background-color:rgba(0,0,0,0.2);
text-align:center;
}
You don't need the outer div, and align="center" is deprecated in HTML5, use CSS for alignment and positioning.

Transparent box (div) with images(as links) -- proportionally resizable?

This is actually a two part question. so I have this transparent div element floating over a background image, what I want is to have images(as links) inside the box. But not transparent. I have the transparent box but I can't seem to figure out how to make the contents not transparent, because I would also like those images(as links) within the box to scale proportionally to the web browser. my css so far is this:
#menu
{
position:absolute;
top:13%;
left:3%;
width:25%;
height:20%;
background-color:#ffffff;
filter:alpha(opacity=60);
opacity:0.6;
-moz-opacity:0.6;
-khtml-opacity: 0.6;
}
#work img
{
position:absolute;
margin: 2% 29%;
height:33%;
}
#infocontact img
{
position:absolute;
margin: 33% 29%;
height:33%;
}
#store img
{
position:absolute;
margin: 66% 29%;
height:33%;
}
and my html is this
<div id="menu">
<div id="work">
<img src="work.gif" /> </div>
<div id="infocontact">
<img src="info.gif" />
</div>
<div id="store">
<img src="store.gif" /></div>
</div>
so what I have now is those gif images scaling with the height (and subsequent width) of the browser. and what im trying to do is have those images scale with the scale of the box as well. so if for some reason you make the browser pretty small, the images dont stick out past the smaller transparent box.
i know its gotta be possible, i just cant figure out the right combination of css/html to make it work.
The CSS:
.pic1
{
position:absolute;
width:10%;
thisistheexactwidthofitscontaineralwaysinpercentmax-width:110px;
}
img.scaled,.scaled
{
width:100%;
}
The HTML:
<div class="pic1"><img class="scaled" src="images/yourpic.png" alt="" title="">
</div>
Give the image a higher zindex than its container and apply the link to the image, not the container.
Also, for scalable images, use the width attribute. Assign the width of the container in respect to its position in the flow of your page, and the img and .scale width to 100%.
You may have to play with the size of the container to get it proportional, but it's a query free solution and works well except for scaling down png images with transparent backgrounds.

Resources