⏰ 2024.11.22 (D+32)
<fieldset class="visible">
<legend>visibility:hidden일때 영역은 그대로 존재</legend>
<div style="background-color:red;">left</div>
<div style="background-color:green;visibility: hidden;">center</div>
<div style="background-color:blue;">right</div>
</fieldset>
<fieldset class="visible">
<legend>display:none일때 영역도 사라짐</legend>
<div style="background-color:red;">left</div>
<div style="background-color:green;display:none">center</div>
<div style="background-color:blue;">right</div>
</fieldset>
<fieldset class="visible">
<legend>태그의 hidden 속성으로 CSS의 diplay:none효과</legend>
<div style="background-color:red;">left</div>
<div style="background-color:green;" hidden>center</div>
<div style="background-color:blue;">right</div>
</fieldset>
<fieldset class="inline">
<legend>가로배치로 변경</legend>
<div style="background-color:red;">left</div>
<div style="background-color:green;">center</div>
<div style="background-color:blue;">right</div>
</fieldset>
<fieldset class="inline-block">
<legend>가로배치로 변경</legend>
<div style="background-color:red;">left</div>
<div style="background-color:green;">center</div>
<div style="background-color:blue;">right</div>
</fieldset>
<fieldset class="block">
<legend>세로배치로 변경</legend>
<span style="background-color:red; width:50px; height:50px;">left</span>
<span style="background-color:green; width:50px; height:50px;">center</span>
<span style="background-color:blue; width:50px; height:50px;">right</span>
</fieldset>
<fieldset>
<legend>float속성(div의 width/height미 지정)</legend>
<div style="background-color: red; float:left;">div1</div>
<div style="background-color: green; float:right;">div2</div>
<div style="background-color: blue; clear:both;">div3</div>
</fieldset>
<fieldset>
<legend>float속성(div의 width만 지정)</legend>
<div style="background-color: red;width:100px; float:left;">div1</div>
<div style="background-color: green;width:100px;float:right;">div2</div>
<div style="background-color: blue;width:100px;">div3</div>
</fieldset>
<fieldset>
<legend>float속성(div의 width/height 지정)</legend>
<div style="background-color: red;width:50px;height:50px;float:left;">div1</div>
<div style="background-color: green;width:50px;height:50px;float:right;">div2</div>
<div style="background-color: blue;width:50px;height:50px;clear:both;">div3</div>
</fieldset>
부모가 position을 가지는 경우와 가지지 않는 경우의 차이
<fieldset>
<legend>Z-INDEX속성</legend>
<div style="background-color:yellow;width:300px;height:300px;position:relative;">
<div style="background-color:red;width:100px;height:100px;position:absolute;left:20px;top:20px;z-index:15;">div1</div>
<div style="background-color:green;width:100px;height:100px;position:absolute;left:60px;top:60px;z-index:10;">div2</div>
<div style="background-color:blue;width:100px;height:100px;position:absolute;left:100px;top:100px;z-index:12;">div3</div>
</div>
</fieldset>
동작 ⚙️
(1) 초기 상태:
(2) 버튼 클릭 시:
(3) 학습 포인트:
<h2>버튼 클릭시 div를 특정 위치(정 가운데)에 띄우기</h2>
<div style="min-width:25em;margin-bottom:10px;background-color:rgb(109, 146, 15);width:100%;height:300px;">
<div id="child" style="text-align:center;line-height:100px;background-color:rgb(231, 225, 116);width:50%;height:100px;display:none;position:absolute;">
나이를 입력 <input type="text"/>
</div>
</div>
<hr/>
<button>입력창 띄우기</button>
<script>
var child = document.querySelector('#child');
var parent = child.parentElement;
var button = parent.nextElementSibling.nextElementSibling;
button.onclick = function() {
parent.style.display = 'flex'; // 부모를 Flexbox로 설정
parent.style.justifyContent = 'center'; // 가로 중앙 정렬
parent.style.alignItems = 'center'; // 세로 중앙 정렬
child.style.minWidth = '288px'; // 자식 요소의 최소 너비 설정
child.style.display = 'block'; // 자식 요소를 보이게 설정
};
</script>