If you run the Web page, you will see that the elements on the list will use the familiar hyperlink style, which is the so-called blue underline:
The next thing you'll do is add headers and footers to the page. You will use the new
<! DOCTYPE html>
As you can see, they are very simple HTML code.
For the header, we'll create the
To view the Web page in a browser, it will now resemble the following interface:
In addition to the footer, it's not much different, but don't worry, this situation will soon change!
Define the appearance of a Web page
In the previous section, when you introduced the anchor tag, you learned about properties that describe the behavior of the element. For anchor tags, you define the behavior that occurs when you click by specifying the HREF attribute.
As you can imagine, you can use attributes to specify the appearance of an element, including font style, font size, color, border, and so on.
So, for example, for the
You can see that the style property of the,
While this works well, it's not the best way to set a page style. Imagine what the result would be if you had to set the style of each element in this way. There will eventually be a lot of text on your page, slowing down the download and browsing speed.
Fortunately, there is another way to use style sheets on a Web page. Style sheets are defined using cascading style sheet concepts, where the set of styles on an element can be inherited by child elements. For example, if you set a style on <div> and <div> has child elements <ol> and <li>, the style will also be applied to them unless the developer overrides the style. W3cschools is a great place to learn about CSS: http://w3schools.com/css/default.asp.
Let's look at how to define a style on the
Instead of putting all of the style code inside the
<H1 class= "Title" >a List of my favorite movies
Now that the tag has a class, we can tell the browser to use a particular style for all the content that owns the class. This is done using CSS code syntax, similar to the following:
. Title { font-size:xx-large; Font-weight:normal; padding:0px; margin:0px; }
The style "language" includes a set of semicolon-delimited and enclosed curly braces ({...} ) in the properties. If you want to apply this style to a class, the class is defined using the point syntax, which is to add a point before the class name.
This code is placed inside the <style> tag in the page header. Your page tag should look similar to:
<! DOCTYPE html>
When you run it, the style will take effect and you will see the following interface:
Keep in mind that
When you want to set a specific element, you can use a class for that element (assuming that the class has only one instance), or you can use an ID to name the element, and then set the class for that ID. If you look at your HTML, you'll notice that the movie list is saved in a <div> with an ID of "movieslist". You can set its style by adding # before "Movieslist" in the style sheet definition, as follows:
#movieslist {Font-family:geneva, Tahoma, Sans-serif;}
This defines the styles for <div>, and any element in this div will apply this style because the style sheets can be cascaded (just give them the name). So, even if I don't have a style that specifically sets the <li> element that contains the text, the style is still applied:
Keep in mind that the browser by default renders the <li> objects in the <ol> list as numbered items. We can set styles to delete numbered items. Because these objects are inside the div we call "movieslist", we can easily access them to change their style.
Here's the syntax:
#movieslist ol { list-style:none; margin:0; padding:0; Border:none; }
This syntax indicates that for each <ol> in #movieslist, the style is set to not a list (that is, there are no bullets), no margins, no borders, and no padding.
The following is the result of the setting:
As you can see, there is no number now.
The text for each list item is saved in a <a> tag, so we can use the following syntax to define the appearance of each <a> tag within each <li> tag in #movieslist:
#movieslist Li a { font-size:large; Color: #000000; Display:block; padding:5px; }
The settings here are self-explanatory, so let's look at how the page looks when it runs.
The above is WebMatrix Advanced Tutorial (3): How to implement a certain style of content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!