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: Hide Left Side Navigation on Home Page

I was recently asked: "How can I hide the side nav bar on the main homepage layout ?? I want to be able to use the side NAV with in the team site etc etc, but I don't want it on the front page.. " There are a couple of ways to do this in SharePoint 2010. If you are using a non-publishing site you can add a Content Editor Web Part to the page and add the following to the HTML Source.
<Style>
body #s4-leftpanel
{
display: none;
}
.s4-ca
{
margin-left: 0px;
}
</style>
Basically the CSS above hides the left navigation Div, and then sets the content area to not have a left margin. Once you are done, simply modify the web part and hide it on the page. If you are using a publishing site for your homepage simply add the same styles specified above to a custom page layout. That way if you have a need for other pages that do not need the left side navigation you can re-use the page layout.

Small Calendar for SharePoint 2010 & 2013

First off I would like to apologize for the lack of posts. I have been really busy with my new role as the UX Design lead within Slalom Consulting Boston. I will share more about that in another post. In a previous post Create Really Small Calendar I showcased how to do this for SharePoint 2007. However the 2010 and 2013 calendar views have changed and therefore we cannot use the same method or CSS as 2007.SharePoint 2010 Small Calendar:
SharePoint 2013 Small Calendar:
See video below for a video walk through on how to create a small calendar for SharePoint 2010 and & SharePoint 2013 with just CSS.Per the video above here is the code that I referenced:2010 CSS link reference in Master Page:
<SharePoint:CssRegistration name="<% $SPUrl:~sitecollection/Style Library/smallcalendar.css %>" After="corev4.css" runat="server"/>2010 CSS:
/**** Small Calendar ***/
.ms-acal-item{height: 10px !important;}
.ms-acal-sdiv,
.ms-acal-mdiv,
.ms-…

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 RowTable Row Left Site Actions Navigate Up Edit Tab List Browse Page Table Row Right Give Feedback Welcome Menu WorkspaceBody Container Title Row Title Title Logo Title Text / BreadcrumbPage DescriptionSocial Data SeparatorI like It Tags/Notes Top Header 2/Top Links li Static-Selected li Static SearchHelpStatus Bar Container Main A…