more csscs115/slides/w02-02-morecss.pdfbox model • css box model à box around an html element...

22
More CSS CS 115 Computing for the Socio-Techno Web Instructor: Brian Brubach

Upload: others

Post on 03-Oct-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

MoreCSSCS115ComputingfortheSocio-TechnoWeb

Instructor:BrianBrubach

Page 2: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

Announcements

• Checkgooglegroupsmail• Assignment2posted,duedatepushedtoFriday• Assignment0feedbackout

Page 3: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

Classicwebpage

Page 4: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

Classicwebpage

Page 5: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

Classicwebpage

Page 6: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

Classicwebpage

Page 7: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

CSSColors

• Canusepredefinedcolors(e.g.,yellow,white,red,purple,blue).• Canspecifyacolorbythered,greenandbluecomponents• Thefollowingareequivalent:• red• rgb(255,0,0)• #ff0000

• CRGBAaddsalphachanneltospecifytheopacityforacolor• RGBAcolorspecification– rgba(RED,GREEN,BLUE,ALPHA)• Alphavalueof0(transparent)to1.0(opaque)• E.g.,rgba(125,125,125,0.5);

• References:http://www.w3schools.com/css/css3_colors.asp

Page 8: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

Numberbases

• Decimalà Base10(e.g.2375)• Whatpeopleuse,why?

• Binaryà Base2(e.g.100110)• Whatcomputersuse

• Hexadecimalà Base16(a4f90)• HTMLcolorsamongotherthings

• Octalà Base8• Let’sseesomeexamplesonthedoccam

Page 9: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

Hexadecimal

• Eachdigitisthecoefficientforapowerof16• Needsingledigitslargerthan9• a=10,b=11,c=12,d=13,e=14,f=15

• Eachdigitisthecoefficientforapowerof16• Example:4-digithexnumber• Hexadecimalcolors• Three2-digithexnumbers• #12fe9b• Sameasrgb(18,254,155)

b4fd

16# 16$ 16% 16&

𝑏×16# + 4×16$ + 𝑓×16% + 𝑑×16&11×4096 + 4×256 + 15×16 + 13×1

= 46333

Page 10: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

SettingSize

• Lengthunits- centimeters(cm),millimeters(mm),etc.• Whitespacecannotappearbetweennumberandtheunit,• Twotypesoflengthunits:• Relative(e.g.,em,rem)• Absolute(e.g.,cm,pt,pc)

• Relative• emà Relativetothesizeofthecurrentfont• 3emà 3timessizeofcurrentfont• http://www.sitepoint.com/power-em-units-css/

• Preferredà relativeandpercentages• http://www.w3schools.com/cssref/css_units.asp

Page 11: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

CSSComments

• Commentsà Surroundedby/**/• Youcanusethemtodisablestyles

Page 12: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

Moreonkindsofselectors

• ClassSelectorsà Allowustoapplythesamerulestomanyelements• Usewhenyouneedtoapplyastylemanytimesinyourdocument• Createdwithaperiod(alsoknownasfullstop)

• IDSelectorsà Similartoclassselectorsbutappearonlyonceinthedocument• Usedwhenyouneedtoapplyastyleonlyonceinyourdocument• Createdusing#

Page 13: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

Moreonkindsofselectors

• TypeSelectorsà ThosebasedonthenameofanHTMLtag(e.g.,p,table,etc.)• p{color:red;}

• Pseudo-classesà attachedtoselectorstospecifyastate• Fourpopularpseudo-classesare:• a:linkà initialcolorofalink• a:visitedà colorforavisitedlink• a:hoverà colorwhenmousehoveroverlink• a:activeà colorduringtheclickingofthelink• Orderisimportant(LoVeHAte)

Page 14: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

MoreonKindsofSelectors

• Descendantselector• Overridethetype,class,andidselectorstyles• Typicallywithtwoelementswherethesecondisadescendant• Exampleà lia{font-size:2em}

• Universalselector• Appliestoallelements• Example:*{font-family:arial,Helvetica;}

• Pseudo-elements• Allowsyoutostyleanitemthatisnotmarkedbyelements• Twopseudo-elementexamplesà :first-letterand:first-line

Page 15: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

Someselectorexamples

• a[title]{}à Alinkwithatitleattribute• .myPrefStyle{}à AnyelementswiththeclassmyPrefStyle (sameclassnamecanappearinmanyelements)• #mySchedule {}à AnelementwithidmySchedule (onlyoneelementonthepage)• div.myPrefStyle{}à AdivwiththeclassmyPrefStyle• div#mySchedule{}à AdivwiththeidmySchedule• divtable{}à Atablewithadivancestor• input[type=“submit”]{}à Aninputwithatypeattributethathasthevaluesubmit

Page 16: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

Boxmodel

Border

Padding

Content

Margin

Marginedge

Borderedge

Paddingedge

Contentedge

Page 17: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

Boxmodel

• CSSboxmodelà boxaroundanHTMLelementwiththefollowingcomponents:margin,border,padding,content• Boxmodelallowustodefinespacebetweendifferentelements• Foursectionscanbeidentified:• Contentà whatliesinthemiddleofthebox(text,image,etc.)• Paddingà surroundsthecontent• Borderà surroundsthepaddingandrepresentstheboxborder• Marginà surroundstheborder

• Noteà Needtospecifyaborder-styleforbordertoappear

Page 18: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

Boxmodel

Border

Padding

Content

Margin

Marginedge

Borderedge

Paddingedge

Contentedge

Page 19: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

Boxmodelpaddingandmargin

• Youcanadjustindividualpadding/marginpropertiesbyusing:• padding-bottom,padding-left,padding-top,padding-right• margin-bottom,margin-left,margin-top,margin-right

• Themargins,borders,padding,andbackgroundpropertiesofblockelements(e.g.,body,p,etc.)arenotpassedtotheirchildblock-levelelements

Page 20: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

Shorthandproperty

• ShorthandPropertyà allowsyoutospecifyseveralpropertiesbyusingonlyone• Ifyoudon’tspecifyoneofthepropertiesadefaultvaluewillbeused• Commonlyusedshorthandproperties• background• font• list-style• margin• border• padding

• Exampleà border:2emsolidgreen;

Page 21: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

Backgroundproperties

• background-color• background-imageà locationofimage• background-repeatà howimagerepeats.Possiblevaluesforrepetition:• no-repeatà oneinstanceoftheimage• repeatà tile• repeat–yà repeatsonthey-axis(repeat–xà repeatsonthex-axis)

• background-attachmentà indicatesattachmentoftheimagetothecontainingelement.Possiblevaluesare:• scrollà defaultvalue• fixedà imagewillstaystationaryasthescrollingtakesplace

• background-positionà top,bottom,center,left,right(combinationsvalid)

Page 22: More CSScs115/slides/W02-02-MoreCSS.pdfBox model • CSS box model à box around an HTML element with the following components: margin, border, padding, content • Box model allow

Genericfontfamilies

• sans-serifà (e.g.,Verdana,Helvetica,Arial)• serifà (e.g.,TimesNewRoman,Georgia,Times)• monospaceà (e.g.,Courier,MSCourierNew)• cursiveà (e.g.,LucidaHandwriting)• fantasyà (e.g.,Whimsey,ComicSans)• Browsercanchooseanavailablefontfromthatfamily