SlideShare une entreprise Scribd logo
1  sur  24
Ramachandran G
#page {
  width: 960px;
  margin: 0 auto;
  }



The above will center the div with an id of page inside it’s parent container.
The HTML:
<div id="container">some text here</div>

The CSS:
div#container {height: 35px; line-height: 35px}



If you want to vertically center text within a containing block who’s height
 is fixed, simply set the line-height of the text to be the same as the height
of the containing block
Method 1
The HTML:
<div id="content">your content here</div>

The CSS:
div#content {position: absolute; top: 50%; height: 500px; margin-top:
  -250px}

The top left corner of the div will be positioned 50% from the top. Since we want
the center of the div to be positioned 50% from the top you need to set a negative
top margin equal to half the height of the div.
This same trick works for horizontal centering as well.
Change top to left and margin-top to margin-left and set the negative margin to
be half of the width of the element.
Method 2

The HTML :
  <div id="wrapper">
        <div id="cell">
                 <div class="content"> Content goes here
                 </div>
         </div>
   </div>

The CSS:
#wrapper {display:table;}
#cell {display:table-cell; vertical-align:middle;}


This method sets some <div>s to display like a table, so we can use the
table’s vertical-align property
div#button{
  background: #888;
   border: 1px solid;
   border-color: #999 #777 #777 #999 ;
  }
The CSS above will create a button with the light source at the upper left.
Usually one or two shades of color change is all that’s needed, but you can
experiment for different effects.
body { font: font-style font-variant font-weight font-size
  line-height font-family; }

Would look like this
body{font: normal bold 14px 18px arial;}


You don’t need to include every property, but know that for any you don’t
include that property will be reset to it’s default.
div#content {width: 580px}
*html body div#content {width: 600px}

IE7 specifically with
*+html body div#content {width: 620px}
.element {
min-height: 500px
height: auto !important
height: 500px
}
For IE6

 .element {
 min-height: 500px
 _height: 500px
 }
Element, Pseudo Element d = 1 – (0,0,0,1)
Class, Pseudo class, Attribute c = 1 – (0,0,1,0)
Id b = 1 – (0,1,0,0)
Inline Style: a = 1 – (1,0,0,0)

p: 1 element – (0,0,0,1)
div: 1 element – (0,0,0,1)
#sidebar: 1 id – (0,1,0,0)
div#sidebar: 1 element, 1 id – (0,1,0,1)
div#sidebar p: 2 elements, 1 id – (0,1,0,2)
div#sidebar p.bio: 2 elements, 1 class, 1 id – (0,1,1,2)
triangle {
border-color: transparent transparent green transparent;
border-style: solid;
border-width: 0px 300px 300px 300px;
height: 0px;
width: 0px;
}
.cirlce {
 width: 300px;
height: 300px;
background-color: red;
border-radius: 150px;
-moz-border-radius: 150px;
-webkit-border-radius: 150px;
}
Preventing:
  h1 { white-space:nowrap; }

Sometimes the text in a link or heading will break where you don’t want it to

Adding:
HTML:
<p><span>hello></span><span>How are you</span></p>

CSS:
p span {
   display: block;
}
h1 {
text-indent:-9999px;
background:url("h1-image.jpg") no-repeat;
width:200px;
height:50px;
}
a {outline: none}
or
a {outline: 0}
@font-face {
   font-family: 'LeagueGothic';
   src: url(LeagueGothic.otf);
 }

 header {
   font-family: 'LeagueGothic';
 }
div {
    text-overflow: ellipsis;
  }
A long cold winter delayed the blossoming …
color: rgba(255, 0, 0, 0.75);
background: rgba(0, 0, 255, 0.75);
.multibg {
    background: url(src/zippy-plus.png) 10px center no-repeat,
                url(src/gray_lines_bg.png) 0 center repeat-x;
  }
textarea{
overflow:auto;
}
The HTML :
    <a href="#" class="tooltip">Tooltip<span> Extra info </span></a>


The CSS :

a:hover {
background:#ffffff;     /*BG color is a must for IE6*
text-decoration:none;
}
a.tooltip span {
display:none;
padding:2px 3px;
margin-left:8px;
width:130px;
}
a.tooltip:hover span{
display:inline;
position:absolute;
background:#ffffff;
border:1px solid #cccccc;
color:#6c6c6c;
}
a[href$='.doc'] {
padding:0 20px 0 0;
background:transparent url(/graphics/icons/doc.gif)
no-repeat center rightright;
}

a[href$='.pdf'] {
padding:0 20px 0 0;
background:transparent url(/graphics/icons/pdf.gif )
no-repeat center rightright;
}
.input{
left: -1000px;
position: absolute;
}

.radioOff {
background: url("off.gif") no-repeat scroll 0 50% transparent;
color: #666666;
display: inline;
font: 0.8em/16px Verdana,Arial,Helvetica;
margin: 0;
padding: 2px 2px 2px 20px;
The HTML :
<div class="columns">
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit
  Nulla elementum accumsan.</p>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit
  </p>
  </div>

The CSS:
.columns {
  -moz-column-count: 2;
  -webkit-column-count: 2;
  }

Contenu connexe

Tendances

Shaping Up With CSS
Shaping Up With CSSShaping Up With CSS
Shaping Up With CSS
sdireland
 
Links and Navigation
Links and NavigationLinks and Navigation
Links and Navigation
sdireland
 
Visualizing The Code
Visualizing The CodeVisualizing The Code
Visualizing The Code
sdireland
 

Tendances (20)

The World of Dynamic Sites
The World of Dynamic SitesThe World of Dynamic Sites
The World of Dynamic Sites
 
Deepak Soni BCA First Year
Deepak Soni BCA First YearDeepak Soni BCA First Year
Deepak Soni BCA First Year
 
A complete html and css guidelines for beginners
A complete html and css guidelines for beginnersA complete html and css guidelines for beginners
A complete html and css guidelines for beginners
 
Efficient, maintainable CSS
Efficient, maintainable CSSEfficient, maintainable CSS
Efficient, maintainable CSS
 
Web Design Basics for Kids: HTML & CSS
Web Design Basics for Kids: HTML & CSSWeb Design Basics for Kids: HTML & CSS
Web Design Basics for Kids: HTML & CSS
 
Shaping Up With CSS
Shaping Up With CSSShaping Up With CSS
Shaping Up With CSS
 
Bhanu pratap
Bhanu pratapBhanu pratap
Bhanu pratap
 
Forms and Databases in PHP
Forms and Databases in PHPForms and Databases in PHP
Forms and Databases in PHP
 
Copy & Paste Design Hacks To Take Your Blog to the Next Level
Copy & Paste Design Hacks To Take Your Blog to the Next LevelCopy & Paste Design Hacks To Take Your Blog to the Next Level
Copy & Paste Design Hacks To Take Your Blog to the Next Level
 
Intro to CSS
Intro to CSSIntro to CSS
Intro to CSS
 
Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1Web Design Course: CSS lecture 1
Web Design Course: CSS lecture 1
 
Html frames
Html framesHtml frames
Html frames
 
Haml. New HTML? (RU)
Haml. New HTML? (RU)Haml. New HTML? (RU)
Haml. New HTML? (RU)
 
Links and Navigation
Links and NavigationLinks and Navigation
Links and Navigation
 
Web Design 101
Web Design 101Web Design 101
Web Design 101
 
Designing and Developing Windowed Interfaces for Web Apps
Designing and Developing Windowed Interfaces for Web AppsDesigning and Developing Windowed Interfaces for Web Apps
Designing and Developing Windowed Interfaces for Web Apps
 
Bs Typography
Bs TypographyBs Typography
Bs Typography
 
Visualizing The Code
Visualizing The CodeVisualizing The Code
Visualizing The Code
 
Css presentation introdution with sample basic projects
Css presentation introdution with sample basic projectsCss presentation introdution with sample basic projects
Css presentation introdution with sample basic projects
 
HTML 5 Simple Tutorial Part 1
HTML 5 Simple Tutorial Part 1HTML 5 Simple Tutorial Part 1
HTML 5 Simple Tutorial Part 1
 

En vedette (6)

Beyond the Standards
Beyond the StandardsBeyond the Standards
Beyond the Standards
 
Ignore the DOM
Ignore the DOMIgnore the DOM
Ignore the DOM
 
Intellectual Property Rights : A Primer
Intellectual Property Rights : A PrimerIntellectual Property Rights : A Primer
Intellectual Property Rights : A Primer
 
Dos and Don't during Monsoon!
Dos and Don't during Monsoon!Dos and Don't during Monsoon!
Dos and Don't during Monsoon!
 
J Query
J QueryJ Query
J Query
 
Google +
Google +Google +
Google +
 

Similaire à Css tips & tricks

Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
Senthil Kumar
 
CSS Layout Tutorial
CSS Layout TutorialCSS Layout Tutorial
CSS Layout Tutorial
hstryk
 
Class 3 create an absolute layout with css abs position (aptana)
Class 3  create an absolute layout with css abs position (aptana)Class 3  create an absolute layout with css abs position (aptana)
Class 3 create an absolute layout with css abs position (aptana)
Erin M. Kidwell
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
tutorialsruby
 
waxaada canshuurahaiyosiyaaddaguudeexamarwaaardaydaDAALBADAN.ppt
waxaada canshuurahaiyosiyaaddaguudeexamarwaaardaydaDAALBADAN.pptwaxaada canshuurahaiyosiyaaddaguudeexamarwaaardaydaDAALBADAN.ppt
waxaada canshuurahaiyosiyaaddaguudeexamarwaaardaydaDAALBADAN.ppt
Ismaciil2
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
tutorialsruby
 

Similaire à Css tips & tricks (20)

CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
 
css-note.pptx
css-note.pptxcss-note.pptx
css-note.pptx
 
Xlrays online web tutorials
Xlrays online web tutorialsXlrays online web tutorials
Xlrays online web tutorials
 
Theme 23
Theme 23Theme 23
Theme 23
 
Introduction to css by programmerblog.net
Introduction to css by programmerblog.netIntroduction to css by programmerblog.net
Introduction to css by programmerblog.net
 
CSS
CSSCSS
CSS
 
CSS Layout Tutorial
CSS Layout TutorialCSS Layout Tutorial
CSS Layout Tutorial
 
Web Design Course: CSS lecture 4
Web Design Course: CSS  lecture 4Web Design Course: CSS  lecture 4
Web Design Course: CSS lecture 4
 
WordPress theme translation
WordPress theme translationWordPress theme translation
WordPress theme translation
 
Class 10
Class 10Class 10
Class 10
 
Getting Started with Sass & Compass
Getting Started with Sass & CompassGetting Started with Sass & Compass
Getting Started with Sass & Compass
 
Class 3 create an absolute layout with css abs position (aptana)
Class 3  create an absolute layout with css abs position (aptana)Class 3  create an absolute layout with css abs position (aptana)
Class 3 create an absolute layout with css abs position (aptana)
 
Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)Sass & Compass (Barcamp Stuttgart 2012)
Sass & Compass (Barcamp Stuttgart 2012)
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
waxaada canshuurahaiyosiyaaddaguudeexamarwaaardaydaDAALBADAN.ppt
waxaada canshuurahaiyosiyaaddaguudeexamarwaaardaydaDAALBADAN.pptwaxaada canshuurahaiyosiyaaddaguudeexamarwaaardaydaDAALBADAN.ppt
waxaada canshuurahaiyosiyaaddaguudeexamarwaaardaydaDAALBADAN.ppt
 
css1.ppt
css1.pptcss1.ppt
css1.ppt
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Dernier

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 

Dernier (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 

Css tips & tricks

  • 2. #page { width: 960px; margin: 0 auto; } The above will center the div with an id of page inside it’s parent container.
  • 3. The HTML: <div id="container">some text here</div> The CSS: div#container {height: 35px; line-height: 35px} If you want to vertically center text within a containing block who’s height is fixed, simply set the line-height of the text to be the same as the height of the containing block
  • 4. Method 1 The HTML: <div id="content">your content here</div> The CSS: div#content {position: absolute; top: 50%; height: 500px; margin-top: -250px} The top left corner of the div will be positioned 50% from the top. Since we want the center of the div to be positioned 50% from the top you need to set a negative top margin equal to half the height of the div. This same trick works for horizontal centering as well. Change top to left and margin-top to margin-left and set the negative margin to be half of the width of the element.
  • 5. Method 2 The HTML : <div id="wrapper"> <div id="cell"> <div class="content"> Content goes here </div> </div> </div> The CSS: #wrapper {display:table;} #cell {display:table-cell; vertical-align:middle;} This method sets some <div>s to display like a table, so we can use the table’s vertical-align property
  • 6. div#button{ background: #888; border: 1px solid; border-color: #999 #777 #777 #999 ; } The CSS above will create a button with the light source at the upper left. Usually one or two shades of color change is all that’s needed, but you can experiment for different effects.
  • 7. body { font: font-style font-variant font-weight font-size line-height font-family; } Would look like this body{font: normal bold 14px 18px arial;} You don’t need to include every property, but know that for any you don’t include that property will be reset to it’s default.
  • 8. div#content {width: 580px} *html body div#content {width: 600px} IE7 specifically with *+html body div#content {width: 620px}
  • 9. .element { min-height: 500px height: auto !important height: 500px } For IE6 .element { min-height: 500px _height: 500px }
  • 10. Element, Pseudo Element d = 1 – (0,0,0,1) Class, Pseudo class, Attribute c = 1 – (0,0,1,0) Id b = 1 – (0,1,0,0) Inline Style: a = 1 – (1,0,0,0) p: 1 element – (0,0,0,1) div: 1 element – (0,0,0,1) #sidebar: 1 id – (0,1,0,0) div#sidebar: 1 element, 1 id – (0,1,0,1) div#sidebar p: 2 elements, 1 id – (0,1,0,2) div#sidebar p.bio: 2 elements, 1 class, 1 id – (0,1,1,2)
  • 11. triangle { border-color: transparent transparent green transparent; border-style: solid; border-width: 0px 300px 300px 300px; height: 0px; width: 0px; }
  • 12. .cirlce { width: 300px; height: 300px; background-color: red; border-radius: 150px; -moz-border-radius: 150px; -webkit-border-radius: 150px; }
  • 13. Preventing: h1 { white-space:nowrap; } Sometimes the text in a link or heading will break where you don’t want it to Adding: HTML: <p><span>hello></span><span>How are you</span></p> CSS: p span { display: block; }
  • 15. a {outline: none} or a {outline: 0}
  • 16. @font-face { font-family: 'LeagueGothic'; src: url(LeagueGothic.otf); } header { font-family: 'LeagueGothic'; }
  • 17. div { text-overflow: ellipsis; } A long cold winter delayed the blossoming …
  • 18. color: rgba(255, 0, 0, 0.75); background: rgba(0, 0, 255, 0.75);
  • 19. .multibg { background: url(src/zippy-plus.png) 10px center no-repeat, url(src/gray_lines_bg.png) 0 center repeat-x; }
  • 21. The HTML : <a href="#" class="tooltip">Tooltip<span> Extra info </span></a> The CSS : a:hover { background:#ffffff; /*BG color is a must for IE6* text-decoration:none; } a.tooltip span { display:none; padding:2px 3px; margin-left:8px; width:130px; } a.tooltip:hover span{ display:inline; position:absolute; background:#ffffff; border:1px solid #cccccc; color:#6c6c6c; }
  • 22. a[href$='.doc'] { padding:0 20px 0 0; background:transparent url(/graphics/icons/doc.gif) no-repeat center rightright; } a[href$='.pdf'] { padding:0 20px 0 0; background:transparent url(/graphics/icons/pdf.gif ) no-repeat center rightright; }
  • 23. .input{ left: -1000px; position: absolute; } .radioOff { background: url("off.gif") no-repeat scroll 0 50% transparent; color: #666666; display: inline; font: 0.8em/16px Verdana,Arial,Helvetica; margin: 0; padding: 2px 2px 2px 20px;
  • 24. The HTML : <div class="columns"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit Nulla elementum accumsan.</p> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit </p> </div> The CSS: .columns { -moz-column-count: 2; -webkit-column-count: 2; }