HTML Code:
<!DOCTYPE html><!-- Declares the document type and version of HTML -->
<html><!-- Begins the HTML document -->
<head><!-- Contains metadata and links to external resources -->
<title>How to specify where to navigate when using the arrow keys</title><!-- Sets the title of the document -->
<style type="text/css"> /* Starts CSS styling */
button { /* Selects all button elements */
position: absolute; /* Sets the position of the buttons to absolute */
} /* Ends the button styling */
button#w3r1 { /* Selects the button with id "w3r1" */
top: 20%; left: 25%; /* Sets the position of the button */
nav-index: 1; /* Specifies the navigation index of the button */
nav-right: #b2; nav-left: #b4; /* Specifies the element to navigate to when pressing the right or left arrow keys */
nav-down: #b2; nav-up: #b4; /* Specifies the element to navigate to when pressing the down or up arrow keys */
color: #3333CC; /* Sets the color of the button */
} /* Ends the styling for button#w3r1 */
button#w3r2 { /* Selects the button with id "w3r2" */
top: 40%; left: 50%; /* Sets the position of the button */
nav-index: 2; /* Specifies the navigation index of the button */
nav-right: #b3; nav-left: #b1; /* Specifies the element to navigate to when pressing the right or left arrow keys */
nav-down: #b3; nav-up: #b1; /* Specifies the element to navigate to when pressing the down or up arrow keys */
color: #3333CC; /* Sets the color of the button */
} /* Ends the styling for button#w3r2 */
button#w3r3 { /* Selects the button with id "w3r3" */
top: 70%; left: 25%; /* Sets the position of the button */
nav-index: 3; /* Specifies the navigation index of the button */
nav-right: #b4; nav-left: #b2; /* Specifies the element to navigate to when pressing the right or left arrow keys */
nav-down: #b4; nav-up: #b2; /* Specifies the element to navigate to when pressing the down or up arrow keys */
color: #3333CC; /* Sets the color of the button */
} /* Ends the styling for button#w3r3 */
button#w3r4 { /* Selects the button with id "w3r4" */
top: 40%; left: 0%; /* Sets the position of the button */
nav-index: 4; /* Specifies the navigation index of the button */
nav-right: #b1; nav-left: #b3; /* Specifies the element to navigate to when pressing the right or left arrow keys */
nav-down: #b1; nav-up: #b3; /* Specifies the element to navigate to when pressing the down or up arrow keys */
color: #3333CC; /* Sets the color of the button */
} /* Ends the styling for button#w3r4 */
</style><!-- Ends CSS styling -->
</head><!-- Ends the head section -->
<body><!-- Begins the body of the document -->
<p>w3resource Tutorial</p><!-- Paragraph element with text content -->
<button id="w3r1">Button 1</button><!-- Button element with id "w3r1" -->
<button id="w3r2">Button 2</button><!-- Button element with id "w3r2" -->
<button id="w3r3">Button 3</button><!-- Button element with id "w3r3" -->
<button id="w3r4">Button 4</button><!-- Button element with id "w3r4" -->
</body><!-- Ends the body section -->
</html><!-- Ends the HTML document -->
Explanation:
Live Demo:
See the Pen nav-index-answer by w3resource (@w3resource) on CodePen.
See the solution in the browser
Supported browser
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4