Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

James Robertson http://www.r0bertson.co.uk

« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS 

Adding style to SVG

To reference a CSS file within an SVG file refer to the following example code.

<?xml-stylesheet href="styles_austria_1.css" type="text/css"?> 

Here's what an SVG CSS file looks like.
.str1 {stroke:#0093DD;stroke-width:16;color:#0093DD}
.str2 {stroke:#0093DD;stroke-width:12}
.str3 {stroke:#0093DD;stroke-width:10}
.str4 {stroke:#0093DD;stroke-width:6}

.str0 {stroke:#DA251D;stroke-width:55;color:#DA251D}
.str6 {stroke:#BB90BB;stroke-width:44;color:#BB90BB}
.str5 {stroke:#0093DD;stroke-width:4}
.str7 {stroke:#1F1A17;stroke-width:13}

.fil0 {fill:none}
.fil2 {fill:#1F1A17}
.fil1 {fill:#C4E5FA}
.fil3 {fill:#FFFFFF}


Source: Example for using CSS-Styles [carto.net]
Reference: Styling - SVG 1.1 - 20030114 [w3.org]

Cursor styles used in CSS

Source: Custom CSS Cursors [javascriptkit.com]
cursor: default;
cursor: hand;
cursor: pointer;
cursor: pointer; cursor: hand;
cursor: crosshair;
cursor: text;
cursor: wait;
cursor: help;
cursor: move;
cursor: e-resize;
cursor: ne-resize;
cursor: nw-resize;
cursor: n-resize;
cursor: se-resize;
cursor: sw-resize;
cursor: s-resize;
cursor: w-resize;
cursor: progress;
cursor: all-scroll;
cursor: col-resize;
cursor: no-drop;
cursor: not-allowed;
cursor: row-resize;
cursor: url(mycursor.cur); /* Note: Only .cur and .ani file types are supported as of IE6. */
cursor: vertical-text;

Adding CSS style to buttons

This HTML and CSS code shows how to customise buttons in a restful way. Source: http://particletree.com/features/rediscovering-the-button-element/
<div class="buttons">
    <button type="submit" class="positive">
        <img src="/images/icons/tick.png" alt=""/> 
        Save
    </button>

    <a href="/password/reset/">
        <img src="/images/icons/textfield_key.png" alt=""/> 
        Change Password
    </a>

    <a href="#" class="negative">
        <img src="/images/icons/cross.png" alt=""/>
        Cancel
    </a>
</div>

/* BUTTONS */

.buttons a, .buttons button{
    display:block;
    float:left;
    margin:0 7px 0 0;
    background-color:#f5f5f5;
    border:1px solid #dedede;
    border-top:1px solid #eee;
    border-left:1px solid #eee;

    font-family:"Lucida Grande", Tahoma, Arial, Verdana, sans-serif;
    font-size:100%;
    line-height:130%;
    text-decoration:none;
    font-weight:bold;
    color:#565656;
    cursor:pointer;
    padding:5px 10px 6px 7px; /* Links */
}
.buttons button{
    width:auto;
    overflow:visible;
    padding:4px 10px 3px 7px; /* IE6 */
}
.buttons button[type]{
    padding:5px 10px 5px 7px; /* Firefox */
    line-height:17px; /* Safari */
}
*:first-child+html button[type]{
    padding:4px 10px 3px 7px; /* IE7 */
}
.buttons button img, .buttons a img{
    margin:0 3px -3px 0 !important;
    padding:0;
    border:none;
    width:16px;
    height:16px;
}

Adding colour to the buttons - Colour is used like a traffic light system, green for go (positive), red for stop (negative, think about this for a moment), and blue which isn't a traffic light (neutral, a miscellaneous item)
/* STANDARD */

button:hover, .buttons a:hover{
    background-color:#dff4ff;
    border:1px solid #c2e1ef;
    color:#336699;
}
.buttons a:active{
    background-color:#6299c5;
    border:1px solid #6299c5;
    color:#fff;
}

/* POSITIVE */

button.positive, .buttons a.positive{
    color:#529214;
}
.buttons a.positive:hover, button.positive:hover{
    background-color:#E6EFC2;
    border:1px solid #C6D880;
    color:#529214;
}
.buttons a.positive:active{
    background-color:#529214;
    border:1px solid #529214;
    color:#fff;
}

/* NEGATIVE */

.buttons a.negative, button.negative{
    color:#d12f19;
}
.buttons a.negative:hover, button.negative:hover{
    background:#fbe3e4;
    border:1px solid #fbc2c4;
    color:#d12f19;
}
.buttons a.negative:active{
    background-color:#d12f19;
    border:1px solid #d12f19;
    color:#fff;
}

Keeping the new contents of a growing list in view

The purpose of this code is to demonstrate how to keep the content at the bottom of a list always in view, similar to a chat window. Keywords: div, overflow, scroll, scrolltop. Reference: scrollTop Property http://snipr.com/1wdbn [msdn2.microsoft.com]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <title>scrolling div</title>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
    
    <style type="text/css">
      <!--
      body {background-color: #43d;}
      div#list  {background-color: #4e8;  overflow: scroll; width: 15em; height: 10em;}
      p.other_user {background-color: #af5;}
      p {background-color: #ed3;}
      -->
    </style>
    <script type="text/javascript">
      function addText() {
        olist = document.getElementById('list');
        op = document.createElement('p');
        op.innerHTML = 'hi';
        ocontent = document.getElementById('content');
        ocontent.appendChild(op);
        olist.scrollTop = olist.scrollHeight;
      }
    </script>
  </head>
  <body>
    <div id="toolbar"><input type="button" value="add text" onclick="addText()" /></div>
    <p>A simple chat style display</p>
    <div id="list">
      <div id="content">
      <p class="other_user">Good <strong>afternoon</strong> how are you?</p>
      <p class="other_user">hello?</p>
      <p class="other_user">is anybody there?</p>
      </div>
    </div>    
  </body>
</html>

Slashdot's 3 column liquid layout

The following html and css code is an example of a 3 column liquid layout used on the front page of http://slashdot.org. What's interesting is that the left and right column do not change their widths, it's only the article content which changes.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <title>Aenean: ullamcorper elementum, dui quam porttitor neque</title>
  <link rel="stylesheet" type="text/css" media="screen" href="core-tidied.css" />

</head>
<body>
<div id="frame">
  <div id="topnav">
    <div id="logo">
      <h1>
        <a href="//aenean.org">Aenean</a>
      </h1>
    </div>
  </div> 
  <div id="slogan">
    <h2>
      ullamcorper elementum, dui quam porttitor neque
    </h2>
  </div>
  <div id="wrapper">
    <div id="links">
      <div class="block" id="links-sections">
        <div class="title" id="links-sections-title">
          <h4>
                  hendrerit
          </h4>
        </div>
        <div class="content" id="links-sections-content">
          <ul>
          <li>suscipit</li>
          </ul>
        </div>
      </div>
    </div>
    <div id="contents">
      <div id="slashboxes">	
        <div class="block">
          <div class="title" id="index_qlinks-title">
            <h4>
                    Vestibulum
            </h4>
          </div>
          <div class="content" id="index_qlinks-content">
            <p>egestas quam </p>
          </div>
        </div>
      </div>
      <div id="articles">
        <div class="article" id="art1">
          <p>
          Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec tincidunt porttitor felis. Sed a tellus in lacus adipiscing tincidunt. Ut sollicitudin auctor dolor. Maecenas orci. Fusce porttitor odio eget erat. Aliquam erat volutpat. Fusce mollis, orci eget ullamcorper elementum, dui quam porttitor neque, euismod pulvinar risus turpis nec neque. Maecenas dolor risus, vestibulum in, congue a, pulvinar id, leo. Vestibulum porttitor hendrerit mauris. Morbi fringilla lectus quis orci. Vivamus laoreet massa scelerisque felis.
          </p>

          <p>
          Aenean nunc neque, euismod porta, tempor ut, eleifend at, massa. Nam tempor urna at ligula. Etiam auctor dui tempus odio egestas sagittis. Donec metus pede, tempor nec, tincidunt sit amet, consectetuer eget, massa. Nam dolor arcu, ornare et, imperdiet vel, euismod ut, nibh. Quisque ut erat. Maecenas ante urna, suscipit eget, dictum non, porttitor at, magna. Duis accumsan. Suspendisse luctus vehicula pede. Mauris a nisl. Cras leo.
          </p>
        </div>
      </div>
    </div>	
  </div>
  <div id="footer">
    Ut sollicitudin auctor dolor. Maecenas orci. 
  </div>	
</div>

</body>
</html>



/* file: core-tidied.css */
body {
  min-width: 680px;
  color: #111;
  background: #222;
}

#contents p {
  background-color: #eee;
}

#topnav {
  background: #044;
  position: relative;
  height: 55px;
  margin: 5px 1.25em 0 1.25em;
}

  #topnav #logo {
    width: 415px;
    height: 100%;
  }
  #topnav #logo h1 {
    display: block;
    height: 100%;
    width: 100%;
  }
    #topnav #logo h1 a {
      display: block;
      width: 100%;
      height: 100%;
      outline: none;
      text-indent: -5000px;
      text-decoration: none;
      background: url(//images.slashdot.org/logo.png) no-repeat left top;
    }
  
#slogan{ display: none; }

/* Wrapper */
#wrapper {
  overflow: hidden;
  background-color: #fff;
}

#wrapper #articles { margin-right: 18.5em; }

/* User section menu */
/* Contents */
#contents {
  width: auto;
  margin-left: 10.5em;
}

/* General Body */

/* Blocks */
div.block div.title { background: #666 }
  div.block div.title h4 {
    color: #fff;
  }


/* Links (left sidebar) */
div#links {
  float: left;
  width: 9.25em;
  background: #eee;
}
    div#links div.block div.content ul li {  list-style-image: none; }

/* Slashboxes (right sidebar) */
div#slashboxes {
  float: right;
  width: 17.25em;
}

/* Footer */
div#footer {
  background: #bbb;
  clear: both;
}

#contents {margin-top: 2em;}


The secret to positioning the columns, is to use left and right margins to push the element (column being adjusted), away from it's siblings. In the above example the contents (outer box) is pushed away from the left (#contents { margin-left: 10.5em;}), and the articles (inner box) within the contents is pushed from the right (#wrapper #articles { margin-right: 18.5em; }).

« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS