-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new HTML Template Element example with header and footer
- Created a new example demonstrating the HTML <template> element - Added index.html with a button to add list items using the template - Included header and footer to match the site style - Updated main.css to include styles for the header and footer - Added main.js to handle the dynamic addition of list items
- Loading branch information
1 parent
d92296e
commit 47768a9
Showing
4 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* Styles for HTML Template Example */ | ||
#itemList { | ||
list-style-type: none; | ||
padding: 0; | ||
} | ||
|
||
#itemList li { | ||
background-color: #f0f0f0; | ||
margin-bottom: 5px; | ||
padding: 10px; | ||
} | ||
|
||
header, footer { | ||
border-bottom: 1px solid #eee; | ||
margin-bottom: 20px; | ||
padding-bottom: 10px; | ||
text-align: center; | ||
} | ||
|
||
footer { | ||
border-top: 1px solid #eee; | ||
margin-top: 20px; | ||
padding-top: 10px; | ||
} | ||
|
||
h1 { | ||
font-size: 24px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!DOCTYPE html> | ||
|
||
<html lang="en"> | ||
|
||
<head> | ||
<title>HTML Template Element</title> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="stylesheet" href="../css/main.css"> | ||
<script src="js/main.js" defer></script> | ||
</head> | ||
|
||
<body> | ||
<div id="container"> | ||
<header> | ||
<h1><a href="https://simpl.info">simpl.info </a>HTML.Template.Element</h1> | ||
</header> | ||
|
||
<main> | ||
<p>This example demonstrates how to use the HTML <code><template></code> element.</p> | ||
|
||
<button id="add">Add Item</button> | ||
|
||
<ul id="itemList"></ul> | ||
|
||
<template id="itemTemplate"> | ||
<li>Item</li> | ||
</template> | ||
</main> | ||
|
||
<footer> | ||
<a href="https://github.com/samdutton/simpl/blob/master/template/index.html" title="View source for this page on GitHub" id="viewSource">View source on GitHub</a> | ||
</footer> | ||
|
||
</div> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const addButton = document.getElementById('add'); | ||
const itemList = document.getElementById('itemList'); | ||
const itemTemplate = document.getElementById('itemTemplate').content; | ||
|
||
addButton.addEventListener('click', () => { | ||
const newItem = itemTemplate.cloneNode(true); | ||
itemList.appendChild(newItem); | ||
}); | ||
}); | ||
|