[Day3] CSS 3 [11/14]

 

JS๋กœ ๋™์ ๋ฒ„ํŠผ ์ƒ์„ฑ - DOM ๋ฉ”์„œ๋“œ ์‚ฌ์šฉ

     // 1. ๋ฒ„ํŠผ [์š”์†Œ๋ฅผ ์ƒ์„ฑ] - createElement() ๋ฉ”์„œ๋“œ
     var btn =  document.createElement("button");
     
     // 2. <button>ํšŒ์›๊ฐ€์ž…</button>   ํ…์ŠคํŠธ๋…ธ๋“œ
     // ์ปฌ๋ ‰์…˜ ํด๋ž˜์Šค - LinkedList : node
     // var textNode =  document.createTextNode("๋ฒ„ํŠผ - 1");
     // btn.appendChild(textNode);
     // 2-2.  <์‹œ์ž‘ํƒœ๊ทธ>Content(๋‚ด์šฉ)</์ข…๋ฃŒํƒœ๊ทธ>
     //         <button>๋ฒ„ํŠผ - 1   innerText ์†์„ฑ</button>
     btn.innerText = "๋ฒ„ํŠผ - 1";
     
     // 3.  ๋™์  ์ƒ์„ฑํ•œ ๋ฒ„ํŠผ์„  ํด๋ฆญ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ.
     btn.onclick = function (){
    	 alert(" ๋ฒ„ํŠผ - 1 ํด๋ฆญ");
     }

     // js == java  ๋ช…๋ น์ข…๊ฒฐ์—ฐ์‚ฐ์ž        ;  ์„ธ๋ฏธ์ฝœ๋ก  ๋ถ™์ธ๋‹ค. ( ์ƒ๋žต ๊ฐ€๋Šฅ )
     // 4. ์ƒ์„ฑ๋œ ๋ฒ„ํŠผ์„ [๋ถ€๋ชจ์š”์†Œ body]์— ์ถ”๊ฐ€
     // document.getElementById(id)
     // document.querySelector("body")
     document.body.appendChild(btn);

* ๋งˆ์ง€๋ง‰ ์ž์‹์š”์†Œ = script

  ๋งˆ์ง€๋ง‰ ์ž์‹ ์š”์†Œ์— ์ถ”๊ฐ€ -> button ์ถ”๊ฐ€๋จ (์ด๋ฆ„์ด ์—†๊ธฐ ๋•Œ๋ฌธ์— ์ž‘๊ฒŒ ๋‚˜์˜ด)

<button id="btnExec"  style="width:150px;">์‹คํ–‰ ๋ฒ„ํŠผ</button> 
<!-- <button id="btnExec"  width="150px">์‹คํ–‰ ๋ฒ„ํŠผ</button> -->

<!-- p#demo -->
<p id="demo">XXX</p>
<script>
        // document.getElementById("btnExec");
        document.querySelector("#btnExec").onclick = function (){
            var pEle = document.querySelector("#demo");
         
            // <p></p>
            // button*10, br*10    ๋ชจ๋“  ์ž์‹ ์š”์†Œ ์ œ๊ฑฐ
            pEle.innerText = "";
            
            //alert(" ์ž ์‹œ ๋ฉˆ์ถค ");
            
        	// ๋ฒ„ํŠผ * 10 => p ์ถ”๊ฐ€
        	for (var i = 1; i <= 10; i++) {
        		 var btn =  document.createElement("button"); 
        		 
        		 // ๋ฒ„ํŠผ์˜ ๋„ˆ๋น„ : 150px
        		 // js  ?  style="width:150px;"
        		 //         style ์†์„ฑ  "width:150px;" ์†์„ฑ๊ฐ’
        		 // btn.setAttribute(name, value);
        		 // value = btn.getAttribute(name);
        		 
        		 // js ์ฝ”๋”ฉ -> F12 ๋””๋ฒ„๊น….
        		 // btn.setAttribute("style", "width:150px;");
        		 btn.style.width = "150px";  //  px ๋‹จ์œ„ ๊ผญ ๋ถ™์ด์ž.     
        		 
        		 //btn.setAttribute("width", "150px");  // X
        		 //btn.width = "150px;"                               X
        		 
        	     btn.innerText = "๋ฒ„ํŠผ - "+ i; 
        	     btn.onclick = function (){
        	    	 // [***** js ํด๋กœ์ € *****] 
        	    	 // *** alert(" ๋ฒ„ํŠผ - "+i+" ํด๋ฆญ");
        	    	 
        	    	 // js์—์„œ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ๋ชจ๋“  ์ด๋ฒคํŠธ ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๋Š” ๊ฐ์ฒด : event ๊ฐ์ฒด
        	    	 alert(  event.srcElement.innerText );
        	    	 
        	     };
        	     pEle.appendChild(btn);
        	     
        	     // <button> ์ธ๋ผ์ธ ๋ชจ๋“œ
        	     pEle.appendChild( document.createElement("br") );
        	     
			} // for
        };
</script>

* p ํƒœ๊ทธ์˜ ์ž์‹ ์•ˆ์—๋‹ค ์ง‘์–ด๋„ฃ์–ด์•ผํ•จ -> document.body.appendChild(btn) ->  pEle.appendChild(btn); 

* js ํด๋กœ์ €!!! (์ค‘์š”)

  -> event ๋‹ด๊ฒจ์ ธ์žˆ์Œ

* button ์†์„ฑ์— width ์†์„ฑ์—†..?

* ์‹คํ–‰๋ฒ„ํŠผ ๋ˆ„๋ฅผ๋•Œ๋งˆ๋‹ค ๋ฒ„ํŠผ์ƒ๊ธฐ๋Š”๊ฑฐ ์ดˆ๊ธฐํ™” -> ํด๋ฆญํ• ๋•Œ ์ œ๊ฑฐํ•˜๊ธฐ 

 

jQuery๋กœ ์ˆ˜์ •

<script>
   $("#btnExec").click( function (){
	   $("#demo").text("");   // js innerText="" ์†์„ฑ = jquery text("") ๋ฉ”์„œ๋“œ , html() ๋ฉ”์„œ๋“œ
	   for (var i = 1; i <= 10; i++) {
		    var btn =  $("<button>๋ฒ„ํŠผ - " + i + "</button>");
		    // style ์†์„ฑ 
		    // jquery method : css();
		    btn.css("width", "150px");
		    
		    // js์˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ : jquery
		    btn.click(function() {
		    	// alert(" ๋ฒ„ํŠผ  ํด๋ฆญ๋จ!! ");
		    	alert(  $(this).text()  );
		    	// alert( event.srcElement.innerText );
		    });    
		    
		    //$("#demo").append(btn);
		    //$("#demo").append($("<br>"));
		    
		    // ์ฒด์ด๋‹
		    $("#demo")
		              .append(btn)
		              .append($("<br>"));
	   } // for
   });
</script>

* ex02_02 ์‹ค์Šต ํ•ด๋ณด๊ธฐ


css ํŽ˜์ด์ง• ์ฒ˜๋ฆฌ

<style>
  *{
     box-sizing: border-box;
  }
  
  /* ์ €๋Š” ์ง์ ‘ ์ฝ”๋”ฉ์„ ํ•˜๋”๋ผ๋„ ์—ฌ๋Ÿฌ๋ถ„๋“ค์€ ์•„์ด๋””๋ช…, ํด๋ž˜์Šค๋ช… ๋“ฑ๋“ฑ ๋ณต์‚ฌ ๋ถ™์ด๊ธฐ */
  .pagination{
    /* background-color: red; */
    width: 50%;
    margin: 0 auto;  /*  0 t/b   auto l/r    ๊ฐ€์šด๋ฐ ์ •๋ ฌ*/
    
    overflow: auto;
  }
  
  .pagination a{
      color:black;;
      text-decoration: none;
      
      /* padding: 5px; */
      /* margin: 3px; */
      float:left;
      width: 8.3%;
      text-align: center;
  }
  
  .pagination a:hover{
      background-color: #ddd;
  }
  
  .pagination a.active{
      background-color: dodgerblue;
      color:white;
  }
</style>

 

<!-- .pagination>a[href=#]*12>{$} -->

<div class="pagination">
   <a href="#">1</a>
   <a href="#">2</a>
   <a href="#">3</a>
   <a href="#">4</a>
   <a href="#">5</a>
   <a href="#">6</a>
   <a href="#" class="active">7</a>
   <a href="#">8</a>
   <a href="#">9</a>
   <a href="#">10</a>
   <a href="#">&gt;</a>
   <a href="#">&raquo;</a>
</div>
<script>
   $(".pagination a").click(function (event){
	   // not()
	   $(".pagination a").not(this).removeClass("active");
	   $(this).addClass("active");  // [ajax( ์—์ด์ž‘์Šค ) ์‚ฌ์šฉ]
   });
</script>

css ๋ชฉ๋ก : ul, ol , li , dl, dd, dt

1)

<style>
  ul, ol{
     background-color: yellow;
     border:1px solid red;
  }
  
  ul.first{
     /* list-style-type: upper-roman; */
     
     /* ํ•ญ๋ชฉ ๋งˆ์ปค์˜ ์œ„์น˜ : li ํƒœ๊ทธ ์•ˆ์— */ 
     list-style-position: inside;
  }
  
  ol.second{
     /* list-style-type: disc; */
     /* ํ•ญ๋ชฉ ๋งˆ์ปค์˜ ์œ„์น˜ : li ํƒœ๊ทธ ๋ฐ–์— ( ๊ธฐ๋ณธ ) */ 
     list-style-position: outside;
  }
  
  li{
     /* background-color: green; */
  }
  
  ul, ol{
     list-style-type: none;
     
     margin: 0;
     padding: 0;
  }
</style>

2)

<style>

  ul{
    /*
     list-style-type: upper-roman;
     list-style-position: inside;
     list-style-image: url();
     */
     
     /* ์•ฝ์‹ ์†์„ฑ */
     /* list-style: type postion image; */
     list-style-image: url('../images/arr.gif');
  }
  
  ul li{
     border-bottom: 1px solid red;
  }
 
  /* li ํƒœ๊ทธ ์ค‘์— ๋งˆ์ง€๋ง‰ li ํƒœ๊ทธ๋Š” border-bottom์„ ์ œ๊ฑฐ */
  /* ul li:nth-child(5){ */
  ul li:last-child{
      border-bottom: none;
  }

</style>
<body>
<!-- ul.first>li*5>lorem1 -->
<ul class="first">
	<li>Lorem.</li>
	<li>Autem!</li>
	<li>Minus!</li>
	<li>Doloribus!</li>
	<li>Molestias.</li>
</ul>

<ol class="second">
	<li>Lorem.</li>
	<li>Autem!</li>
	<li>Minus!</li>
	<li>Doloribus!</li>
	<li>Molestias.</li>
</ol>
</body>

css ํ…Œ์ด๋ธ”

<style>
   table{
      width: 100%;
      border-collapse: collapse;
   }
   caption{
      font-weight: bold;
      text-transform: uppercase;
      caption-side: bottom;
   }
   th, td{
      border-bottom: 1px dotted red;
   }
   th{
      width: 100px;
      height: 70px;
   }
   td{
       height: 30px;
       text-align: center;
       vertical-align: middle;
   }
   
   tr:nth-child(even) {
	  background-color: #f2f2f2;
  }
  
  /* not()        jquery method */
  /* :not()      css selector  */
  tr:hover:not( :first-child ){
    background-color: #4caf50;
  }
</style>
<!-- table>caption+tr*3>td*4>{$} -->
  <table>
  	<caption>table sample</caption>
  	<!-- tr>th*4>{์ปฌ๋Ÿผ๋ช…$} -->
  	<tr>
  		<th>์ปฌ๋Ÿผ๋ช…1</th>
  		<th>์ปฌ๋Ÿผ๋ช…2</th>
  		<th>์ปฌ๋Ÿผ๋ช…3</th>
  		<th>์ปฌ๋Ÿผ๋ช…4</th>
  	</tr>
  	<tr>
  		<td>1</td>
  		<td>2</td>
  		<td>3</td>
  		<td>4</td>
  	</tr>
  	<tr>
  		<td>1</td>
  		<td>2</td>
  		<td>3</td>
  		<td>4</td>
  	</tr>
  	<tr>
  		<td>1</td>
  		<td>2</td>
  		<td>3</td>
  		<td>4</td>
  	</tr>
  	<tr>
  		<td>1</td>
  		<td>2</td>
  		<td>3</td>
  		<td>4</td>
  	</tr>
  	<tr>
  		<td>1</td>
  		<td>2</td>
  		<td>3</td>
  		<td>4</td>
  	</tr>
  	<tr>
  		<td>1</td>
  		<td>2</td>
  		<td>3</td>
  		<td>4</td>
  	</tr>
  </table>

css ๋ฐ˜์‘ํ˜• ํ…Œ์ด๋ธ”

- ํ™”๋ฉด์ด ๋„ˆ๋ฌด ์ž‘์•„์„œ ์ „์ฒด ํ…Œ์ด๋ธ”์„ ํ‘œ์‹œํ•  ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ

- ๋ฐ˜์‘ํ˜• ํ…Œ์ด๋ธ”์— ๊ฐ€๋กœ ์Šคํฌ๋กค ๋ง‰๋Œ€๊ฐ€ ํ‘œ์‹œ๋˜๋„๋กํ•˜๋Š” ๊ฒƒ.

- overflow:auto   ์ปจํ…Œ์ด๋„ˆ ์š”์†Œ์—  ์ž์‹์š”์†Œ๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ๋ฐ˜์‘ํ˜• ์œผ๋กœ ๋งŒ๋“ค ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ์†์„ฑ

<style>
   table{
       width: 100%;
       border-collapse: collapse;
   }
   
   th, td{
      text-align: left;
      padding: 8px;
   }
   
   tr:nth-child(even){
      background-color: #f2f2f2;
   }
   
   div{
     border: 1px solid red;
     
     overflow-x:auto; 
   }
</style>
 <!-- table>(tr>th*10>lorem1)+(tr>td*10>lorem1) -->
 
 <div>
 
 <table>
 	<tr>
 		<th>Lorem.</th>
 		<th>Aut.</th>
 		<th>In.</th>
 		<th>Ea.</th>
 		<th>Dolore.</th>
 		<th>Soluta.</th>
 		<th>Eligendi.</th>
 		<th>Nam.</th>
 		<th>Quasi.</th>
 		<th>Iusto!</th>
 	</tr>
 	<tr>
 		<td>Lorem.</td>
 		<td>At!</td>
 		<td>Provident?</td>
 		<td>Ducimus.</td>
 		<td>Ratione.</td>
 		<td>Placeat?</td>
 		<td>Amet.</td>
 		<td>Nihil!</td>
 		<td>Sunt!</td>
 		<td>Dolor.</td>
 	</tr>
 </table>
 
 </div>

display ์†์„ฑ

   1. ๋ ˆ์ด์•„์›ƒ์„ ์ œ์–ดํ•˜๋Š” ๊ฐ€์žฅ ์ค‘์š”ํ•œ CSS ์†์„ฑ

   2. ๊ธฐ๋ณธ๊ฐ’ : inline / block

   3. ์š”์†Œ๊ฐ€ ํ‘œ์‹œ๋˜๋Š”์ง€ ์—ฌ๋ถ€๋ฅผ ์ง€์ •ํ•˜๋Š” ์†์„ฑ.

<!-- ๋ธ”๋Ÿญ๋ชจ๋“œ : div, hn,  p, header, footer, section,๋“ฑ๋“ฑ-->
<!-- ul>li*3>a[href="#"]>lorem1 -->
<ul>
	<li><a href="#">Lorem.</a></li>
	<li><a href="#">Praesentium.</a></li>
	<li><a href="#">Temporibus.</a></li>
</ul>
<!-- ์ธ๋ผ์ธ๋ชจ๋“œ : a, span, img -->

<!-- span*3>lorem1 -->
<span>Lorem.</span>
<span>Error?</span>
<span>Commodi?</span>

 

ex)

display:none/block, visibility:hidden/visible ์†์„ฑ์˜ ์ฐจ์ด์ 

<style>
   .imgbox{
      width: 120px;
      border:1px solid gray;
      padding: 6px;
      text-align: center;
      
      float: left;      
   }
   
   .imgbox img, imgbox button{
     width: 100%;
   }
</style>
<style>
    #imgbox1{
        /* display: none;        ์˜์—ญ์ฐจ์ง€ X */
        /* visibility: hidden;   ์˜์—ญ์ฐจ์ง€ O( ์œ ์ง€ ) - ๋ ˆ์ด์•„์›ƒ ์˜ํ–ฅ ๋ผ์นœ๋‹ค.  */
    }
</style>
<div id="imgbox1" class="imgbox">
   Box1
   <img src="../images/img_5terre.jpg" alt="" />
   <button onclick="remove();">Remove</button>
</div>
<div id="imgbox2" class="imgbox">
   Box2
   <img src="../images/img_5terre.jpg" alt="" />
   <button onclick="hide('imgbox2');">Hide</button>
</div>
<div id="imgbox3" class="imgbox">
   Box3
   <img src="../images/img_5terre.jpg" alt="" />
   <button onclick="resetAll();">ResetAll</button>
</div>

js

<script>
   function remove() {
	   // ์˜์—ญ ์œ ์ง€ X -  ์ˆจ๊น€    display=none
	   // js   ๋‹จ์œ„ ์ƒ๋žต(์ฃผ์˜),  ์†์„ฑ๊ฐ’์€ ๋ฌธ์ž์—ด๋กœ ์„ค์ •..(์ฃผ์˜)
	   document.querySelector("#imgbox1").style.display = "none";
   }
   function hide(id) {
		// ์˜์—ญ ์œ ์ง€ O -  ์ˆจ๊น€   visibility=hidden
		document.getElementById(id).style.visibility = "hidden";
   }
   function resetAll() {
		// ์ˆจ๊น€ - ๋ณด์ด๋„๋ก...
	   document.querySelector("#imgbox1").style.display = "block";
	   document.getElementById("imgbox2").style.visibility = "visible";
   }
</script>

jquery

<script>
  $("#imgbox1 button").click(function (){
	  // alert("test")
	  // ์˜์—ญ ์œ ์ง€ X +  ์ˆจ๊น€
	  // display=none
	  
	  // $("#imgbox1").css("display","none");  // jquery css() ๋ฉ”์„œ๋“œ 
	  $("#imgbox1").hide();  // jquery hide() ๋ฉ”์„œ๋“œ
	  
  });
  $("#imgbox2 button").click(function (){
	  // alert("test")
	  $("#imgbox2").css("visibility", "hidden"); 
  });
  $("#imgbox3 button").click(function (){
	  // alert("test")
	  $("#imgbox1").show();
	  $("#imgbox2").css("visibility", "visible"); 
  });
</script>

 

ex2)

<style>
 #panel, .flip{
    font-size: 16px;
    padding: 10px;
    background-color: #4acf50;
    color:white;
    text-align: center;
    margin:auto;
    border:1px solid #a6d8a8;
 }
 
 #panel{
     display: none;
 }
 
 .flip:hover{
    cursor: pointer;
    color:red;
 }
</style>
<!-- p.flip>{Click to show panel}^#panel>p*3>lorem -->
<p class="flip">Click to show panel</p>
<div id="panel">
	<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Explicabo sit repudiandae totam rem numquam velit architecto libero unde ratione dignissimos molestiae deserunt amet doloremque aliquid nostrum similique reprehenderit fugit culpa!</p>
	<p>Modi blanditiis nemo ducimus saepe ipsum dignissimos repudiandae eos atque. Nihil quisquam rerum vel voluptatem voluptas harum dicta laborum culpa asperiores dolore natus illum laudantium doloribus. Expedita delectus at sint!</p>
	<p>Beatae numquam totam accusantium placeat doloremque consectetur iusto dolores esse facere quo impedit facilis sunt delectus commodi ducimus iure vel sequi velit et eum! Accusantium pariatur tenetur soluta mollitia adipisci.</p>
</div>

js

<script>
    var sw = false;  // ์Šค์œ„์น˜๋ณ€์ˆ˜, ์ „์—ญ๋ณ€์ˆ˜

    document.querySelector("p.flip").onclick = function (){
    	// alert("Test");
    	/*
    	if (  !sw  ) {
    		document.getElementById("panel").style.display = "block";
    		//sw = true;
		} else {
			document.getElementById("panel").style.display = "none";
			//sw = false;
		}
    	*/
    	
    	// js  -  if ~ else ,    ์‚ผํ•ญ์—ฐ์‚ฐ์ž ? :
    	document.getElementById("panel").style.display =  sw ? "none" : "block";    		
    	sw = !sw;	
    }
</script>

jquery 

<script>     
     // sw๋ณ€์ˆ˜ ์„ ์–ธ. X
    $("p.flip").click( function (){
    	// alert("test")
    	// alert(  $("#panel").css("display") );  // "none"   ์†์„ฑ์˜ ๊ฐ’์„ ์–ป์–ด์™”๋‹ค. 
    	/*
    	if( $("#panel").css("display") == "none"){
    		$("#panel").show();
    	}else{
    		$("#panel").hide();
    	}
    	*/
    	
    	// jquery method -  toggle() ํ† ํด ๋ฉ”์„œ๋“œ
    	// $("#panel").toggle(); // hide-> show,   show -> hide
    	
    	// jquery method - slideToggle() 
    	$("#panel").slideToggle(5000);  // slow, fast  1000ms
    } );
</script>

width, max-width, min-width ์†์„ฑ

<style>
   div{
      border: 3px solid #73ad21;
   }
   
   .ex01{
      width: 500px;
   }
   .ex02{
     /* width:100%;  ๊ธฐ๋ณธ๊ฐ’ */
     max-width: 500px;
   }
</style>
<!-- .ex$$*2>lorem5 -->
<div class="ex01">Lorem ipsum dolor sit amet.</div>
<br>
<div class="ex02">Eaque sint consequatur sit tenetur.</div>

๋ ˆ์ด์•„์›ƒ ๊ด€๋ จ ์œ„์น˜ : position ์†์„ฑ *****

 

   [ position ์†์„ฑ - ์š”์†Œ์˜ ์œ„์น˜ ์ง€์ • ๋ฐฉ๋ฒ•]

   1. static       ( ์ •์ , ๊ธฐ๋ณธ๊ฐ’ ) - top,bottom,left, right ์†์„ฑ X

   2. relative    ( ์ƒ๋Œ€์ขŒํ‘œ) - ๊ธฐ์ค€  

   3. fixed       ( ๊ณ ์ • )

   4. absolute ( ์ ˆ๋Œ€ ์ขŒํ‘œ ) - ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๋ถ€๋ชจ(์กฐ์ƒ)์š”์†Œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋ฐฐ์น˜

   5. sticky     ( ์‚ฌ์ „์ ์˜๋ฏธ : ๋ˆ์ ๋ˆ์ ํ•œ ) - ์‚ฌ์šฉ์ž์˜ ์Šคํฌ๋กค ์œ„์น˜์— ๋”ฐ๋ผ ๋ฐฐ์น˜ 

                       

  -  postion ์†์„ฑ์„ ๋จผ์ € ์„ค์ •ํ•˜์ง€ ์•Š์œผ๋ฉด t/b/l/r ์†์„ฑ์„ ์ ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค. 

  - top, bottom, left, right ์†์„ฑ์„ ์‚ฌ์šฉํ•ด์„œ ๋ฐฐ์น˜

 

ex1)

<style>
   .box{
     border:1px solid gray;
     width:100px;
     height:100px;
     text-align: center;
   }
</style>

<style>
  /* :nth-of-type(1) , :nth-child(1) */
  div:nth-of-type(1){
    position:static;
    background-color: red;
  }
  div:nth-of-type(2){
    position:relative;
    left:30px;
    top:30px;
    
    background-color: green;
  }
  div:nth-of-type(3){
    /* Box - 4 ์˜ ์œ„์น˜๊ฐ€  Box-3 ์œ„์น˜*/
    position:fixed;
    right:10px;
    bottom:10px;
    
    background-color: blue;
  }
  
  div:last-of-type{
     background-color: yellow;
     
     position: absolute;  /* ์ ˆ๋Œ€์ขŒํ‘œ */
     left:30px;
     top:30px;
     
     z-index: -1;
  }
</style>
<script>
   // js๋กœ div ์š”์†Œ 5๊ฐœ๋ฅผ ๋™์  ์ถ”๊ฐ€.
   for (var i = 1; i <=5 ; i++) {	   
	   var div =  document.createElement("div");
	   div.innerText = "Box - " + i;
	   
	   /*
	   div.style.border = "1px solid gray";
	   div.style.width = "100px";
	   div.style.height = "100px";
	   // div.style.text-align = "center";
	   div.style.textAlign = "center";
	   */
	   
	   /* <style>  .box ํด๋ž˜์Šค๋ช…  </style>   -> js ํด๋ž˜์Šค ์†์„ฑ ์„ค์ •. */
	   // div.className = "box";
	   div.classList.add("box");  	   
	   
	   document.body.appendChild(div);	
   } // for
   
   // jquery๋กœ p ์š”์†Œ 50๊ฐœ ๋™์  ์ถ”๊ฐ€.
   for (var i = 1; i <=50 ; i++) {
	 $("body").append(  $("<p>.</p>") );
	 // $("body").append(  $("<p></p>").text(".") );
   } // for

</script>

 

   postion:sticky;

   - IE ์ง€์›ํ•˜์ง€ ์•Š๋Š” ์†์„ฑ.

   - Safari :   webkit- ์ ‘๋‘์‚ฌ๋ฅผ ๋ถ™์ธ๋‹ค. 

   - left, right, bottom, top ์ ์–ด๋„ ํ•˜๋‚˜๋Š” ์ง€์ •ํ•ด์•ผ ๋œ๋‹ค. 

ex1)

<style>
   div.stick_test{
      border:2px solid #4caf50;
      background-color: #cae8ca;
      padding: 3px;
      text-align: center;
      
      /* ์‚ฌ์šฉ์ž์˜ ์Šคํฌ๋กค ์œ„์น˜์— ๋”ฐ๋ผ ๋ฐฐ์น˜ */
      position: sticky;
      position: -webkit-sticky;   /* Safari */   
      top:0;
   }
   
   div:last-of-type{
     /* ์Šคํฌ๋กค๋ฐ”๋ฅผ ๊ธธ๊ฒŒ ์ƒ๊ธฐ๋„๋ก ํ•˜๊ธฐ ์œ„ํ•ด  */
      padding-bottom: 2000px;
      border:1px solid gray;
   }
</style>
<!-- p>lorem -->
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. 
Magnam sit deleniti ducimus consequuntur fuga perferendis doloribus 
facere assumenda porro amet dicta eum sequi iusto rerum in eligendi 
quod consequatur impedit!
</p>

<!-- .stick_test -->
<div class="stick_test">hello world</div>

<!-- div>p*3>lorem -->
<div>
	<p>
	Lorem ipsum dolor sit amet, consectetur adipisicing elit. 
	Cumque aspernatur enim odio voluptas quo non est eius officia 
	rerum minima molestiae suscipit ad omnis deleniti accusantium 
	repellat perferendis distinctio quos.
	</p>
	<p>
	Expedita dignissimos laborum odio ea quisquam tempore
	 alias vel iste odit. Aliquid dolore itaque modi fuga harum molestiae 
	 eaque libero architecto rem! Reiciendis harum dolore corporis 
	 earum culpa tempore dolores!
	 </p>
	<p>
	  Ex odio est cupiditate nemo quia vero quo? Fuga culpa ullam
	 officia dolores harum ab ducimus quidem nostrum deserunt sunt
	  accusamus consequuntur quisquam fugiat. Iusto reiciendis dolore
	   ipsa sunt laboriosam.
	  </p>
</div>

 

ex2)

<style>

body{
   margin: 0;
   padding: 0;
   font-size: 28px;
   font-family: Arial, sans-serif;
}

header{
   background-color: #f1f1f1;
   text-align: center;
   padding:30px;
}

</style>
<style>
 
#navbar{
   background-color: #333;
   overflow: auto; 
   
   position: sticky;
   position: -webkit-sticky;
   top:0; 
   /* 
   width: 50%;
   border:1px solid red;
    */
}
#navbar a{
   color:#f2f2f2;
   display: block;
   font-size: 17px;
   text-decoration: none;
   padding: 14px 16px;
   text-align: center;
   
   /*   */
   float:left;
}

/*
#navbar::after{   
}
*/

#navbar a:hover{
   color:black;
   background-color: #ddd;
}
#navbar a.active{
   color:white;
   background-color: #4caf50;
}
 
</style>
v<!-- (header>h3+p>lorem5)+(nav#navbar>a[href='#']*3)+(section.content>h3+p*15>lorem) -->
<header>
	<h3>TOP</h3>
	<p>Lorem ipsum dolor sit amet.</p>
</header>
<nav id="navbar">
	<a href="#" class="active">Home</a>
	<a href="#">News</a>
	<a href="#">Contact</a>
</nav>

<section class="content">
	<h3>Sticky Test</h3>
	<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Architecto ipsam ad dolore eius consectetur odit sunt odio omnis soluta ipsum sed beatae? Aliquid temporibus minima quam beatae asperiores aspernatur ad.</p>
	<p>Sequi cumque veniam maiores repellat incidunt sed assumenda iure nihil inventore tempora quia ipsam delectus quisquam voluptatum esse officiis sunt magni error corporis enim. Omnis veritatis exercitationem mollitia distinctio perferendis?</p>
	<p>Dolorem quis libero impedit numquam quibusdam delectus architecto minus consectetur deleniti tempora. Error consectetur ipsam aut debitis ducimus reprehenderit quasi soluta explicabo. Adipisci et esse aliquam voluptatibus sint quaerat doloribus.</p>
	<p>Veniam libero deserunt dignissimos sunt porro maiores eligendi aperiam sint nihil magnam id ut incidunt. Quaerat ab temporibus corrupti perferendis quam sit. Maxime placeat excepturi odit illum atque dignissimos sapiente.</p>
	<p>Laudantium cupiditate provident quas error quis eos repellat ducimus quia accusamus tenetur quaerat nesciunt voluptas eaque enim aliquid quisquam ipsum. Dolorem vitae ab ipsam hic nisi animi ut ullam voluptas.</p>
	<p>Quam cupiditate perspiciatis incidunt voluptates placeat at deleniti est debitis necessitatibus molestias consectetur sed rerum distinctio quos commodi ratione aut atque qui eos animi corrupti maiores mollitia fugiat voluptatum minima?</p>
	<p>Odio ea provident quia amet sunt iste tempore dignissimos quidem exercitationem debitis magnam soluta ex ab assumenda iusto maxime beatae possimus iure natus a nemo voluptatibus illo eveniet pariatur enim.</p>
	<p>Quia ipsam ea iste rem commodi perspiciatis culpa velit adipisci deserunt placeat vitae suscipit modi obcaecati doloremque iusto accusantium animi? Sit blanditiis minus porro fugit cumque laboriosam error numquam et!</p>
	<p>Dignissimos modi veritatis aliquam molestiae est sint provident placeat ab fugiat animi ullam ut dicta dolor aperiam reiciendis reprehenderit impedit quasi tempore in eos vitae unde libero amet esse saepe.</p>
	<p>Voluptatum perferendis molestias sapiente dolorum assumenda. Nam ut totam eos doloribus rerum fuga voluptatem eligendi incidunt enim excepturi officiis sed exercitationem voluptas porro veritatis asperiores tempora officia! Earum ea tempora.</p>
	<p>Vitae cum culpa ea officiis dignissimos animi totam reprehenderit ipsum nemo. Distinctio exercitationem at nisi sapiente neque quae culpa porro voluptatibus mollitia quod nostrum quasi fugiat velit! Nemo laudantium praesentium!</p>
	<p>Alias in amet sapiente soluta iste dolorem omnis cum commodi veritatis error ratione ullam. Commodi quos eos nostrum consequatur laboriosam accusantium enim tempora velit fugiat nemo praesentium atque possimus doloribus.</p>
	<p>Dignissimos sint unde fuga porro ab cumque molestiae quasi maxime explicabo adipisci perspiciatis quae consequatur itaque harum dolore quibusdam deleniti atque hic neque nesciunt id ut assumenda illo consequuntur optio.</p>
	<p>Dolorem rem blanditiis ad voluptates nam rerum fuga deleniti modi impedit quaerat eius eaque hic repellendus saepe harum voluptas unde soluta ratione dolor totam consequuntur eveniet obcaecati explicabo error minima.</p>
	<p>Quam natus quo impedit voluptas necessitatibus vero distinctio consequuntur voluptates earum culpa quis tempora repellendus harum veritatis optio aliquid tempore nostrum iure tenetur deserunt magni quod animi minima et dolorem!</p>
</section>

 

position:absolute ์„ค๋ช… (์ค‘์š”)

<style>
   .out{
      width: 400px;
      height: 200px;
      border:3px solid #73ad21; 
      
      /* ***** */
      position: relative;
   }
   
   .in{
      width: 200px;
      height: 100px;
      border:3px solid #73ad21; 
      
      /* ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๋ถ€๋ชจ์š”์†Œ :  .out,  body  */
      /* div.out  position:static X  */
      position: absolute;
      right: 50px;
      bottom: 30px;
   }
</style>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. 
Placeat possimus quos qui tempora modi explicabo perspiciatis 
excepturi sit perferendis repellat tempore inventore. Consequatur
 sapiente qui consequuntur voluptatem ipsa atque nisi!</p>
 
 <!-- .out>lorem7+.in>{in} -->
 <div class="out">
    Lorem ipsum dolor sit amet, consectetur adipisicing.
 	<div class="in">in</div>
 </div>

- ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๋ถ€๋ชจ

- ๋ถ€๋ชจ์˜ position์ด static์€ ๋ถ€๋ชจ๊ฐ€ ๋  ์ˆ˜ ์—†์Œ 


<style>
div{
  width: 80%;
  height:100px;
  border:1px solid gray;
  text-align: center;
  margin: 0 auto;
}
</style>
<style>
   .prev, .next{
      width:50px;
      height:50px;
      
      border: 1px solid red;
      border-radius: 25px;
      
      position: absolute;
   }
   
   .prev{
     left: -25px;
     top:25px;
   }
   .next{
     right:-25px;
     top:25px;
   } 
</style>
<div></div>
<div></div>
<div style="position: relative;">
   <div class="prev">&lt;</div>
   <div class="next">&gt;</div>
</div>
<div></div>
<div></div>
<div style="position: relative;">
   <div class="prev">&lt;</div>
   <div class="next">&gt;</div>
</div>
<hr>
<div style="position: relative;">
   <div class="prev">&lt;</div>
   <div class="next">&gt;</div>
</div>

<style>

div{
  width: 80%;
  height:100px;
  border:1px solid gray;
  text-align: center;
  margin: 0 auto;
}

</style>
<style>
 
   .prev, .next{
      width:50px;
      height:50px;
      
      border: 1px solid red;
      border-radius: 25px;
      
      position: absolute;
   }
   
   .prev{
     left: -25px;
     top:25px;
   }
   .next{
     right:-25px;
     top:25px;
   }
 
</style>
<div style="position: relative;">
   <div class="prev">&lt;</div>
   <div class="next">&gt;</div>
</div>
<div></div>
<div></div>
<div style="position: relative;">
   <div class="prev">&lt;</div>
   <div class="next">&gt;</div>
</div>
<hr>
<div style="position: relative;">
   <div class="prev">&lt;</div>
   <div class="next">&gt;</div>
</div>

z-index ์†์„ฑ

<style>
  .container{
     position: relative;
     border:1px solid black;
  }
  .red-box{
     background-color: red;
     height: 100px;
     margin: 30px;
     
     position: relative;
     
     z-index: 100;
  }
  .green-box{
      background-color: green;
      width: 70%;
      height:60px;
      
      position: absolute;
      left:50px;
      top:50px;
      
      z-index: 10;
      
  }
  .blue-box{
     background-color: blue;
     width:35%;
     height: 100px;
     
     position: absolute;
     left:270px;
     top:-15px;
     
     z-index: -1;
  }
</style>
<div class="container">
	<div class="red-box">red-box</div>
	<div class="green-box">green-box</div>
	<div class="blue-box">blue-box</div>
</div>

<style>

#mySidenav a{
    background-color: #111;
    color:white;
    padding: 13px;
    text-decoration: none;
    font-size: 20px;
    border-radius: 0 5px 5px 0; 
    
    position: absolute;   /*  ๋ถ€๋ชจ์š”์†Œ body */
    width:100px;
    left:-84px;
    text-align: center;
    
    /* ์ „ํ™˜ : ๋‹ค๋ฅธ ์ƒํƒœ,์กฐ๊ฑด์œผ๋กœ ๋ณ€๊ฒฝ(์ดํ–‰)*/
    /* left๊ฐ’์ด -84 -> 0 ์ „ํ™˜ */
    transition:0.5s ease;
}
#mySidenav a:hover{
   left:0;
}
#home{  top:20px; }
#services{ top:80px; }
#clients{ top:140px;}
#contact{ top:200px;}

#content{
  margin-left:120px;
}
</style>
<div id="mySidenav" class="sidenav">  
  <a href="#" id="home">Home <i class="fa fa-fw fa-home"></i></a>
  <a href="#" id="services">Service<i class="fa fa-fw fa-wrench"></i></a>
  <a href="#" id="clients">Clients<i class="fa fa-fw fa-user"></i></a>
  <a href="#" id="contact">Contact<i class="fa fa-fw fa-envelope"></i></a>
</div>
<div id="content">
   <h2>Lorem ipsum dolor sit amet.</h2>
   <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magnam beatae!</p>
</div>

'๐Ÿ‘จโ€๐Ÿ’ป Web Development > HTML | CSS | JS | jQuery' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Day5] CSS 5 - ๋กค์˜ค๋ฒ„, ๋ฉ”๋‰ด๋ฐ”, ํƒ€์ž„๋ผ์ธ, ์ด๋ฏธ์ง€ ๊ฐค๋Ÿฌ๋ฆฌ, ์ด๋ฏธ์ง€ ์Šคํ”„๋ผ์ดํŠธ, ์„ ํƒ์ž, ๊ฒ€์ƒ‰์Šคํƒ€์ผ, ํ‰์ , ํŠน์ด์„ฑ(์ ์ˆ˜), ๋ง‰๋Œ€๊ทธ๋ž˜ํ”„, ํ”„๋กœํ•„, ๋‘ฅ๊ทผ๋ชจ์„œ๋ฆฌ, ๋‹ค์ค‘๋ฐฐ๊ฒฝ์ด๋ฏธ์ง€, background image, paral..  (0) 2022.11.17
[Day4] CSS 4 - overflow, ํŒ์—…ํผ, display, prev|next, ๋ ˆ์ด์•„์›ƒ๋ฐฐ์น˜(์ˆ˜์ง์ˆ˜ํ‰), css๊ฒฐํ•ฉ์ž, ์˜์‚ฌํด๋ž˜์Šค, ์˜์‚ฌ์š”์†Œ, ๋ถˆํˆฌ๋ช…, ํƒ์ƒ‰๋ชจ๋“ฌ, ๋“œ๋กญ๋‹ค์šด  (0) 2022.11.16
[Day2] CSS 2 - selector, ์ƒ‰์ƒ, ํ…Œ๋‘๋ฆฌ, margin, padding(border-box), width/height, box model, ๋งํฌ, ํ…์ŠคํŠธ, ์•„์ด์ฝ˜, ๊ธ€๊ผด, active์ฒ˜๋ฆฌ  (0) 2022.11.10
[Day1] CSS 1 - ๊ฐœ์š”, ์Šคํƒ€์ผ ์ ์šฉ ๋ฐฉ๋ฒ•  (0) 2022.11.10
[Day6] HTML 6 - div ํŽ˜์ด์ง€, ๋ฐ˜์‘ํ˜•์›น, form, canvas,svg, ๋ฉ€ํ‹ฐ๋ฏธ๋””์–ด, youtube  (0) 2022.11.10
  • ๋„ค์ด๋ฒ„ ๋ธ”๋Ÿฌ๊ทธ ๊ณต์œ ํ•˜๊ธฐ
  • ๋„ค์ด๋ฒ„ ๋ฐด๋“œ์— ๊ณต์œ ํ•˜๊ธฐ
  • ํŽ˜์ด์Šค๋ถ ๊ณต์œ ํ•˜๊ธฐ
  • ์นด์นด์˜ค์Šคํ† ๋ฆฌ ๊ณต์œ ํ•˜๊ธฐ