Study Guide
University:
Massachusetts Institute of TechnologyCourse:
6.170 | Software StudioAcademic year:
2023
Views:
296
Pages:
19
Author:
Adelaide Ray
This is a paragraph.
Web Browsers The purpose of a web browser (such as Google Chrome, Internet Explorer, Firefox, Safari) is to read HTML documents and display them as web pages. The browser does not display the HTML tags, but uses the tags to interpret the content of the page: Screenshot of browser displaying sample heading and paragraph text removed due to copyright restrictions. Refer to: Step 4 in HTML Editors. HTML Page Structure Below is an example of HTML page structure:This is a paragraph.
This is another paragraph.
HTML Versions Since the early days of the web, there have been many versions of HTML: Version Year HTML 1991 HTML+ 1993 HTML 2.0 1995 HTML 3.2 1997 HTML 4.01 1999 XHTML 1.0 2000 HTML5 / XHTML5 2012 The Declaration The declaration helps the browser to display a web page correctly. There are many different documents on the web, and a browser can only display an HTML page 100% correctly if it knows the HTML type and version used. Declarations Before HTML5, it was common to declare the HTML version at the start with something messy: XHTML 1.0 HTML 4.01 HTML5 is much simpler, and is what we recommend you use: HTML5 Topic 2: CSS Here are screenshots of some sample P1.2's The functionality is present in all these pages, but the sites themselves are visually unappealing. (In fact, perhaps good visual design is essential to your site's functionality - e.g. people abandoned MySpace as a social networking tool since they couldn't tolerate looking at the cluttered, eye-soring profiles vs. Facebook's incredibly clean [c. 2007] layout.) Maybe we can find a way to style the pages so that our sites could look... like this! Let's look at an HTML page about whales: But this isn't the best looking page on whales. One way to style it could be by manually editing each HTML element with HTML attributes. However, now you're mixing concerns about what data should be presented and how that data should be presented in the same file. The better way is to create a separate, external file called a .css file which specifies how certain data on the whale page should be presented. What do .css files actually do? CSS stands for Cascading Style Sheets. And .css files are just that: stylesheets. Your browser has a default way of rendering certain HTML elements. But if you link an HTML page to a .css file, the browser can parse that .css file and then override its native way of rendering HTML data. CSS syntax CSS files as a regular grammar: CSS FILE ::= (RULE)* RULE ::= (SELECTOR)+ (DECLARATION)* DECLARATION ::= PROPERTY (VALUE)+ CSS files are a series of zero or more presentation rules. Here's a sample rule: (from http://w3schools.com/css/css_syntax.asp) This rule demands that content betweenelement the id "welcome". Add a presentation rule to whale.css that makes this element's content larger, Arial font, centered, and of dark blue color. For example: #welcome { font-family:Arial; font-size:36px; color: #3B6AA0; text-align: center; } Now, whale page looks like: 4. Give the whale picture element the class "whale pic". Then, using CSS, center the whale picture and give it rounded corners! For example: .whale_pic { display:block; -webkit-border-radius: 20px; -moz-border-radius: 20px; border-radius: 20px; margin-left: auto; margin-right: auto; } Note: Margin-left and margin-right are equal to 'auto' so the browser calculates the left and right margins of the .whale pic element on the fly as the browser is resized. Now whale page looks like... 5. Cool. Now let's give the page some good background color! body { background-color: #E0EEEE; } 6. Cool. Now let's style the actual text of the page. p, ul { font-family: Arial; color: #3B6AA0; } Whale page now looks like: 7. Now our whale page is marginally better looking. But wait! You now realize there's some redundancy in the CSS. We can get rid of the color and font-family declarations in the #welcome CSS rule since they're covered by the p presentation rule. Identifying and getting rid of these redundancies can allow us to write cleaner CSS. Topic 3: Specificity and the “Cascade” in CSS: So we've just seen CSS in action, but... What happens if there are rule conflicts (like if there are multiple stylesheets that target the same elements)? This is the Cascading part of the style sheets. There's a particular order of precedence for applying stylesheets (information obtained from: http://bit.ly/5uu3iX [vanseo design], http://bit.ly/bisLP [w3c css2 spec]). When applying this order of precedence, the stylesheets cascade into each other, functionally creating a new stylesheet. 1. Get all CSS declarations from all stylesheets that apply to a particular property for a particular element. 2. Break ties by origin and weight. What do you mean an origin? Your browser has a default stylesheet. A user can specify his/her own stylesheet for his/her browser (for example, if s/he needs a particular stylesheet to see the content better due to medical concerns). And then of course there are the style sheets the author of an HTML page explicitly links to. So there are three possible stylesheet origins: browser, user, and author. What do you mean by weight? When you write a declaration like h1 {color: blue;} you can add !important after the value in the declaration to specify that that particular declaration should have some overriding power. For example: h1 {color: blue !important;}. So if your HTML page links to one stylesheet that says h1 {color: red;} and another that says h1 {color: blue ! important;} then the latter rule trumps over the former. Note: !important is considered bad practice - it’s usually a sign that your original classes, IDs, and styles were not well thought out and you’re brute-forcing things. The order of precedence in terms of origin and weight is: user important overrides author important which overrides author unimportant which overrides user unimportant which overrides any browser rules. U Important >> A Important >> A Unimportant >> U Unimportant >> Browser 3. Break further ties by specificity. What do you mean by specificity? Intuition test - Assume we had an
6.170 Tutorial 5 - HTML & CSS
Get your assignment done in just 3 hours. Quick, easy, and available 24/7.
Report
Tell us what’s wrong with it:
Thanks, got it!
We will moderate it soon!
Our EduBirdie Experts Are Here for You 24/7! Just fill out a form and let us know how we can assist you.
Enter your email below and get instant access to your document