padding
is magic that creates internal proportions . Because we set the padding in percent based on the width of the parent block..wrapper-with-intrinsic-ratio {
position: relative;
padding-bottom: 20%;
height: 0;
}
.element-to-stretch {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: teal;
}
* This source code was highlighted with Source Code Highlighter .
.wrapper-with-intrinsic-ratio
.position: relative
position: relative
all child elements will be positioned relative to this container.padding-bottom: 20%
padding
makes the block height equal to 20% of its width.padding-bottom
, not padding-top
. This is because IE5 removes the “space” created with padding-top
from the stream. In other words, using padding-top: 20%
will create the layout that we want, but the block will behave as an absolutely positioned element, overlapping the following elements in the stream.height: 0
.element-to-stretch
rule.position: absolute
top: 0
top: 0
to place the block at the top of its parent.left: 0
width: 100%
width: 100%
stretches the block to the full width of its container.height: 100%
background: teal
padding
to display the video in wide format (16: 9).#containingBlock {
width: 50%;
}
.videoWrapper {
position: relative;
padding-bottom: 56.25%;
padding-top: 25px;
height: 0;
}
object,
embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
* This source code was highlighted with Source Code Highlighter .
#containingBlock
selectorwidth: 50%
body
element..videoWrapper
selector.padding-bottom: 56.25%
padding-top: 25px
padding-top
, not height
to create space for the control panel.object, embed
selector, because some browsers use object
(for example, Safari), others embed
(for example, Firefox).embed
.#containingBlock {
width: 50%;
}
.videoWrapper {
position: relative;
padding-top: 25px;
padding-bottom: 56.25%;
height: 0;
}
* html .videoWrapper {
margin-bottom: 45px;
margin-bot\tom: 0;
}
.videoWrapper div,
.videoWrapper embed,
.videoWrapper object {
position:absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
}
* This source code was highlighted with Source Code Highlighter .
.videoWrapper
selector.height: 0
* html .videoWrapper
. The so-called “star hack”, This selector only works for IE6 and below, so only these versions will process the following declarations:margin-bottom: 45px
padding
creates some problems in IE5. Here we use an arbitrary value (which should work with different control panels) as compensation for “space” we lose the ability to use padding-top
. This is necessary to prevent the overlay of the video on the following elements.margin-bottom: 0
style
the document header..videoWrapper div
selector is an additional wrapper that we need to do for Internet Explorer versions 5, 6 and 7..videoWrapper div, .videoWrapper embed
and .videoWrapper object {}
instead of .videoWrapper * {}
to prevent other content from being .videoWrapper * {}
.padding-top
ad from the previous rules and attach the yoke to the classes. Thus, we can easily style videos with different proportions and / or control panels. Example 5#containingBlock {
width: 50%;
}
.videoWrapper {
position: relative;
height: 0;
}
* html .videoWrapper {
margin-bottom: 45px;
margin-bot\tom: 0;
}
.videoWrapper div,
.videoWrapper embed,
.videoWrapper object {
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
}
.wideScreen {
padding-bottom: 56.25%;
}
.fourBYthree {
padding-bottom: 75%;
}
.chrome_25 {
padding-top: 25px;
}
.chrome_35 {
padding-top: 35px;
}
* This source code was highlighted with Source Code Highlighter .
.wideScreen
..wideScreen
.fourBYthree
.chrome_25
.chrome_35
embed
elements ).& amp;
". Then, we implement the single object method . Unlike the method of nested objects , this technology provides the browser with a single object, as the code sample below shows. Example 6< div id ="containingBlock" >
< div class ="videoWrapper" >
< div >
<!--[if IE]>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="480" height="295">
<param name="movie" value="http://www.youtube.com/v/mDRYnaajUcY&hl=en&fs=1&showinfo=0" />
<![endif]-->
<!--[if !IE]>-->
< object type ="application/x-shockwave-flash" data ="http://www.youtube.com/v/mDRYnaajUcY&hl=en&fs=1&showinfo=0" width ="480" height ="295" >
<!--<![endif]-->
< param name ="quality" value ="high" />
< param name ="wmode" value ="opaque" />
< p >< a href ="http://www.adobe.com/go/getflashplayer" >< img alt ="Get Adobe Flash player" src ="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" /></ a ></ p >
</ object >
</ div >
</ div >
...
</ div >
* This source code was highlighted with Source Code Highlighter .
<object>
, and not in two <object>
and </object>
.< div id ="containingBlock" >
< div class ="videoWrapper" >
< div >
<!--[if IE]>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="480" height="295">
<param name="movie" value="http://www.youtube.com/v/mDRYnaajUcY&hl=en&fs=1&showinfo=0" />
<![endif]-->
<!--[if !IE]>-->
< object type ="application/x-shockwave-flash" data ="http://www.youtube.com/v/mDRYnaajUcY&hl=en&fs=1&showinfo=0" width ="480" height ="295" >
<!--<![endif]-->
< param name ="quality" value ="high" />
< param name ="wmode" value ="opaque" />
< p >< a href ="http://www.adobe.com/go/getflashplayer" > < img alt ="Get Adobe Flash player" src ="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" ></ a ></ p >
</ object >
</ div >
< p > The following is the description of the video embeded in this document. </ p >
< p > This short clip is about YouTube widescreen formatting. It shows the two main formats (16:9, 4:3) and also explains the best way to create a Flash movie according to the new widescreen format. </ p >
</ div >
...
</ div >
* This source code was highlighted with Source Code Highlighter .
.videoWrapper
class, as well as add a wrapper if necessary for IE. Example 8em
.n.innerHTML = this .getSWFHTML();
* This source code was highlighted with Source Code Highlighter .
n.className += " videoWrapper" ;
if ( typeof document .documentElement.style.zoom != "undefined" ){
var wrapper4ie = document .createElement( "div" );
n.appendChild(wrapper4ie);
wrapper4ie.innerHTML = this .getSWFHTML();
} else {
n.innerHTML = this .getSWFHTML();
};
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/62178/
All Articles