Mysuccess Website Designer Associate Version 2.0
Total Page:16
File Type:pdf, Size:1020Kb
MySuccess Website Designer Associate Version 2.0 Topic 6 – Getting Started with CSS In this Lesson • Introduction • Separating content from presentation. • Placing CSS. • CSS Selectors • Selectors. • Practical CSS • Styling headings. • Styling lists. • Styling links. • Styling tables. • Styling DIVs. • Styling images and videos. • Styling forms. MySuccess Website Designer Associate | Copyright © 2013-2017 ICE Malta | Topic 6 | Slide 2 Introduction Placing CSS • CSS consists of creating a block of rules. • Each block applies to one or more elements in a page. • The blocks then consist of rules which modify the appearance of the element. • The elements can be selected by their element type, their id or their class name. • CSS can be added inline with an element, it can be embedded in an HTML file or it can be placed in an external file. MySuccess Website Designer Associate | Copyright © 2013-2017 ICE Malta | Topic 6 | Slide 4 Example CSS Placement • With inline placement, you specify the rules for an element in a style attribute of that element: <h4 style="color: red">Redundant Language</h4> • This will make just this particular <h4> red. • With embedded placement, CSS rules are specified inside a <style> block somewhere on the page. <style> h4 { color: red; } </style> • This will make all <h4> headers on this page red. • The best practice is to have CSS in a separate file, and then link to this file from the pages that need it. This allows the CSS to remain in one place, and changing this CSS will apply changes throughout the whole site. MySuccess Website Designer Associate | Copyright © 2013-2017 ICE Malta | Topic 6 | Slide 5 Selectors Selectors • A selector is used to choose an element from the page (called the DOM). • Style rules are then applied to the selector. • CSS have several selectors, the basics being: Selector Example Description element p Selects an HTML tag .class .articleHeader Selects an element by its class attribute #id #firstArticle Selects an element by its id <h1>A header</h1> <div class="article"></div> <p id="terms"></p> h1 { .article { #terms { … … … } } } MySuccess Website Designer Associate | Copyright © 2013-2017 ICE Malta | Topic 6 | Slide 7 Selectors Note • You should use classes when there is more than one item with that class in the page (such as an article in a blog). • You should use IDs when there is only one item with that id in the page (such as the page header). MySuccess Website Designer Associate | Copyright © 2013-2017 ICE Malta | Topic 6 | Slide 8 CSS 1/2 Selectors Selector Example Example Description element p Selects all <p> elements .class .articleHeader Selects the element with the ‘articleHeader’ class #id #firstArticle Selects the element with the ‘firstArticle’ id * * Selects all elements element, element div, p Selects all <div> and all <p> elements element element div p Selects all <p> elements inside <p> elements element > element div > p Selects all <p> elements where the parent is a <div> element element + element div + p Selects all <p> elements that are placed immediately after <div> elements [attribute] [target] Selects all element with a target attribute [attribute=value] [target=_blank] Selects all element with a target attribute value set to ”_blank” [attribute |= value] [lang |= en] Selects all element with a lang attribute value starting with “en” [attribute ~= value] [title ~= flower] Selects all elements with a title attribute containing the word “flower” :active a:active Selects the active link ::after p::after Insert something after the content of each <p> element ::before p::before Insert something before the content of each <p> element MySuccess Website Designer Associate | Copyright © 2013-2017 ICE Malta | Topic 6 | Slide 9 CSS 1/2 Selectors Selector Example Example Description :first-child p:first-child Selects every <p> element that is the first child of its parent ::first-letter p::first-letter Selects the first letter of every <p> element ::first-line p::first-line Selects the first line of every <p> element :focus input:focus Selects the input element which has focus :hover a:hover Selects links on mouse over :lang(language) p:lang(it) Selects every <p> element with a lang attribute equal to “it” (Italian) :link a:link Selects all unvisited links :visited a:visited Selects all visited links MySuccess Website Designer Associate | Copyright © 2013-2017 ICE Malta | Topic 6 | Slide 10 Practical CSS Practical CSS • Let’s create some CSS for Joe’s Blog. • Add a new folder to the site called ‘styles’, and create a ‘styles.css’ file inside. • Before we start using this file, we have to tell the pages of our site to use this styles file – we can easily do this by adding a reference to the file in the site template. • Open normal.dwt and add a link in the <head> section. <head> <meta charset="UTF-8"> <!-- TemplateBeginEditable name="doctitle" --> <title>Home</title> <!-- TemplateEndEditable --> <link rel="stylesheet" href="../styles/styles.css"> <!-- TemplateBeginEditable name="head" --> <!-- TemplateEndEditable --> </head> MySuccess Website Designer Associate | Copyright © 2013-2017 ICE Malta | Topic 6 | Slide 12 Practical CSS • Let’s start by adding some rules common to all elements. * { font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, "sans-serif"; font-size: 10pt; } • The font-family rule specifies a list of fonts to try and use on the browser. • If the first font is not available, the second one is tried, and so on. • Dreamweaver will suggest suitable fonts for you – the best fonts for web are sans-serif fonts. • The second rule specifies a default font size. MySuccess Website Designer Associate | Copyright © 2013-2017 ICE Malta | Topic 6 | Slide 13 Styling Headers • Now let’s add some style to the headers. /** Header Styles **/ h1 { font-size: 24pt; } h3 { font-style: italic; font-size: 14pt; margin-left: 40px; text-transform: capitalize; line-height: 0.5; } h4 { font-size: 12pt; } • Looking better already! • Styling headers is very much the same as styling text, with a number of rules available, shown in the next slide. MySuccess Website Designer Associate | Copyright © 2013-2017 ICE Malta | Topic 6 | Slide 14 Text Styling Properties Property Description color Sets the colour of text direction Specifies the text direction/writing direction letter-spacing Increases or decreases the space between characters in text line-height Sets the line height text-align Specifies the horizontal alignment of text text-decoration Specifies the decoration (underline, strike through, overline…) added to text text-shadow Specifies the shadow effect added to text text-transform Controls the capitalisation of text text-overflow Specifies how overflowed content that is not displayed should be signaled to the user (for example: hidden, or with scroll bars). unicode-bidi Used together with the direction property to set or return whether the text should be overridden to support multiple languages in the same document vertical-align Sets the vertical alignment of an element white-space Specifies how white-space inside an element is handled word-spacing Increases or decreases the space between words in text MySuccess Website Designer Associate | Copyright © 2013-2017 ICE Malta | Topic 6 | Slide 15 Styling Lists • We want to use different bullets for the lists in our page. • The list-style-type property can be used to change the type of bullet displayed in unordered lists or the type of number displayed in ordered lists. • A full list of supported types can be found here. ul { list-style-type: square; } Property Description list-style Sets all the properties for a list in one rule list-style-image Specifies an image as the list-item marker list-style-position Specifies if the list-item markers should appear inside or outside the content flow list-style-type Specifies the type of list-item marker MySuccess Website Designer Associate | Copyright © 2013-2017 ICE Malta | Topic 6 | Slide 16 Styling Links • A link has four states: • a:link – a normal, unvisited link. • a:visited – a link that the user has previously visited. • a:hover – a link underneath the mouse cursor. • a:active – a link, the moment it is clicked. • Ok, so let’s style the links. /** Links **/ a:link { text-decoration: none; color: #158ABE; } a:visited { text-decoration: none; color: #158ABE; } a:hover { text-decoration: underline; color: #158ABE; } a:active { text-decoration: underline; color: red; } MySuccess Website Designer Associate | Copyright © 2013-2017 ICE Malta | Topic 6 | Slide 17 Styling Tables • Next up, the table. • Let’s use some professional styling here to get a really nice table. • Check out codepen for the full example. • The following styles are for the table header: 44: Text colour 43 th { 44 color:#D5DDE5;; 45: Background colour 45 background:#1b1e24; 46 border-bottom:4px solid #9ea7af; 46: Grey bar at the bottom of the header row 47 border-right: 1px solid #343a45; 48 font-size:15px; 47: Border at the right of header bar 49 font-weight: 100; 48: Font size. 50 padding:14px; text-align:left; 51 49: Font weight (specific value). 52 text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1); 53 vertical-align:middle; 50: Cell padding. 54 } 51: Horizontal text alignment. 52: Text shadow (size and colour). 53: Vertical alignment MySuccess Website Designer Associate | Copyright © 2013-2017 ICE Malta | Topic 6 | Slide 18 Styling Tables • In the previous CSS, we specified the ’padding’ value. The padding is part of the CSS box model. • Content: The text in the cell. • Padding: space between the text and the border. • Border: The border width and colour. • Margin: Space between the border and other elements. MySuccess Website Designer Associate | Copyright © 2013-2017 ICE Malta | Topic 6 | Slide 19 Styling Tables • The header row is done, now let’s style the other rows. 56 tr { A row 57 border-top: 1px solid #C1C3D1; 58 border-bottom: 1px solid #C1C3D1; 57, 58: Border of a row 59 color:#666B85; 60 font-size:12px; 59: Text colour font-weight:normal; 61 60: Text size 62 text-shadow: 0 1px 1px rgba(256, 256, 256, 0.1); 63 } 61: Text weight (normal – not bold).