HTML, CSS์ ์ด์ด Javascript ๊ธฐ์ด๋ฅผ ํ์ตํ ํ ์์ ๋ฅผ ํ์ด๋ณด์์ต๋๋ค.
์๋ ๋งํฌ์์ ์ตํ๋จ์ Quiz๋ฅผ ์ง์ ๊ตฌํํ์ต๋๋ค.
์ค์ต ์์ ๋ชจ์ | ์๋ฐ์คํฌ๋ฆฝํธ ๊ธฐ์ด
Quiz-1) ๋ฉ์ธํ๋ฉด ํญ ๋ฉ๋ด ๊ตฌํ
html ์ฝ๋
๊ธฐ๋ณธ HTML ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ด ์์ฑ ํฉ๋๋ค.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="About" class="content">
<h1>About</h1>
<p>Custom Software Development Company</p>
</div>
<div id="Products" class="content">
<h1>Products</h1>
<p>Building tailored software to address critical needs of global enterprises.</p>
</div>
<div id="Technology" class="content">
<h1>Technology</h1>
<p>Machine Learning, Artificial Intelligent, Cloud Platform.</p>
</div>
<div id="Downloads" class="content">
<h1>Downloads</h1>
<p>You can download a free 10 days trial.</p>
</div>
<button id="default" class="tab" onclick="openMenu('About', this, 'tomato')">About</button>
<button class="tab" onclick="openMenu('Products', this, 'darkolivegreen')">Products</button>
<button class="tab" onclick="openMenu('Technology', this, 'dodgerblue')">Technology</button>
<button class="tab" onclick="openMenu('Downloads', this, 'orange')">Downloads</button>
<script>
</script>
</body>
</html>
css ์ฝ๋
๊ธฐ๋ณธ CSS ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ด ์์ฑ ํฉ๋๋ค. ์ธ๋ถ CSS ํ์ผ ํน์ ์๋ฒ ๋๋ CSS ๋ก ์์ฑํ ์ ์์ต๋๋ค.
/* tab button */
.tab {
background-color: #555;
color: white;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
font-size: 17px;
width: 25%;
}
/* change background color when mouse over */
.tab:hover {
background-color: #777;
}
/* default content */
.content {
color: white;
display: none;
padding: 50px;
text-align: center;
}
/* Style each tab content individually */
#About { background-color: tomato; }
#Products { background-color: darkolivegreen; }
#Technology { background-color: dodgerblue; }
#Downloads { background-color: orange; }
openMenu() ํจ์
๊ฐ๊ฐ์ ํญ์ด ํด๋ฆญ๋์์๋ ํธ์ถ๋๋ ํจ์๋ก ์คํํ ํ์ผ์ id, ํธ์ถํ๊ฐ์ฒด(this), ๋ณ๊ฒฝํ tab์์ ์ ์ธ์๋ก ๊ฐ์ง๋ค.
function openMenu(target, seltab, color) {
}
์ฝ๋
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="js-quiz1.css">
</head>
<body>
<div id="About" class="content">
<h1>About</h1>
<p>Custom Software Development Company</p>
</div>
<div id="Products" class="content">
<h1>Products</h1>
<p>Building tailored software to address critical needs of global enterprises.</p>
</div>
<div id="Technology" class="content">
<h1>Technology</h1>
<p>Machine Learning, Artificial Intelligent, Cloud Platform.</p>
</div>
<div id="Downloads" class="content">
<h1>Downloads</h1>
<p>You can download a free 10 days trial.</p>
</div>
<button id="default" class="tab" onclick="openMenu('About', this, 'tomato')">About</button>
<button class="tab" onclick="openMenu('Products', this, 'darkolivegreen')">Products</button>
<button class="tab" onclick="openMenu('Technology', this, 'dodgerblue')">Technology</button>
<button class="tab" onclick="openMenu('Downloads', this, 'orange')">Downloads</button>
<script>
document.getElementById('default').click();
function openMenu(target, seltab, color) {
var contents = document.getElementsByClassName("content");
var tabs = document.getElementsByClassName("tab");
for( var i = 0; i < contents.length; i++ ){
var content = contents.item(i);
content.style.display = "none";
}
for( var i = 0; i < tabs.length; i++ ){
var tab = tabs.item(i);
tab.style.background = "#555";
}
document.getElementById(target).style.display = "block";
seltab.style.backgroundColor = color;
}
</script>
</body>
</html>
css
๋ฌธ์ ์ ๋์์๋ ์ฝ๋์ ๋์ผํฉ๋๋ค.
๊ฒฐ๊ณผ
css ์ฝ๋ ์ค์์ ์๋ ์ฝ๋ ๋ถ๋ถ์ด ์ ์ฉ๋์ง ์๋ ๋ฌธ์ ๊ฐ ์์์ต๋๋ค.
๋ง์ฐ์ค๋ฅผ ํญ์ ์น์์ ๋ ํญ์ ๋ฐฐ๊ฒฝ ์์์ด ํ์์ผ๋ก ๋ฐ๋๋ ๋ถ๋ถ์
๋๋ค.
/* change background color when mouse over */
.tab:hover {
background-color: #777;
}
์์นญํด๋ณด๋ javascript ์ฝ๋์์ ์ฐ์ ์์ ๋ฌธ์ ๋๋ฌธ์ background-color
๊ฐ ๋ฐ์๋์ง ์๋ ๊ฒ ๊ฐ์์ต๋๋ค.
javascript ์ฝ๋์๋ ํญ์ background-color
๋ฅผ ๋ณ๊ฒฝํด์ผํ๋ ๋ถ๋ถ์ด ์์๋๋ฐ, ์ด๋ ๊ฒ css ์ฝ๋์ ๊ฒน์น ๊ฒฝ์ฐ css ์ฝ๋๊ฐ ๋ฌด์๋๋ ๋ด
๋๋ค.
javascript ์ฝ๋๋ฅผ ์์ ํ๋ฉด์ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์๋ ์์์ง๋ง, quiz์์ ์๊ตฌํ๋ ๋ฐฉ์์ด ์๋ ๊ฒ ๊ฐ์์ ์์ ํ์ง ์์์ต๋๋ค.
๊ฒฐ๊ณผ ํ์ธ ์ ์ฐธ๊ณ ๋ฐ๋๋๋ค.
Quiz-2) ์ด์ฝ๋์ธ UI ๊ตฌํ
html ์ฝ๋
๊ธฐ๋ณธ HTML ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ด ์์ฑ ํฉ๋๋ค.
<!DOCTYPE html>
<html>
<head>
<style>
.accordion {
background-color: #eee;
color: #444;
cursor: pointer;
padding: 18px;
width: 80%;
border: none;
outline: none;
font-size: 15px;
transition: 0.4s;
}
.accordion:hover {
background-color: #ccc;
}
.panel {
padding: 0 18px;
background-color: white;
max-height: 0;
width: 80%;
overflow: hidden;
transition: max-height 0.2s ease-out;
}
</style>
</head>
<body>
<div align=center>
<h2>Accordion</h2>
<hr>
<button class="accordion">Section 1</button>
<div class="panel" align=left>
<p>Lorem ipsum dolor sit amet...</p>
</div>
<button class="accordion">Section 2</button>
<div class="panel" align=left>
<p>Lorem ipsum dolor sit amet...</p>
</div>
<button class="accordion">Section 3</button>
<div class="panel" align=left>
<p>Lorem ipsum dolor sit amet...</p>
</div>
<script>
</script>
</div>
</body>
</html>
์ด์ฝ๋์ธ ์์ ๋์์ธ
์ด์ฝ๋์ธ ์์๋ฅผ ๊ตฌํํ๋ ๋ฐฉ๋ฒ์ ๋ค์ํ์ง๋ง ์ฌ๊ธฐ์๋ ๋ค์๊ณผ ๊ฐ์ด button, div ์ ๊ตฌ์กฐ๋ฅผ ์ฌ์ฉํฉ๋๋ค.
<button class="accordion">Section 1</button>
<div class="panel" align=left>
<p>Lorem ipsum dolor sit amet...</p>
</div>
์ฝ๋
html
<!DOCTYPE html>
<html>
<head>
<style>
.accordion {
background-color: #eee;
color: #444;
cursor: pointer;
padding: 18px;
width: 80%;
border: none;
outline: none;
font-size: 15px;
transition: 0.4s;
}
.accordion:hover {
background-color: #ccc;
}
.panel {
padding: 0 18px;
background-color: white;
max-height: 0;
width: 80%;
overflow: hidden;
transition: max-height 0.2s ease-out;
}
</style>
</head>
<body>
<div align=center>
<h2>Accordion</h2>
<hr>
<button class="accordion">Section 1</button>
<div class="panel" align=left>
<p>Lorem ipsum dolor sit amet...</p>
</div>
<button class="accordion">Section 2</button>
<div class="panel" align=left>
<p>Lorem ipsum dolor sit amet...</p>
</div>
<button class="accordion">Section 3</button>
<div class="panel" align=left>
<p>Lorem ipsum dolor sit amet...</p>
</div>
<script>
var accordion = document.getElementsByClassName("accordion");
for (var i = 0; i < accordion.length; i++) {
accordion[i].addEventListener("click", function () {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.maxHeight) {
panel.style.maxHeight = null;
} else {
panel.style.maxHeight = panel.scrollHeight + "px";
}
});
}
</script>
</div>
</body>
</html>
๊ฒฐ๊ณผ
'๐ Study > Web Front-End Basic' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[4-6์ฃผ์ฐจ] ์์ ์คํธ๋ฆฌ๋ฐ ์๋น์ค FLO ์น ์ฌ์ดํธ ํด๋ก ์ฝ๋ฉ (0) | 2024.07.18 |
---|---|
[2์ฃผ์ฐจ] CSS ์์ ์ค์ต (0) | 2024.07.18 |
[2์ฃผ์ฐจ] CSS ํด์ฆ ํ์ด (0) | 2024.07.18 |
[1์ฃผ์ฐจ] HTML ์์ ์ค์ต (0) | 2024.07.18 |
[1์ฃผ์ฐจ] HTML ํด์ฆ ํ์ด (0) | 2024.07.18 |