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

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 2010 Content Query for Blog Posts

I hope this post will help many of you feel comfortable with using the Content Query Web Part. In this post I will walk you through the process of creating a content query web part and configuring it to show custom field types. I will also give details on how to use XSLT to stylize and format the data being pulled. I will be using the following scenario as an example. Say that you had a site collection with a top level publishing site. This publishing site would display a the most recent blog posts from all blog sites within its own site collection. To solve this problem we will use a Content Query Web Part and a customized ItemStyle.xsl using XSLT. Please note that the “SharePoint Server Publishing Infrastructure” needs to be enabled at the site collection to display the content query web part. Step 1: Add a Content Query Web Part to Page Navigate to the site that you want the blog posts to show up and click on edit page. Under Editing Tools in the Ribbon, Click on

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