Responsive Images & Video

by diaryfakta

HTML

<h1>Demo: CSS Tricks for Responsive Design</h1>
<p>Tutorial by <a href="http://twitter.com/nickla">Nick La</a>, <a href="http://webdesignerwall.com">Web Designer Wall</a> (<a href="http://webdesignerwall.com/tutorials/5-useful-css-tricks-for-responsive-design">related article</a>)</p>

<h3>Responsive Video</h3>
<div class="video">
    <iframe src="http://player.vimeo.com/video/6929537" width="978" height="550" frameborder="0"></iframe>
</div>

<h3>Min Max Width</h3>

<h4>Max Width Container</h4>
<div class="container">
    .container { <br>
        width:700px;<br> 
        max-width:90%;<br>
    }
</div>

<h4>Responsive Image</h4>
<figure>
    <img src="http://webdesignerwall.com/demo/responsive-css-tricks/images/koi.jpg" alt="koi">
</figure>

<h4>Min-Width</h4>
<form>
    <p><input type="text"><label>Input</label></p>
    <p><textarea></textarea></p>
</form>

<h3>Relative Value</h3>
    
<h4>Relative Margin</h4>
<ul class="commentlist">
    <li>
        <img src="http://webdesignerwall.com/demo/responsive-css-tricks/images/1.jpg" alt="1">
        <div class="comment-text">
            <cite>Comment</cite>
            <p>Cras ultricies cursus nisl, eget congue tellus consequat nec. Cras id nibh neque, eu dignissim orci. Aenean at adipiscing urna. Suspendisse potenti. Suspendisse vitae tellus a neque commodo rutrum. Praesent ac neque vitae massa pharetra pellentesque.</p>
        </div>

        <ul>
            <li>
                <img src="http://webdesignerwall.com/demo/responsive-css-tricks/images/2.jpg" alt="2">
                <div class="comment-text">
                    <cite>Comment</cite>
                    <p>Cras ultricies cursus nisl, eget congue tellus consequat nec. Cras id nibh neque, eu dignissim orci. Aenean at adipiscing urna. Suspendisse potenti. Suspendisse vitae tellus a neque commodo rutrum. Praesent ac neque vitae massa pharetra pellentesque.</p>
                </div>
                
                <ul>
                    <li>
     ...

CSS

body {
    font: .8em/150% Arial, Helvetica, sans-serif;
    color: #666;
    width: 850px;
    margin: 20px auto;
    max-width: 90%;
}
a {
    color: #66C;
}
p {
    margin: 0 0 1em;
}
h1, h2, h3, h4 {
    color: #000;
}
h1 {
    font: 1.7em;
    line-height: 110%;
}
h3 {
    font-size: 1.5em;
    line-height: 120%;
    margin: 30px 0 20px;
    padding-top: 20px;
    border-top: double 3px #eee;
}
h4 {
    font-size: 1.2em;
    line-height: 120%;
    margin: 30px 0 10px;
    text-transform: uppercase;
}

figure {
    margin: 0;
}


/* html5 elements */
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { 
    display: block;
}

/************************************************************************************
RESPONSIVE VIDEO
*************************************************************************************/
.video {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
}
.video iframe,  
.video object,  
.video embed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/************************************************************************************
MIN & MAX WIDTH
*************************************************************************************/
/* max width container */
.container {
    width: 700px;
    max-width: 90%;

    margin: 0 auto;
    background: #eee;
    border: solid 1px #ddd;
    height: 200px;
}

/* responsive image */
img {
    max-width: 100%;
    height: auto;
}
@media \0screen {
  img { 
      width: auto; /* for ie 8 */
  }
}

/* form */
input[type="text"], textarea {
    background: #eee;
    border: solid 1px #ddd;
    padding: 8px 5px;    
}
input[type="text"] {
    width: 400px;
    min-width: 140px;
    max-width: 40%;
    margin-right: 10px;
}
textarea {
    width: 96%;
    height: 180px;
}

/************************************************************************************
RELATIVE...