CSS: center video behind div without affecting overall div layout? - html

I have a page with multiple divs. They've all been sized and positioned according to various criteria.
[div1]
[div2]
[div3]
Now there's been a request to place a video (of a set width/height) behind one of the divs.
[div1]
[div2 - now with background video]
[div3]
How can I do this without affecting the existing layout in any way?
Here's a fiddle with the starting point for what I'm trying to do:
https://jsfiddle.net/gzdjL8kx/
I want the blue box (which represents the video) to remain centered (vertically and horizontally) behind the yellow box, without affecting the layout of the yellow/red/orange boxes at all, and in such a way that the layout of the yellow/red/orange boxes can be changed and the blue box's position will adapt so that it remains centered behind yellow. The blue box should also remain centered even if its width/height is changed.
Given that fiddle, here's my desired outcome, but I don't know how to achieve it:
https://i.imgur.com/k0S8WNF.png
Basically I want the blue box to be able to be positioned relative to the yellow box without affecting the other boxes at all. All my attempts to center it so far end ultimately up bumping the other boxes around too.

If you use position:absolute; on your video you'll remove it from the document flow, which stops it influencing the position of other relatively positioned divs.
If you're aiming for a lightbox style popup for your video you can centre it in the viewport using the following:
.yellow
{
width:250px;
height:150px;
margin:auto;
background-color:yellow;
position:relative;
}
.orange
{
width:500px;
height:100px;
margin:auto;
background-color:orange;
}
.red
{
width:100%;
height:150px;
background-color:red;
}
.blue
{
width:320px;
height:240px;
background-color:blue;
position:absolute;
top:50%;
left:50%;
transform:translate(-50%, -50%);
}
<div class="orange">
</div>
<div class="yellow">
<div class="blue"></div>
</div>
<div class="red">
</div>

Related

Animate background-image CSS

I have a parent div, which contains two other Divs and I'm looking to animate the background-image of the parent div so that it constantly scrolls along the x-axis. The image is 3840px wide and the div is 100% of the browser (1920px). Essentially the image needs to repeatedly scroll whilst not impacting upon the child elements within the parent div, is this possible?
Here is my HTML
<div id="SliderBackground">
<div id="SliderBanner"></div>
<div id="SliderStaticImage"></div>
</div>
Here is my CSS
#SliderBackground
{
width:100%; /*1920px*/
height:500px;
background-image:url(Background.png);
z-index:-1;
position:absolute;
top:90px;
}
Thankyou in advance.

Vertically align text as middle in span/label irrespective of screen resolution not working

I am able to vertically align text in span(which is inside div) but i need my page to be independent of screen resolution. have used line height feature to curb the my text from going out of the div when I change the resolution..but I see its not vertically aligned as middle in all resolution. what feature in css i should look into?
<div>
<span style="width:49%; height:50%; top:25%; left:0%; line-height:50%;font-size:x-small;font-family:Verdana;font-weight:bold; position:absolute; display:block;">
Random Text
</span>
</div>
The above span tag is inside a div. Also What should be the recommended value of line-height.Should it be same as height of the span tag?
I saw this link for understanding the vertical aligning of single line text.
>
Some other CSS doubts>>
1. a textbox inside a div containing single line of text also goes out of the control while changing screen resolution. what could I possibly do to solve this?I am about to control it in a button
Remove those position unless extremely needed and use, display:table-cell
Fiddle Demo
div span {
border:1px solid red;
width:49%;
height:50%;
display:table-cell; /*check this */
vertical-align:middle; /**aligns where you want it */
font-size:x-small;
font-family:Verdana;
font-weight:bold;
}
You might wanna check out this thread too : Align multiple divs in one line and center text veticaly and horizontally
You could position the span element vertically at the middle by using top: 50% and adding a negative top margin which is equal to half of the height of the line.
Here you go:
EXAMPLE HERE
span {
position:absolute;
top: 50%; left:0;
font-size: 0.7em;
line-height: 100%; /* 100% of font-size */
margin-top: -0.35em;
}
However if you're not eager to use absolute positioning, you could follow this approach.
Note: I've nothing against table-cells, except the effect relative positioning is undefined for such types of elements. If you don't mind, you could follow #NoobEditor's solution as well.

Gmail home page css

I'm more of a programmer than a web designer, I am trying to do a simple (I think) design like the home page of gmail https://mail.google.com/intl/fr/mail/help/about.html
I have a div in the center of my screen with a overflow:hidden so the background image don't resize.
In that div, I have 2 other div, one at the left and one at the right, the probleme is, since the main div is overflow:hidden when i shrink the page the right div is not visible anymore.
You can see a demo here : http://jsfiddle.net/e7MMQ/
first of all the background has nothing to do with div overflow , you could just use
background-attachment:fixed;
and for you divs
just use float : left; and float : right ;
if this what you are trying to do :
http://jsfiddle.net/prollygeek/e7MMQ/1/
it is because you have specified a width , and your div is still there but you to scroll to right to see it.
You can try applying overflow:hidden in your left/right divs and make them fixed. Thats assuming you dont have any content inside the larger container and everything is in the left/right div.
Then make your larger container a fixed size that is the combined size of your left/right divs.
HTML:
<div id="container">
<div id="left">Some content</div>
<div id="right">Some other content</div>
</div>
CSS:
#container{
width:300px;
height:300px;
}
#left{
float:left;
width:150px;
height:300px;
overflow:hidden;
}
#right{
float:right;
width:150px;
height:300px;
overflow:hidden;
}
Hope that helps!

Two Stacked divs and controlling heights

I am trying to stack two divs A and B.
Div A - will be scrollable but its height needs to be determined by the div underneath it, Div B so if the content in Div B changes, and it's height changes the height of Div A also changes.
Div B - needs to be aligned to the bottom of page on top of a absolute positioned footer. Its content needs to be aligned to the bottom.
I've tried using position relative and float by wrapping these divs in a wrapper, but the whole thing breaks when I try to keep the Div B aligned or positioned absolutely above the footer.
I've got a feeling this needs to go back to basics, any help would be greatly appreciated
thanks
Here's a basic example. I think I have correctly understood your requirement. This example has them appear to be stacked but in the HTML they are not actually stacked, they are nested. I wasn't sure if you could allow that in your solution but fingers crossed.
Example: http://jsfiddle.net/jyR2A/1/
CSS:
#divA {overflow-y:scroll;position:absolute;height:100%;top:-100%;background:green;width:100%;}
#divB {position:absolute;bottom:0;background:blue;width:100%;color:white;}
HTML:
<div id="divB">
<!-- Div A is nested so we can use divB's height -->
<div id="divA">
</div>
<!-- Div B content -->
<div id="divBinnerContent">
Line 1 <br />
Line 2 <br />
..Keep adding more lines to test how it works <br />
</div>
</div>
How it works:
divB is the parent element defining the height of divA. So if we set divB position relative or absolute and place divA inside then we can set divA's height to 100% to give it the height of parent element divB.
Now to position divA we make sure it has position:absolute and set top:-100% which will move it up the same distance as the height of its container divB. Position absolute not only allows us to position it correctly but it also removes it from affecting the height of its parent, divB.
And the content for divB I have made a nice container for it but it is not neccessary. Simply put it anywhere inside divB (but not inside divA) and it will be OK.
You can use the content to define the height,as I have, or use an absolute height set in CSS.
Hope this is what you were after.
Le-roy
I managed to achieve this with help from this question and fiddle.
Stack div elements in css vertically (with dynamic height)
http://jsfiddle.net/nCrEc/334/
Essentially the answer was giving my Div A a height without using the height parameter but instead using absolute positioning on top and bottom. Which meant changes to Div B changed the location of the Div A's bottom (oo er) which pushed the middle div up whenever another populates the bottom area.
<div class="con">
<div class="top"></div>
<div class="middle"></div>
<div class="bottom"></div>
</div>
then using this CSS
.con {
width:200px;
top:50px;
bottom:0;
left:0;
position:absolute;
background:#ff0;
}
.top {
width:200px;
height:20px;
position:absolute;
top:0;
left:0;
background:#f60;
}
.bottom {
width:200px;
height:50px;
position:absolute;
bottom:0;
left:0;
background:#f60;
}
.middle {
overflow-y:auto;
min-height:1px;
position:absolute;
bottom:50px;
top:20px;
left:0;
background:#06f;
}

Two divs, one inside the other. Parent scrollable. Child fixed.

I have two divs I want to place one inside the other. The parent div has height 100% and is x-scrollable (the content will overflow to the right).
The child div has a repeatable background image set through css.
I want to place it at the bottom of the parent div (above the scrollbar), like a footer but when the scroll is moved this div should stay still.
How can this be done?
Right now I have
.parent{
overflow-x:scroll;
overflow-y:hidden;
width:100%;
height:100%;
position:fixed; }
.child{
height:33px;
width:100%;
bottom:0;
left:0;
background-image:url(<image_path>);
background-repeat:repeat-x;
position:absolute;}
<div class="parent">
<div class="child">
</div>
</div>
The problem I'm having is that the child div moves when scrolling the parent div.
Thanks.
You don't really need the child div unless there's some other content there in addition to the background image. You could do it all in the parent div.
JSBin Demo -------> HERE
After your fiddle... an edit... Forget the background of the child div. Place the background image on the parent div. let the child div be transparent and contain the text.
Updated Fiddle --------> HERE