Search notes:

CSS Snippets

/2D/scale.html

<!DOCTYPE html>
<html>
<head>
  <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  <title>scale</title>

  <style type='text/css'> 

    body {
      margin: 0;
    }

    #parent {
      position: absolute;
      left: 100px;   /*  Note: Element borders body's border although */
      top: 100px;    /*  left and top are set to 100 px */
      width: 200px;
      height: 200px;
      transform: scale(2);
      border: DarkBlue 1px solid;
      background-color: DodgerBlue;

    }

    #child {
      position: absolute;
      top: 50px;
      left: 50px;
      transform: translate(50px, 50px);
      width: 100px;
      height: 100px;
      border: orange 1px solid;
      background-color: yellow;

    }
     

  </style>

</head>
<body>

  <div id='parent'>
     <div id='child'></div>
  </div>

</body>
</html>
Github repository about-css, path: /2D/scale.html

/3D/perspective.html

<!DOCTYPE html>
<html>
<head>
  <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  <title>perspective</title>

  <style type='text/css'> 

    .col_1 {transform: rotateX(15deg); left:  20px}
    .col_2 {transform: rotateX(45deg); left: 340px}
    .col_3 {transform: rotateX(75deg); left: 660px}

    .row_1 {top:  20px}
    .row_2 {top: 340px}
    .row_3 {top: 660px}

    div:not(.persp) {
      background-color: #ffaa33;
      position: absolute;
      width:  300px;
      height: 300px;

      font-size: 140px;
      text-align: center;
      line-height: 300px; /* http://stackoverflow.com/a/8865463/180275 */
    }

    .persp {

      perspective: 1000px;

    }

  </style>

</head>
<body>

<div class='persp'>
  <div class='row_1 col_1'>1/1</div> <div class='row_1 col_2'>1/2</div> <div class='row_1 col_3'>1/3</div>
  <div class='row_2 col_1'>2/1</div> <div class='row_2 col_2'>2/2</div> <div class='row_2 col_3'>2/3</div>
  <div class='row_3 col_1'>3/1</div> <div class='row_3 col_2'>3/2</div> <div class='row_3 col_3'>3/3</div>
</div>
  


</body>
</html>

Github repository about-css, path: /3D/perspective.html

/examples/align-decimal-point.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><!--{-->
  <title>Align on decimal point</title>
  <style type='text/css'> 
    .price {white-space:pre;font-family:courier}
  </style>
</head><!--}-->
<body>

<table summary='Aligned'>

  <tr><td>Soap      </td><td class='price'>   4.95 </td></tr>
  <tr><td>Toothpaste</td><td class='price'>   5.-- </td></tr>
  <tr><td>Pen       </td><td class='price'>  20.-- </td></tr>

</table>

<p>
  See also 
  <a href='http://krijnhoetmer.nl/stuff/javascript/table-align-char/'>http://krijnhoetmer.nl/stuff/javascript/table-align-char/</a>

</body>
</html>

Github repository about-css, path: /examples/align-decimal-point.html

/examples/link_color.html

<!DOCTYPE html>
<html>
<head><!--{-->

  <title>Link colors</title>

  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <!-- HTML5 (?) <meta charset="utf-8"> -->

   <!--{--><style type='text/css'>



   /* Note the ordering

      Remember them with
      Link
      o
      Visited
      e

      Hover
      Active
      t
      e
    
    */

   a:link     { color: #4499ff; }
   a:visited  { color: #33aa22; }
   a:hover    { color: #ff0077; }
   a:active   { color: #ffff00; }

   a {font-size: 50px};

   </style><!--}-->

</head><!--}-->
<body><!--{-->

  <a href='file://link_color.html'>link_color.html</a><br>
  <a href='http://renenyffenegger.ch'>renenyffenegger.ch</a><br>
  <a href='javascript:alert("hi");'>Say hi</a><br>
  <a href='http://google.com'>google.com</a>

</body><!--}-->
</html>
Github repository about-css, path: /examples/link_color.html

/line-breaking/prevent-line-break.html

<!DOCTYPE html>
<html>
<head>
  <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  <title>display:inline-block</title>

  <style type='text/css'> 
      tr    { vertical-align: top; }
	    table { width: 50em;}

      .nobreak {white-space: nowrap;}
  </style>
</head>
<body>


  <table>
    <tr>
      <td>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.</td>
      <td>/usr/local/share/foo/bar.txt</td>
    </tr>
  </table>

  <table>
    <tr>
      <td>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.</td>
      <td class='nobreak'>/usr/local/share/foo/bar.txt</td>
    </tr>
  </table>

  <hr>

   See also <a href='../properties/white-space.html'>The whitespace property</a>
    

</body>
</html>
Github repository about-css, path: /line-breaking/prevent-line-break.html

/positioning/margin_0_auto.html

<!DOCTYPE html>
<html>
<head>

  <title>margin 0 auto</title>

  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

   <style type='text/css'>

     body {
       margin: 0;
     }

     .center {
       background-color:#adf;
       border:black solid 1px;
       margin: 0 auto;
       width:500px;
       height:400px;
     }

   </style>

</head>
<body>

  <div class='center'>centered (<code>margin: 0 auto</code>)</div>

  <div style='height: 600px; width: 600px; background-color:#ef2'>
    <div class='center'>centered within yellow (<code>marging: 0 auto</code>)</div>
  </div>

</body>
</html>
Github repository about-css, path: /positioning/margin_0_auto.html

/positioning/table_like_divs.html

<!DOCTYPE html>
<html>
<head>

  <title>3 horizontal divs</title>

  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

   <!--{--><style type='text/css'>

     body {
       margin: 0;
       height:10000px;
       background-color: #112;
     }

    #main{
        position     :fixed;
        display      :table;
        width        :100%;
        top          : 10%;
        margin-bottom:100px;
        height       : 50%;
    }

    #row{
        display:table-row;
    }

    #row div{
        display:table-cell;
        width: 33%;
    }
    
    #left {
        background:#f70;
    }

    #middle {
        background:#31a;
        width:33%;
        margin:auto;
    }

    #right {
        width: 33%;
        background:#feb;
    }

   </style><!--}-->
  

</head>
<body>

<div id='main'>
    <div id='row'>
        <div id='left'  ></div>
        <div id='middle'></div>
        <div id='right' ></div>
    </div>
</div>


</body>
</html>
Github repository about-css, path: /positioning/table_like_divs.html

/properties/empty-cells.html

<!DOCTYPE html>
<html>
<head>
  <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  <title>empty-cells</title>

  <style type="text/css">
    div {font-family: monospace; margin-top: 3em; margin-bottom: 1em; font-size: 20px}

    td {border: 1px solid black}

    #show-them { empty-cells: show }
    #hide-them { empty-cells: hide }

  </style>

</head>
<body>

  <div>empty-cells: show</div>

   <table summary='.' id='show-them'>
       <tr><td>foo</td><td>one  </td> </tr>
       <tr><td>bar</td><td>     </td></tr>
       <tr><td>   </td><td>three</td></tr>
      </tbody>
   </table>

  <div>empty-cells: hide</div>

   <table summary='.' id='hide-them'>
       <tr><td>foo</td><td>one  </td> </tr>
       <tr><td>bar</td><td>     </td></tr>
       <tr><td>   </td><td>three</td></tr>
      </tbody>
   </table>

</body>
</html>
Github repository about-css, path: /properties/empty-cells.html

/properties/border/radius.html

<!DOCTYPE html>
<html>
<head>
  <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  <title>border-radius</title>


</head>
<body>


  <span style='border-radius: 3px; padding: 4px; background-color: #f33; color:#fff;'>
    <b>border-radius: 3px</b>
  </span>

  <p>

  <span style='border-radius: 5px; padding: 4px; background-color: #33f; color:#fff;'>
    <b>border-radius: 5px</b>
  </span>

  <p>

  <span style='border-radius: 7px; padding: 4px; background-color: #3f3; color:#fff;'>
    <b>border-radius: 7px</b>
  </span>

</body>
</html>

Github repository about-css, path: /properties/border/radius.html

/properties/border/tr.html

<!DOCTYPE html>
<html>
<head>
  <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  <title>border</title>
  <style type="text/css">


     table#B {
       border-collapse: collapse;
     }

     tr {
       border-bottom: #2b3 4px dotted;
     }

     table {
       background-color: #f7fcf9;
     }

     td {
       padding: 0.4em;
     }

  </style>
</head>
<body>


  Two tables: both are equal except that table B has the <code>border-collapse</code> set to <code>collapse</code>.

  <h1>Table A</h1>

  Without the border-collapse property set to collapse, the <code>border-bottom</code> property of <code>tr</code> elements is not applied:

  <table id='A'>
    <tr>
      <td>foo</td><td>bar</td><td>baz</td>
    </tr><tr>
      <td>one</td><td>two</td><td>three</td>
    </tr>
  </table>

  <h1>Table B</h1>

  Yet, with the border-collapse property set to collapse, the <code>border-bottom</code> property of <code>tr</code> elements is applied:

  <table id='B'>
    <tr>
      <td>foo</td><td>bar</td><td>baz</td>
    </tr><tr>
      <td>one</td><td>two</td><td>three</td>
    </tr>
  </table>

  <hr>
    See also <a href='collapse.html'>border-collapse</a>

</body>
</html>
Github repository about-css, path: /properties/border/tr.html

/properties/css3-tranformations/rotate.html

<!DOCTYPE html>
<html>
<head>
  <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  <title>rotate</title>

  <style type="text/css">

    
    .rotated {
       position: absolute;
       left: 200px;
       top: 200px;
       font-size:100px;
    }

    #deg_60 {
     -webkit-transform: rotate(60deg); /* Chrome?  */
        -moz-transform: rotate(60deg); /* Firefox  */
         -ms-transform: rotate(60deg); /* IE       */
          -o-transform: rotate(60deg); /* Opera    */
      color: red;
    }

    #deg_150 {
     -webkit-transform: rotate(150deg);
        -moz-transform: rotate(150deg);
         -ms-transform: rotate(150deg);
          -o-transform: rotate(150deg);
      color: blue;
    }

  </style>

</head>
<body>

  <div class='rotated' id='deg_60'>60 degrees</div>
  <div class='rotated' id='deg_150'>150 degrees</div>

</body>
</html>

Github repository about-css, path: /properties/css3-tranformations/rotate.html

/stacking_order/position/test_01.html

<!DOCTYPE html>
<html>
<head>
  <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  <title>Test 01</title>

  <link rel="stylesheet" type="text/css" href="test_x.css">

  <style type='text/css'> 


    img {
      position: absolute;
      top: 0px;
      left: 0px;
    }

    #qrst {
      font-size: 200px;
      color: red;
      font-family: sans-serif;
    }
    

  
  </style>

</head>
<body>

<div id='qrst'>
Q R<br>
S T
</div>

<img src="image_200x200.png" />

<div id='text'>
  The image has <code>position: absolute</code>.
  <br>The text does not have any position absolute.
  <br>The text is behind the image:
     when the <code>div</code>
     comes before the <div>img</div> (this page) or after (<a href='test_02.html'>test_02.html</a>).
    <br>See also <a href='test_03.html'>test_03.html</a> and <a href='test_04.html'>test_04.html</a>
</div>


</body>
</html>

Github repository about-css, path: /stacking_order/position/test_01.html

/stacking_order/position/test_02.html

<!DOCTYPE html>
<html>
<head>
  <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  <title>Test 02</title>

  <link rel="stylesheet" type="text/css" href="test_x.css">

  <style type='text/css'> 


    img {
      position: absolute;
      top: 0px;
      left: 0px;
    }

    #qrst {
      font-size: 200px;
      color: red;
      font-family: sans-serif;
    }
    

  
  </style>

</head>
<body>


<img src="image_200x200.png" />

<div id='qrst'>
Q R<br>
S T
</div>

<div id='text'>
  The image has <code>position: absolute</code>.
  <br>The text does not have any position absolute.
  <br>The text is behind the image:
     when the <code>div</code>
     comes after the <div>img</div> (this page) or before (<a href='test_01.html'>test_01.html</a>).
    <br>See also <a href='test_03.html'>test_03.html</a> and <a href='test_04.html'>test_04.html</a>
</div>


</body>
</html>

Github repository about-css, path: /stacking_order/position/test_02.html

/stacking_order/position/test_03.html

<!DOCTYPE html>
<html>
<head>
  <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  <title>Test 03</title>

  <link rel="stylesheet" type="text/css" href="test_x.css">

  <style type='text/css'> 


    img {
      position: absolute;
      top: 0px;
      left: 0px;
    }

    #qrst {
      top: 0px;
      left: 0px;
      position: absolute;
      font-size: 200px;
      color: red;
      font-family: sans-serif;
    }
    

  
  </style>

</head>
<body>

<div id='qrst'>
Q R<br>
S T
</div>

<img src="image_200x200.png" />

<div id='text'>
  The image <b>and</b> the div both have <code>position: absolute</code>.
  <br>The text is behind the image when the div is placed before the image (this page).
  <br>When the div is placed after the image, it's put above the image (<a href='test_04.html'>test_04.html</a>).
    <br>See also <a href='test_01.html'>test_01.html</a> and <a href='test_02.html'>test_02.html</a>
</div>


</body>
</html>

Github repository about-css, path: /stacking_order/position/test_03.html

/stacking_order/position/test_04.html

<!DOCTYPE html>
<html>
<head>
  <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  <title>Test 04</title>

  <link rel="stylesheet" type="text/css" href="test_x.css">

  <style type='text/css'> 


    img {
      position: absolute;
      top: 0px;
      left: 0px;
    }

    #qrst {
      position: absolute;
      top: 0px;
      left: 0px;
      font-size: 200px;
      color: red;
      font-family: sans-serif;
    }
    

  
  </style>

</head>
<body>


<img src="image_200x200.png" />

<div id='qrst'>
Q R<br>
S T
</div>

<div id='text'>
  The image <b>and</b> the div both have <code>position: absolute</code>.
  <br>The text is above the image when the div is placed after the image (this page).
  <br> When the div is placed before the image, it's put behind the image (<a href='test_03.html'>test_03.html</a>).
    <br>See also <a href='test_01.html'>test_01.html</a> and <a href='test_02.html'>test_02.html</a>
</div>


</body>
</html>

Github repository about-css, path: /stacking_order/position/test_04.html

/tables/borders-of-adjacent-tds.html

<!DOCTYPE html>
<html>
<head>
  <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  <title>Borders of adjacent TDs</title>

   <style type="text/css">

     table {border: 1px solid grey}

     .tabcollapse    {border-collapse: collapse;}
     .tabseparate    {border-collapse: separate;}
     .borderspacing0 {border-collapse: separate; border-spacing: 0;}

     .foo {border: red   7px solid}
     .bar {border: blue  7px solid}
     .baz {border: #6f6  7px solid}

   </style>
</head>
<body>


  <table class='tabcollapse'>
    <tr>
      <td colspan='3'>Table with <code>border-collapse: collapse</code></td>
    </tr>
    <tr>
      <td class='foo'>Foo</td>
      <td class='bar'>Bar</td>
      <td class='baz'>Baz</td>
    </tr>
  </table>

  <p>

  <table class='tabseparate'>
    <tr>
      <td colspan='3'>Table with <code>border-collapse: separate</code></td>
    </tr>
    <tr>
      <td class='foo'>Foo</td>
      <td class='bar'>Bar</td>
      <td class='baz'>Baz</td>
    </tr>
  </table>

  <p>

  <table class='borderspacing0'>
    <tr>
      <td colspan='3'>Table with <code>border-collapse: separate</code> and <code>border-spacing: 0</code></td>
    </tr>
    <tr>
      <td class='foo'>Foo</td>
      <td class='bar'>Bar</td>
      <td class='baz'>Baz</td>
    </tr>
  </table>

</body>
</html>
Github repository about-css, path: /tables/borders-of-adjacent-tds.html

/transition/transition-duration.html

<!DOCTYPE html>
<html>
<head>
  <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  <title>transition-duration</title>

<script type="text/javascript"><!--{-->

var rect, out_x, out_y, out_c;
function main() {

  var $ = function(id) {return document.getElementById(id);};

  rect  = $('rect');
  out_x = $('out_x');
  out_y = $('out_y');
  out_c = $('out_c');
  update_out();
}

function set_x(x) {
  rect.style.left = x + 'px';
}
function set_y(y) {
  rect.style.top = y + 'px';
}
function set_color(c) {
  rect.style.backgroundColor = c;
}
function opacity(o) {
  rect.style.opacity = o;
}
function show(b) {
  if (b) {
    rect.style.visibility = 'visible';
  }
  else {
    rect.style.visibility = 'hidden';
  }
}

function $html(id, txt) {
  id.innerHTML = txt; 
}
function update_out() {

  console.log('update_out ' + rect.style.left);
  $html(out_x, rect.style.left);
  $html(out_y, rect.style.top );
  $html(out_c, rect.style.backgroundColor );

  setTimeout(update_out, 100);
}
  

</script><!--}-->
<!--{--><style type='text/css'>

#rect {

  position: absolute;

  width: 100px;
  height: 100px;
  top: 100px;
  left: 100px;
  border: 1px solid black;
  background-color: yellow;

  transition-duration: 5s;
  transition-timing-function: linear;

}

#controls {

  position: absolute;
  top: 500px;

}

</style><!--}-->

</head>
<body onload='main()'>


  <div id='rect'> </div>

  <div id='controls'>

    <table>

      <tr><td><input type='button' onclick='set_x(100)       ;' value='x=100'       ></td><td><input type='button' onclick='set_x    (300   );' value='x=300'     ></td><td id='out_x'></td></tr>
      <tr><td><input type='button' onclick='set_y(100)       ;' value='y=100'       ></td><td><input type='button' onclick='set_y    (300   );' value='y=300'     ></td><td id='out_y'></td></tr>
      <tr><td><input type='button' onclick='set_color("#f00");' value='red'         ></td><td><input type='button' onclick='set_color("#00f");' value='blue'      ></td><td id='out_c'></td></tr>
      <tr><td><input type='button' onclick='show     (true  );' value='show'        ></td><td><input type='button' onclick='show     (false );' value='hide'      ></td><td           ></td></tr>
      <tr><td><input type='button' onclick='opacity  (100   );' value='opacity 100%'></td><td><input type='button' onclick='opacity  (0     );' value='opacity 0%'></td><td           ></td></tr>

   </div>

</body>
</html>
Github repository about-css, path: /transition/transition-duration.html

See also

Centering an element on client area and on content
CSS

Index