The new symbols can flip any code into comments that means the browser can ignore the road. you'll be able to comment out a lot of lines by moving the left or right comment symbols Love this:
An example of CSS comments
In the code higher than,
the last 3 lines are commented out, so that they are unheeded.
Comments ar quite helpful for reminding yourself what a specific rule will For example,
An example of CSS comments other to code Try to add comments where attainable once you come to your code a couple of weeks down the road it'll create a lot of sense if you've got other comments.
In the next lesson you will learn the way to position things with CSS.
In this section you may find out how to get out your sites exploitation CSS positioning Before doing therefore, however it helps to find out regarding one thing known as the CSS Box Model.
The CSS Box Model
An hypertext markup language page is considered a series of boxes stacked one on prime of the opposite. These boxes will hold text in paragraphs images kind objects etc every box is split up into four areas: a margin, a border, some artifact and eventually the content itself:
The margin is clear and goes round the border you cannot set a color for margins It is massive as within the image higher than or set to zero and snuggle right up against the border.
The border goes round the artifact and therefore the content. It will take a color, a size, and a border kind (dotted, solid, etc).
The artifact is that the house between the content and therefore the border. It takes an equivalent color because the background for the complete box.
The content is things like text and pictures - the entire purpose of the box.
All four areas will have their sizes set. within the code below, we've established 2 paragraphs of text:
CSS code for 2 paragraphs lightness in the box model
All we're doing is setting a height and dimension for 2 and therefore the artifact (We've additionally further a color therefore you'll be able to see what it's like within the browser.) Here's the result:
Notice the scale of the margins encompassing the border. the primary margin is thirty pixels on all four sides you'll be able to set you want:
By simply exploitation margin, though, you are setting the margin for all four sides an equivalent is true for border and padding: you'll be able to set all four right away or simply set individual values by adding prime right bottom or left.
To get the whole size of the box you add up all four parts: margin border padding content for instance within the code higher than we've got a dimension of three hundred pixels for the primary paragraph (the dimension refers to the content area).
The margin is thirty pixels on either side giving a complete margin dimension of sixty pixels The border is one pel on the left and one pel on the correct. The artifact is twenty pixels on the left and twenty pixels on the correct the whole dimension of the complete box is therefore:
Left margin thirty Right margin thirty Left border one Right border one Left artifact twenty Right artifact twenty Content dimension three hundred
Total box dimension = 402 pixels
So though we have a tendency to given a dimension worth of three hundred pixels the dimension of the box round the entire paragraph was truly 402 pixels. you wish involved this in mind once setting values like this particularly after you float components left and right. for instance, if you've got a navigation space floated left then it is a sensible plan to line the dimension worth and every one of the others values: simply bear in mind to feature up all the various sizes once shrewd the general size In the next lesson you may find out how to a add comments to your CSS code.
Two new parts area unit the HTML5 tags FIGURE and FIG
CAPTION. the primary one, FIGURE, is nice for things like pictures and
different graphics, whereas FIG CAPTION is employed to inform folks what
they're observing As Associate in Nursing example, take a glance at the
subsequent code:
A read of royalty cathedral from a street.
Here, we've enclosed the IMG code with 2 FIGURE tags. FIG
CAPTION tags area unit then place beneath the image. this is often be} what the
higher than code seems like during a browser:
You can have the FIG CAPTION tags
higher than the image.
A read of royalty cathedral from a street.
Notice, though, that the FIGURE and FIG CAPTIONS tags aren't
getting formatted for you - you have got to try and do that yourself with some
CSS:
FIG CAPTION
Because FIGURE and FIG CAPTION area unit new HTML5 tags,
older browsers will not apprehend what they're. so that they get rendered on
the page as inline tags.
What this suggests is you will not get Associate in
Nursing automatic line break for your figure captions: they'll simply be
side-by-side with the pictures. the answer is to use the CSS property show with
a worth of block. Like this:
FIGURE, FIG CAPTION
The CSS higher than tells the browser to render FIGURE and
FIG CAPTION tags as block-level parts as a result of block level parts area
unit stacked one on high of the opposite, your caption can then be within the
right place - higher than or below your pictures. (You'll learn additional
concerning block-level parts within the CSS positioning chapter later within
the course.)
But we'll leave pictures there. within the next section,
we'll take a glance at hyperlinks.
You can set your backgrounds to be pictures, if you favor.
The CSS property to use is background-image. For the worth, you specify the
placement of your image. This goes between spherical brackets and when the word
uniform resource locator. The image name is enclosed with quotation mark marks:
BODY
The same rules on image referencing you learned earlier
apply here.The higher than code, therefore, references a picture within the
same folder because the current online page.
you may place your background
pictures during a folder referred to as backgrounds. The code would then be:
BODY
The default for background pictures is for them to be
perennial. for instance, if your background image is one hundred pixels by one
hundred pixels this image are going to be derived till the entire of the screen
is stuffed. This coating will look awful. The image below shows this:
he
background image we have a tendency to used higher than was a two hundred by
two hundred gradient. it's OK going from left to right (the X direction)
however happening (in the Y direction) the coating appearance terrible!
To give you a lot of management of background coating, the
CSS property background-repeat is employed. The property will take four values
repeat-x, repeat-y and no-repeat For our gradient higher than, we wish it to
solely tile from left to right, within the X direction. therefore we want
repeat-x:
BODY
Our background would then appear as if this
Which is way
superior!Background Position
You can specify an edge for background pictures. For that
the CSS property background-position is employed. This property takes the
subsequent values:
top left
top center
top right
center left
center center
center right
bottom left
bottom center
bottom right
But you'll be able to additionally use pixels with X and Y
values. it is also potential to use a page proportion. As a sensible example,
suppose you needed a emblem within the prime right of your page you may fuck
like this:
BODY {
background-image: URL ('backgrounds logo brolly.gif');
background-position: prime right;
background-repeat: no-repeat;
}
The impact would be this:
Notice that we've used
background-repeat with a price of no-repeat, otherwise we'd get a page filled
with brollies!
Here area unit some samples of the opposite values you'll be
able to use:
background-position: 300px 100px;
background-position: eightieth 0%;
With the pel values (px) the X direction comes initial
followed by the Y direction is an area separates the 2. identical is true of
the share values: X direction initial, then Y direction, an area because the
setup.
Try them out for yourself. you will find the background
pictures within the further files that came with this course, within the
extra_files/backgrounds folder. (If you haven't got the additional the transfer
location is here, below the heading internet style - New Course : transfer the
additional Files required for this course (You do not would like the downloads
for the previous course.)
In the next lesson, you will find out about image captions.
Before we have a tendency to begin, make certain to repeat
our smaller pictures over to your york_images pictures folder, as explained
earlier. There ought to be five of those within the files you downloaded for
this course: (If you haven't got the additional files nonetheless, the transfer
location is here, beneath the heading internet style - New Course :
transfer
the additional Files required for this course (You do not would like the
downloads for the recent course.)
york_minster.jpg
york_minster_2.gif
york_minster_3.gif
york_minster_4.gif
york_minster_5.gif
The smaller ones square measure all GIF pictures.
In HTML5, image alignment is finished victimization CSS.
However, if you simply wish basic left, right or centre alignment then the DIV
tag is kind of helpful. The DIV tag is associate degree general-purpose tag.
It's somewhat just like the P tag in this you get a line break once you employ
it.
To see the DIV tag in action, amend your markup language
code to the present (we've disregarded the DOCTYPE tag at the top):
Here, we're
employing a try of DIV tags: . once an area, we've more the attribute
ALIGN="right". this may apply to something between the gap and
shutting DIV tags. For us, this can be the second of the House of York
cathedral GIF pictures.
Save your work and reload the net page in your browser. you
ought to see this:
The different 2 horizontal values for the ALIGN attribute
square measure left and center (American spelling). strive them out by deleting
"right" and replacement it with 1stthen . Save your work and see what the results square measure in your
browser. (If you simply wish left alignment then you do not would like the DIV
tags in the least, as a result of left is that the default alignment.)
The ALIGN attribute may also be used with the P tag:
Again, this may apply to something between the 2 tags,
together with tex
Now add some text on top of and below the 2 DIV tags:When
you save your work and look at the results, you ought to see this with a left
aligned image:
Notice that the DIV tags has place some house on top of and below
itself: you do not ought to add a P tag for the text. however you'll if you
wish - it is often smart apply to own your text between P tags.In the next
lesson, you will see the way to wrap text around a picture with CSS.
When you use IMG you're employing a hypertext mark-up
language tag. The SRC half is termed Associate in Nursing attribute. There
square measure immeasurable different attributes you'll be able to boost the
IMG tag. Here square measure the image attributes in hypertext mark-up language
5:
ALT
SRC
HEIGHT
WIDTH
USEMAP
ISMAP
In previous versions of hypertext mark-up language, you
furthermore may had these:
ALIGN
BORDER
HSPACE
VSPACE
However, these have currently been deprecated. you'll be
able to still use them though that, however the hypertext mark-up language five
method is to use these with CSS. you will see the way to do this shortly.
The elevation Attribute
The first attribute is elevation. you employ it like this:
ALT means that "alternative text". If the image doesn't
show then users can see the text between the quote of elevation. Try it out.
modification your hypertext mark-up language code to this:
Here, we've modified the name of the image. currently save
your work and refresh your page within the browser you ought to see this
(Internet human) Internet Explorer
has intercalary the elevation text when the
red X.
You should continuously add some elevation text to your IMG
tags because it is useful to blind and part quick-sighted users: the elevation
text are scan out elevation text is additionally helpful for search engines,
particularly Google's image search.
Height and breadth Attributes
Another issue you'll be able to do with the Image tag is
specify a replacement height and breadth. This one is sort of simple.
modification your image tag to the current (we've left the elevation tag off):
The original image was 2048 pixels high by 1536 pixels wide.
By ever-changing the peak and breadth, we are able to decrease the scale of the
image. The image itself can still take a similar quantity of your time to load
into a browser as a result of we've not modified the scale of the JPEG file.
All we've done is to vary the peak and breadth attributes of the IMG tag.
This, however, wouldn't be sensible on the web, as a result
of the scale of the JPEG file would not modification. All you may do is assign
a lot of transfer time to induce a smaller image. thus once ever-changing image
size with the peak and breadth attributes, go up in size and not down, as we've
got done here. If your pictures square measure too massive, use image redaction
code to scale back the peak and breadth.
The USEMAP Attribute
The USEMAP attribute is employed to show specific areas of a
picture into clickable links. Take the image below, for instance. we do not
wish the total of the image to be a link, simply the colored shapes.
If you hold
your mouse over the gray areas then nothing happens - your mouse pointer will
not modification. Hold your mouse over a form however and also the mouse pointer
changes to point that it is a link. this can be all through with the USEMAP
attribute The hypertext mark-up language code with a USEMAP attribute appears
like this:
After the attribute USEMAP comes Associate in Nursing equal
sign, then the name of your map, preceded by a hash/pound image. The name of
the map are often something you prefer.
Once you've got a map name, you wish a map to travel with it
Take a glance at this code, thatthe map
for our shapes image above:So you've got 2 MAP tags a begin associated an
finish one of the primary MAP tag takes a reputation attribute. this is often
the USEMAP name from your IMG code. In between the 2 MAP tags you would like a
minimum of one space tag. the realm tag takes attributes of its own form
COORDS, and HREF. The shapes you'll be able to have area unit RECT (short for
rectangle), CIRCLE, and POLY (short for polygon).
every form wants some
coordinates For any rectangular space of your image you would like the
coordinates of the highest left corner in pixels. Ours was thirty seven and
twenty five. this implies thirty seven pixels from the left fringe of the image
itself (the X direction), and twenty five pixels down from the highest of your
image (the Y direction). the lowest right of our parallelogram was 137 pixels
within the X direction and seventy two within the Y direction.
For a circle, you would like the X and Y values for the
centre of your circle You live from the left of the total image not the left
fringe of the circle For the Y direction, you live from the highest of your
image The third coordinate you would like for a circle is that the radius (half
the diameter).
For a polygonal shape, you would like X and Y coordinates
for every purpose. Our polygonal shape could be a triangle therefore has associate
X and Y worth for every of the 3 points.
The HREF attribute is that the online page a traveller is
taken to once a region on the map is clicked. We've written a # image. this
implies "don't go anyplace - be a similar page".
In the next section, you'll find out how to govern pictures
with CSS.
In the previous section, you study relative file referencing
during this section we'll continue the lesson with some sensible work.
Navigate to wherever on your drive you saved your HTML
pages. For us, this was a folder known as HTML inside the HTML folderproduce 2 additional. decision one in every
of the folders pictures and therefore the alternative pages. If you are
employing a Windows pc your someone window can then seem like this (Windows
7):
Double click your guide document and add the subsequent HTML image
code:
Click File > Save As and save your guide as a HTML file. however
reserve it in your new pages folder, and decision it pictures.HTML. remember to
vary the Save as sort box to all or any Files if you are victimization Windows:
Once you've got saved your guide as a HTML website, double click it to open it
up in your browser. you ought to see this, if you're victimization Firefox::
If
you're victimization net someone, however, you ought to see this:
In each cases,
the image has not displayed. Firefox displays a broken file icon, and net
someone displays a red X icon. the rationale is that the browser cannot realize
the file thus if you see either of these icons in future, simply keep in mind
that the browser is telling you "Image File Not Found".
To solve this drawback, we've some files for you. The file
you wish is within the extra_files folder that came with this:
course. (If you
haven't got the additional files nonetheless, the transfer location is here,
below the heading internet style - New Course : transfer the additional Files
required for this course (You do not want the downloads for the previous
course.)
Double click the extra_files folder, then double click it
into your HTML/pages folder. Your pages folder can then seem like this:The
image and therefore the website square measure within image we'd wish to appear
into this.
Once you've got derived. you ought to see the image
appear:
If you do not see a picture, however still have the "Image File:
SRC="york_minster.jpg"
Note the minuscule orthography, and therefore the 2 double
quote marks. a typical error is to spell SRC as SCR. Make sure, too, that the
image and therefore the website square measure within the same folder.
Once you get the image displayed within the browser, produce
another folder within the pages folder. decision this one york_images. Your
someone window ought to then seem like this:
Now move someone window can then
seem like this:
Reload your website in your browser. you ought to see the
"Image Not Found" icon once more.
Go back to your HTML code and alter the IMG line to this:
So we've accessorize within the same directory because the
HTML page. once the forward slash, we've the image name. What we're language
here is, "In constant folder because the pictures.HTML page, explore for a
folder known as york_images.
Save your work and reload the photographs.HTML website in
your browser. you ought to see the image re-emerge.Advanced file referencing
Previously, you created Associate in Nursing pictures folder
and a pages folder. This:For neatness sake, this is often an honest idea:
you'll be able to have most of your HTML pages within the pages folder, and
every one your photos within the pictures folder.
(We say most of your HTML
pages as a result of there's Associate in Nursing exception known as the
index.HTML page. you may study this a little later.)
One issue concerning this approach is that file referencing
becomes lots more durable. Suppose we have a tendency to affected the
york_images folder inside the photographs folder. If we did, the code we have a
tendency to wrote before would now not work. This line:
That's as a result of there would now not be a folder known
as york_images within the same location because the pictures.HTML file. The
image is currently one folder up from the pages folder. The code would thus be
this:
After SRC we have a tendency to currently have 2 dots and a
forward slash. 2 dots and a forward slash mean "go up one folder from the
photographs.HTML page, wherever the code is.) The browser can then explore for
a folder known as pictures. it'll search this folder for one known as york_images.
Then it'll explore for the image such.
Don't worry if all that's not too clear: we'll keep pictures
and image folders along, only for simplicity's sake. however if you are still
unsure concerning file referencing, we've made a video for you here: File
Referencing Video.
In the next lesson, you may study Image Attributes.