- For each of these pairs of hex color components, which component is
larger? Recall that hex digits can have any one of 16 values:
0 1 2 3 4 5 6 7 8 9 A B C D E F
The digits 0 through 9 have the same values as their corresponding
base 10 digits. The digits A through F
represent the values 10 through 15
(A==10, B==11, C==12, D==13, E==14, F==15)
(05,09) (0C,05) (45,3A)
(98,D2) (B8,BC) (FA,BE)
Answer: 05<09 0C>05 45>3A 98<D2 FA>BE
Remember that for a two digit hex (base 16) number, the left digit is the
sixteens place and the right digit is the ones place. BE
represents the number B*16 + E = 11*16 + 14 = 190. The way you
compare 2 two-digit hex numbers is to first look at the left digits. The
number with the larger hex digit is larger. If the left digits are equal,
the number with the larger right digit is larger. If both digits are
equal, obviously the two numbers are the same and equal.
- What is the difference between an attribute and a property?
Answer: an attribute is part of an HTML element, for example:
<img id="img1" src="mypic.jpg">
id and src are properties of the
img element.
Let image1 be the JavaScript object defined by
var image1 = document.getElementById("img1");
If we set
image1.src = "andromeda.jpg";
src is a property of the JavaScript img object
image1.
- Display an image element on an HTML page with width:300px and
height:200px.
However, wait to display the image file until the image element is clicked.
Your image element should work something like this:
Answer:
The index file with HTML, CSS, and JavaScript all in the same file. There are
two solutions presented here: (1) the traditional solution setting event handler
by using the onclick attribute of the button, and (2) the modern solution that
creates a JavaScript button object and attaches an event handler to the button
object like this:
var image1 = document.getElementById("img1");
image1.addEventListener("click", showImage);
Solution 1 (traditional solution):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Display Image</title>
<style>
body { background-color: aliceblue;
color: navy; }
img { width: 300px;
height: 200px; }
</style>
<script>
function showImage( ) {
var image1 = document.getElementById("img1");
image1.src = "images/andromeda.jpg";
}
</script>
</head>
<body>
<h1>Display Image</h1>
<img id="img1" onclick="showImage( )">
</body>
</html>
Solution 2 (modern solution):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Display Image</title>
<style>
body { background-color: aliceblue;
color: navy; }
img { width: 300px;
height: 200px; }
</style>
<script>
function showImage( ) {
var image1 = document.getElementById("img1");
image1.src = "images/andromeda.jpg";
}
function init( ) {
var image1 = document.getElementById("img1");
image1.addEventListener("click", showImage);
}
window.addEventListener("load", init);
</script>
</head>
<body>
<h1>Display Image</h1>
<img id="img1">
</body>
</html>
- Show how to use this CSS class:
.large-red { font-size: 200%; color: red; }
Answer: apply this CSS class to an h2 tag like this:
<h2 class="large-red">Text of the h2 Header Element</h2>
- Read the CSS Shorthand Styles section in the Jan 11 Notes (or look up this topic
in W3Schools). Then rewrite these CSS styles as shorthand styles.
/* Style a */
p { font-family: arial, sans-serif;
font-size: 20px;
font-weight: bold; }
/* Answer: */
p { font: bold 20px arial, sans-serif; }
/* Style b */
img { padding-bottom: 20px;
padding-top: 10px;
padding-left: 25px;
padding-right: 15px; }
/* Answer: */
img { padding: 10px 15px 20px 15px; }
With four distances, start at the top and proceed clockwise: top, east, south, west.
/* Style c */
img { border-width: 10px;
border-style: solid;
border-color: red; }
/* Answer: */
img { border: 10px solid red; }