Skip to main content

Knowing the basics of CSS (Cascading Style Sheets)

If you want to know more about CSS and how to use it, there are many great resources out there that can help you get started: I would start with http://www.w3schools.com/Css/default.asp

Here are the basics that you will use:

Syntax
selector {property: value;}

External Style Sheet - (Added within the <head> tags)
<link rel="stylesheet" type="text/css" href="style.css" />

Internal Style - (Added within the <head> tags)
<style type="text/css">
selector {property: value;}
</style>

Inline Style- (Added within the <body> tags)
<tag style="property: value">

Or use the following table with some of the most basic Properties. I am using the .MS-Main class as a reference for all of the examples below.

Properties

Example

Other Values

Backgrounds

   

background-color

.MS_Main{
background-color:  #000000
}

black
rgb(0,0,0)
transparent

background-image

.MS_Main{
background-image:  url(imgname.gif);
}

none

 

background-position

.MS_Main{
background-position:  top left;
}

top center
top right
bottom right
x% y%
xpos ypos
(Many Others)

background-repeat

.MS_Main{
background-repeat:  no-repeat;
}

repeat
repeat-X
repeat-Y

background-attachment

.MS_Main{
background-attachment: fixed;
}

scroll

Borders

 

 

border

.MS_Main{
border:  1px #000000 solid;
}

none

Element Position and Visibility

 

 

display

Note:  You will never use display none for the body of you website.

.MS_Main{
display: none;
}

Block
(Many others)

visibility

.MS_Main{
visibility: hidden;
}

visible
collapse

position

.MS_Main{
position: relative;
top: 10px;
left: 10px;
}

static
absolute
fixed

Heights and Widths

 

 

height

.MS_Main{
height: 400px;
}

auto
length (px)
%

width

.MS_Main{
width: 980px;
}

auto
length (px)
%

Fonts and text treatments

 

 

Font-family

.MS_Main{
Font-family: arial, sans-serif;
}

Times, Serif
(many Others)

Font-size

.MS_Main{
Font-size: 12pt;
}

10px
1.1em
x-large

Font-style

.MS_Main{

Font-style: italic;

}

normal

oblique

Font-weight

.MS_Main{
Font-style: bold;
}

normal
bolder
lighter
100
(Many Others)

Text-align

.MS_Main{
Text-align: center;
}

left
right
justify

Text-decoration

.MS_Main{
Text-decoration: underline;
}

none
overline
line-through
blink

Line-height

.MS_Main{
Line-height: 20px;
}

normal
number
length (px)
%

Spacing of Elements

 

 

Padding

.MS_Main{
Padding: 20px;
}

padding-top
padding-left
(Many Others)

Margin

.MS_Main{
margin: 10px;
}

margin-top
margin-left
(Many Others)

Pseudo-classes

 

 

Hover

Note: you apply this pseudo class after the class name to achieve a hover state effect.

.MS_Main:hover {
Background-color: #CC0000;
}

Transparencies

Note: You can make a class’s opacity to give it a transparent look.

.MS_Main: {
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
}

!Important tag

Note: Sometimes your css will not override hardcoded inline styles or ids so you can simply force the style with the !important tag.

.MS_Main{
Background-color: #CC0000 !important;
}

Differences between Classes and ID's

A class is referenced in the HTML as the following:
<td class="ms-main"></td>

Notice the class does not have the "." period in front of it. To add style to this class you would use the following syntax:
.ms-main {color: red;}

A ID is referenced in the HTML as the following:
<DIV ID="ms-main"></DIV>

To add style to this class you would use the following syntax:
#ms-main {color: red;}

So if you can remember that Classes use (.) periods and ID's Use (#) Pound signs you should be golden.

Comments

Mike said…
Now if only MSFT would implement a decent CSS solution in SharePoint we would all be happy :)

Imho they really should have let the team that did the CSS implemtation in CMS do it instead of using the CSS from SPS... It's still a mess :(

Popular posts from this blog

How To: Create Hyperlink to Modal Pop-Up Form

I was asked by a client recently if there was a way to create a hyperlink to a New Item Form anywhere within a site but still get the rich experience of the Modal pop-up window that grays out the background. (Note this is for SharePoint 2010 Only…) I basically took the code directly from the “Add new item” and the “Add Document” link within the list view. What this allows you to do is simply add in the following code to any content editor web part, Master page, or Page Layout in any site collection and display the form to be filled out. The user will get the nice experience of the modal window and not have to navigate away from their current page. This could be used for example a feedback form that is included in the master page so whenever someone wants to give feedback it is always going back to a central list. The only that is required for you to know is the List ID and the site name. Full Code For a List Item: <a onclick="javascript:NewItem2(event, &quot

SharePoint 2010 Base CSS Classes

This will be the first of many SharePoint 2010 posts. I will be focusing on a few of the main CSS classes used for SharePoint 2010 Public Beta. As the product becomes more final there might be some changes to the class names but I will be sure to create a new post if that happens. This will be quite a lengthy but it should be helpful. The default CSS given below are just highlights of the full CSS attributes for that class. I will be using a basic team site as my base for the screenshots. Here is a basic structure of the main areas that I will cover. Ribbon Row Table Row Left Site Actions Navigate Up Edit Tab List Browse Page Table Row Right Give Feedback Welcome Menu Workspace Body Container Title Row Title

SharePoint 2013 Responsive Table Columns

I have been wanting to write this one for a while now. It is really amazing how UX is really finding is way into everything that we use and interact with. From Custom applications both mobile and on a desktop to document management or large data visualizations. There is always room for better usability and new concepts. SharePoint lists and library functionality really has not changed much for the past 10 years... I remember back in 2003 when I saw the same table/grid based views of documents and list items that exists in SharePoint 2013. But now we can look at them in a whole new way! In this video blog you will see how to create a responsive CSS table so that when the browser size is reduced it will hide specific columns. However hiding data is not always the right thing to do. What if a user needed those columns to filter on or to use for comparison to another document? Well that is where the custom jQuery Column chooser comes in. It allows you to see what columns are displ