Never been to TextSnippets 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 (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
44 total  XML / RSS feed 

CSS image floats no text wrap

Credit goes to:

http://ghettocooler.net/2005/11/13/image-floats-without-the-text-wrap/

.callout {
float:left;
width:275px;
}

.callout h3 {
width:115px;
height:65px;
float:left;
text-indent:-8008px;
background:transparent url(team-report.gif) no-repeat 0 0;
}

.callout * {
width:160px;
float:right;
}

.callout * * {
width:auto;
float:none;
}


Cross-browser solution for adding hover border to linked images

// The class is assigned to the href.

.borderit img {
        border: 1px dashed #776e09;
        padding: 2px;
}
.borderit:hover img {
        border: 1px solid #fff71c;
        padding: 2px;
}
.borderit:hover {
        color: red; /* irrelevant definition to overcome IE bug */
}

Standard CSS helpers

Some really common layout classes I use in almost every CSS file.

/********* helpers *********/
.floatRight { float: right; }
.floatLeft  { float: left; }
.right  { text-align: right; }
.left   { text-align: left; }
.center { text-align: center; }
.clear, .clearer { clear: both; }
.block  { display: block; }

Remove border from images when linked

// description of your code here

img {
 border-style: none;
}

CSS Overflow Vertical Only

Will always have the vertical scrollbar and no horizontal scrollbar. Horizontal can be done by using -x

overflow-y: scroll;

Universal Selector

An even better starting point for every style sheet: it sets everything to 0. No sense writing out every selector!

* { // This selects every element on the page
margin: 0;
padding: 0;
border: 0 none;
font-style: normal;
font-weight: normal;
font-size: 100%;
list-style-type: none;
text-align: left;
text-decoration: none;
}

IE Fix for max-width CSS property

AGAIN another IE fix. IE of course does not recognize the max-width CSS property. This piece of code will fix it for IE6 and IE7. This code snip will make the maximum width for the html object 900 pixels.

.cssClass
{
width:expression(document.body.clientWidth > 900? "900px": "auto" );
}

Some good body fonts

// Some fonts that could be used for body copy

font:10pt 'Trebuchet MS',Arial,sans-serif;
font:76%/140% Verdana,Geneva,Arial,Helvetica,sans-serif;
font:76%/1.5 "Lucida Grande",Geneva,Verdana,Arial,Helvetica,sans-serif;
font:12px/1.5 "Lucida Grande","Lucida Sans Unicode", sans-serif;

skidoo_lean.css

// skidoo_lean.css

@charset "iso-8859-1";

/*******************************************************************************
*  skidoo_lean.css : 2004-08-17 : Ruthsarian Layouts
* ------------------------------------------------------------------------------
*  lean and mean version of the original skidoo layout seen at:
*  http://webhost.bridgew.edu/etribou/layouts/skidoo/
*  CSS for horizontal and vertical nav elements based on unordered lists
*  isn't here to help reduce the layout to its core components.
*******************************************************************************/

body
{
        background-color: #333;
        color: #fff;
        font-size: 100.1%;
        margin: 0;
        padding: 2em;           /* remove this to stretch the layout 
                                   across the screen edge-to-edge */
}
#pageWrapper
{
        border-style: solid;
        border-width: 0 1px;    /* layout's side borders */
        font-family: arial, helvetica, sans-serif;
        font-size: 80%;         /* arial looks better with a smaller size */
        margin: 0;
        min-width: 500px;       /* IE doens't understand this property */
        width: auto;
}
* html #pageWrapper
{
        word-wrap: break-word;  /* invalid CSS but keeps IE from breaking 
                                   horribly under narrow viewports */
}
#masthead
{
        background-color: #666;
        border-style: solid;
        border-width: 1px 0;
        color: #fff;
}
#masthead h1
{
        display: inline;        /* easier than setting 0 padding and margin */
}
#outerColumnContainer
{
        background-color: #fff;
        border-style: solid;
        border-width: 0 14em;   /* side border widths must equal the
                                   widths of the left and right columns. 
                                 */
        border-left-color: #ccc;        /* left hand column background color */
        border-right-color: #999;       /* right hand column background color */
        color: #000;
        z-index: 1;
}
* html #outercolumncontainer
{
        /* IE5.0/Win fix for 1px whitespace between masthead and body. 
         * The case-incorrect selector is on purpose. IE5.0 and IE5.5 are
         * case insensitive and I'm targeting IE 5.0. 5.5 doesn't get hurt
         * by this extra margin work.
         */
        margin-top: -1px;
        border-top: solid 1px #000;
}
#innerColumnContainer
{
        border-style: solid;
        border-width: 0 1px;    /* puts borders between middle and the side 
                                   columns. */
        margin: 0 -1px;         /* compensate for the borders because of
                                   100% width declaration */
        width: 100%;
        z-index: 2;
}
html[xmlns] .mozclear
{
        /* this selector should be valid CSS, but Opera 7.5 (and above) will pick
         * this up as well. Shouldn't be a problem, Opera should handle this fine,
         * but it's a Mozilla-targeted hack, and it should probably only affect
         * mozilla. You can do that by replacing the INVALID CSS selector
         * :root .mozclear for what's give here.
         */
        border-bottom: 1px solid;
        border-color: transparent;
        margin-bottom: -1px;
}
#leftColumn, #rightColumn, #contentColumn
{
        float: left;
        overflow: visible;      /* fix for IE italics bug */
        position: relative;
        z-index: 10;
}
#leftColumn
{
        margin: 0 1px 0 -14em;  /* the margin on the side the column is to be
                                   rendered on must be the negative equal of 
                                   the column's width. The opposite border must
                                   be 1px */
        width: 14em;
}
#rightColumn
{
        float: right;   /* doesn't have to be floated right, but if using some
                           original skidoo tweaks, you need it this way */
        margin: 0 -14em 0 1px;  /* same as in the #leftColumn but reversed */
        width: 14em;
}
#rightColumn .inside
{
        font-size: 90%; /* because the parent element ( #rightColumn )
                           defines its width in EMs, we can't change the font 
                           size in that selector, otherwise the column won't use
                           the entire width reserved for the column */
}
#contentColumn
{
        margin: 0 -1px;               /* required to get the negative margin-based
                                   layout to work. if #contentColumn does not
                                   overlap the left and right columns, then
                                   the whole layout will break */
        width: 100%;
}
#footer
{
        background-color: #666;
        border-style: solid;
        border-width: 1px 0;    /* border for bottom of layout and top of 
                                   footer area */
        color: #fff;
        position: relative;
        text-align: center;
}
html>body #footer
{
        padding-bottom: 1.01em; /* attempt to fix Gecko engine's rounding errors
                                   which can disrupt the layout. */
}
p, h1, h2, h3, h4, h5, h6
{
        margin: 1em 0;          /* for better consistency across platforms */
}
.clear
{
        clear: both;
}
.inside
{
        padding: 0 1.5em;       /* glitch in IE caused by vertical padding in
                                   this class, so 0 padding is set here and
                                   those blocks that need the vertical padding
                                   must be applied to the parent element.
                                   the purpose of this class is to provide 
                                   horizontal padding without using hacks to
                                   get around IE's broken box model. so it's
                                   okay to apply vertical padding to the parent
                                   element, just not horizontal padding. */
}
#leftColumn, #centerColumn, #rightColumn, #masthead
{
        padding-top: 0.5em;
        padding-bottom: 0.5em;  /* this is the vert padding talked about in the
                                   .inside selector comment. */
}
#masthead, #footer
{
        padding: 1em;   /* ditto from above */
}
#pageWrapper, #innerColumnContainer, #masthead, #footer
{
        border-color: #000;     /* one-stop control of border color used within
                                   the layout */
}
#outerColumnContainer
{
        border-top-color: #000; /* should match the above border color */
}

/******************************************************************************/

fixedWidth.css

// description of your code here

@charset "iso-8859-1";

/*******************************************************************************
*  fixedWidth.css : 2004-07-19 : Ruthsarian Layouts
* ------------------------------------------------------------------------------
*  Provide a fixed width to the layout
*******************************************************************************/

* html body
{
        text-align: center;   /* hack to center this under IE5 */
}
* html #pageWrapper
{
        text-align: left;     /* keep the content left-aligned */
}

#pageWrapper
{
        width: 700px;
        margin-left: auto;
        margin-right: auto;
}

/******************************************************************************/

twoColumnsLeft.css

@charset "iso-8859-1";

/*******************************************************************************
*  twoColumnsLeft.css : 2004-08-17 : Ruthsarian Layouts
* ------------------------------------------------------------------------------
*  This stylesheet removes the right-hand column from the 3 column layout
*******************************************************************************/

html>body #rightColumn
{
        display: none;      /* for compliant browsers, hide this column entirely */
}
* html #rightColumn *
{
        display: none;      /* ie's ghost-text bug is triggered by key elements
                           having display:none set. #rightColumn is one of those
                           key elements. so we display:none all child
                           elements (doesn't trigger the bug) and try to
                           make #rightColumn have no chance to affect
                           document flow. */
}
#rightColumn
{
        position: absolute;
        margin: 0;
        padding: 0;
        width: 0;
        height: 0;
        border: none;       /* remove anything that'll give this elemnt width. */
}
#outerColumnContainer, #innerColumnContainer
{
        border-right-width: 0; /* to get from 3 to 2 columns, we must hide the
                                   right-side border */
}
#innerColumnContainer
{
        margin-right: 0;
}

/******************************************************************************/

tank.css

http://webhost.bridgew.edu/etribou/layouts/Tank!/index.html

@charset "iso-8859-1";

/*******************************************************************************
*  tank.css : 2005.09.01
* -----------------------------------------------------------------------------
*  
*******************************************************************************/

@import "http://webhost.bridgew.edu/etribou/layouts/rMenu/rMenu.css";
@import "http://webhost.bridgew.edu/etribou/layouts/utility_css/dropmenu.css";

/* begin with generic selectors so that they can be overridden if needed
 * by classes deeper in the stylesheet
 */
.clear
{
        clear: both;
        padding-bottom: 1px;      /* for Gecko-based browsers */
        margin-bottom: -1px;   /* for Gecko-based browsers */
}
* html .clear
{
        padding: 0;
        margin: 0;
}
.hide
{
        display: none !important;
}
.inside
{
        /* glitch in IE caused by vertical padding in this class, so 0 padding is
         * set here and those blocks that need the vertical padding must be 
         * applied to the parent element. the purpose of this class is to provide
         * horizontal padding without using hacks to get around IE's broken box 
         * model. so it's okay to apply vertical padding to the parent element, 
         * just not horizontal padding.
         */
        padding: 0 14px;
}

/* The core Tank! layout structure begins here. No surprises here. Basic
 * negative margins (skidoo) layout structure with the added benefit of
 * forcing #pageWrapper to go the full height of the viewport even if the
 * content isn't tall enough to otherwise foce that height.
 *
 * Theme-related stuff (colors, fonts, etc...) are in the tank_theme.css
 * stylesheet, although 'default' values could be included within this
 * stylesheet.
 */
html, body
{
        height: 100%; /* need to set the height on these two elements to 100%,
                           otherwise child elements such as #pageWrapper, when
                           its height is set to 100%, will only go as height as
                           the needed to contain the content within the 
                           element */
}
body
{
        margin: 0;
        padding: 0;        /* no padding here, we put it as margin values on 
                           #pageWrapper. padding/margin values here will break
                           the min-width emulation for IE */
} 
#pageWrapper
{
        border: solid 1px #000;
        border-width: 0 1px;
        margin: 0 20px 0 140px; /* this value defines the margins surrounding the
                                   layout and how much of the body element's 
                                   background color will show through. since we're
                                   using a 100% height hack, vertical margins don't
                                   belong here */
        min-width: 700px;
        width: auto;
        min-height: 100%;
        _height: 100%;  /* if we didn't use the hack, and just set height to 100%
                           then some browsers will stop the #pageWrapper block
                           at 100% the height of the window. any content that
                           doesn't fit within that space will overflow but the
                           background colors of the columns will not carry. Ugly. */
}
* html #pageWrapper
{
        word-wrap: break-word;  /* invalid CSS but keeps IE from breaking 
                                   horribly under narrow viewports */
}
#masthead
{
        padding: 10px;
        border-bottom: solid 1px #000;
}
#masthead h1, #masthead h2
{
        margin: 0;
        padding: 0;
}
#outerColumnContainer
{
        border-right: solid 16em #fff;
        z-index: 1;
}
#innerColumnContainer
{
        border-right: solid 1px #000;
        margin: 0 -1px 0 0;     /* -1px to make room for the 1px border. this is not
                                   part of the negative margins hack used to create
                                   multiple columns. */
        width: 100%;
        z-index: 2;
}
#contentColumn, #rightColumn
{
        float: left;
        overflow: visible;
        /* \*/ position: relative;      /* drop-down menus go transparent if this is 
                                           left in for IE/Mac to see. Very odd. */
}
#rightColumn
{
        margin: 0 -16em 0 1px;
        width: 16em;
}
#contentColumn
{
        margin-right: -1px;
        width: 100%;
}
* html #contentColumn
{                       /* * html #rightColumn */
        overflow: hidden;       /* this is because IE 6 and earlier do not handle overflow
                                   properly. visible overflow forces the overflowing block
                                   to grow to contain the oversized child element. this can
                                   break the layout. so we hide content. */
}
#rightColumn h3
{
        position: relative;
        z-index: 999;
}
* html #rightColumn h3
{
        display: inline-block;
}
#footer
{
        border-top: solid 1px #000;
        text-align: center;
}
#footer p
{
        /* #footer is also assigned the .inside class so padding is being 
         * applied already. we don't need the paragraph gutterspace on top 
         * of it. since the footer is only one paragraph, we can just kill 
         * all gutterspace on all p elements in #footer. but if you plan on 
         * having more than one p element, go ahead and kill this rule and 
         * remove the .inside class assignment from #footer in the HTML
         */
        padding: 0;
        margin: 0;
}

/* twoColumns class for implementing a simple 2-column structure wherever you need it
 * inside the content column. 
 */
div.twoColumns
{
        margin: 14px 0;
        width: 100%;
}
div.twoColumns div.leftColumn, 
div.twoColumns div.rightColumn
{
        float: left;
        width: 50%;
        overflow: visible;      /* fix for IE italics bug */
}
div.twoColumns div.leftColumn
{
        margin-right: -1px;
        border-right: solid 1px #000;
}
div.twoColumns div.rightColumn
{
        margin-right: -2px;
        border-left: solid 1px #000;
}
div.twoColumns div.leftColumn div.inside
{
        padding-left: 0;
}
div.twoColumns div.rightColumn div.inside
{
        padding-right: 0;
}

/* Miscellaneous things layout-related, but not core to the layout itself.
 */
p.fontsize-set, div.colorPicker
{
        _padding-top: 1px;      /* keep IE from putting in too much padding */
        text-align: center;
}
p.fontsize-set img
{
        border-width: 0;
        margin: 0 3px;
}
div.colorPicker a
{
        display: block;
        width: 12px;
        height: 12px;
        margin: 0 5px;
        float: left;
        padding: 0;
        line-height: 0;
        font-size: 0;
        background-color: #dc8; /* default color picker */
}

/* style-switcher will use anchors converted to block elements with no
 * content. set the background-color property to whatever value that particular
 * swatch should be
 */
a#colorPicker-blue
{
        background-color: #abe;
}
a#colorPicker-green
{
        background-color: #aca;
}
a#colorPicker-camille
{
        background-color: #e77;
}
a#colorPicker-gray
{
        background-color: #ccc;
}
a#colorPicker-black
{
        background-color: #000;
}

/******************************************************************************/

rMenu.css

Ruthsarian Menus - A CSS-based dropdown menu system

@charset "iso-8859-1";

/*******************************************************************************
*  rMenu.css : 2006.10.17 : [email protected]
* ------------------------------------------------------------------------------
* Ruthsarian Menus - A CSS-based dropdown menu system
*
* 
*
* KNOWN BUGS
*       - Opera 7.23 and earlier have problems with absolutely positioned 
*         elements positioned relative to a parent element. this causes a
*         problem with right-aligned horizontal menus. stay away from those
*         types of menus if you've got any reason to care about Opera 7.23 or
*         earlier versions.
*
* DEV NOTES
*       - setting position: relative; to ul.rMenu triggers a bug in Netscape 7
*         and earlier that makes content jump as menus pop
*       - need to remember that when assigning multiple classes to an element
*         to list them left-to-right from most-specific to least-specific.
*         Otherwise IE/Mac flips out
*    - IE/Mac needs whitespace before <UL> and UL> tags in the markup
*         otherwise very odd things can happen
*       - hasLayout should not be triggered on LI elements under IE7
*       - IE/Mac has a selector bug where rMenu-v* and rMenu-h* rules
*      are applied to rMenu-v and rMenu-h elements. ie rMenu-vRight rules
*      get applied to rMenu-v elements. This is incorrect.
*    - if any parent element of the menu is a float it (or the parent of
*      the menu) needs to be relatively positioned. Otherwise the menu
*      is not rendered on the page.
*
* EXAMPLE HTML
*    <ul class="rMenu-hor rMenu"
*      ><li
*        ><a href="">Menu Itema
*           > 

visual_consistencies.css

visual_consistencies.css : 2005.09.07 : Ruthsarian Layouts

@charset "iso-8859-1";

/*******************************************************************************
*  visual_consistencies.css : 2005.09.07 : Ruthsarian Layouts
* -----------------------------------------------------------------------------
*  Font sizes on heading elements and the margin/padding applied to these
*  same elements will vary from browser to browser. This is an attempt to pull
*  the font sizes and spacing together for a consistent look across all
*  browsers. 
*
*  There are other rules included in this stylesheet (with comments on each)
*  to handle other visual consistency issues. You do not need to use this
*  stylesheet, nor do you need to follow it exactly. You can make changes
*  anywhere you want to make things look the way you want to. Nothing here
*  _should_ break a layout if modified.
*******************************************************************************/

ul, ol, dl, p, h1, h2, h3, h4, h5, h6
{
        /* pixels are used here, rather than ems, because I want a consistent 
         * margin on the different headings. if I use ems, 1em for an h1 element 
         * is much larger than 1em on an h6 element. I don't want this.
         */
        margin-top: 10px;
        margin-bottom: 10px;
        padding-top: 0;
        padding-bottom: 0;
}
ul ul, ul ol, ol ul, ol ol
{
        /* kill margins on sub-lists
         */
        margin-top: 0;
        margin-bottom: 0;
}
h1
{
        font-size: 240%;
}
h2
{
        font-size: 180%;
}
h3
{
        font-size: 140%;
}
h4
{
        font-size: 100%;
}
h5
{
        font-size: 70%;
}
h6
{
        font-size: 50%;
}
a, a:link, a:visited, a:active
{
        text-decoration: underline;
}
a:hover
{
        /* because I like the visual feedback a user gets when they
         * mouse over a link and see the underline of the link
         * disappear.
         */
        text-decoration: none;
}
code, pre
{
        /* Make sure we're all using the same monospaced font for CODE
         * and PRE elements
         */
        font-family: "Courier New", Courier, monospace;
}
label
{
        /* It's all about the visual feedback. In this case, label 
         * elements are usually clickable which then set focus on
         * their target. I want to show that to the user in a manner
         * they are used to and understand.
         */
        cursor: pointer;
}
table
{
        /* Some browsers won't carry the font size down into the 
         * browser like they're suppose to.
         */
        font-size: 100%;
}
td, th
{
        /* I never like or use the default vertical centering "feature"
         * provided by tables. 
         */
        vertical-align: top;
}
body
{
        /* I've seen several comments that setting the base font size to 100.1%
         * fixes some browser bugs. Which bugs? I don't know. I believe it's
         * to fix some rounding-error bugs that some browsers (Mozilla) are
         * prone to. It doesn't hurt anything, so I keep it here.
         */
        font-size: 100.1%;
}

/******************************************************************************/

Toggle Layers across browsers

// description of your code here

function toggleLayer(whichLayer) 
{
        if (document.getElementById) 
        {
                // this is the way the standards work
                var style2 = document.getElementById(whichLayer).style;
                style2.display = style2.display? "":"none";
        }
        else if (document.all)
        {
                // this is the way old msie versions work
                var style2 = document.all[whichLayer].style;
                style2.display = style2.display? "":"none";
        }
        else if (document.layers)
        {
                // this is the way nn4 works
                var style2 = document.layers[whichLayer].style;
                style2.display = style2.display? "":"none";
        }
}


vertical align in div

http://www.jakpsatweb.cz/css/css-vertical-center-solution.html

Understandable code:
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
  <title>Universal vertical center with CSStitle>