국비교육(22-23)

36일차(1)/CSS(7) : bootstrap CSS 적용하기

서리/Seori 2022. 11. 28. 18:06

36일차(1)/CSS(7) : bootstrap CSS 적용하기

 

- 지금까지 만들어놓은 페이지에 bootstrap을 사용해 css를 적용할 예정

 

 

include/<navbar.jsp>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String thisPage=request.getParameter("thisPage"); // "index" | "member" | "todo"
	String id=(String)session.getAttribute("id");
	
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>/include/navbar.jsp</title>	
</head>
<body>
	<nav class="navbar navbar-dark navbar-expand-md bg-primary">
	  <div class="container-fluid">
	  
	    <a class="navbar-brand" href="http://localhost:8888/Step04_Final/index.jsp">
	    	<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-house-fill" viewBox="0 0 16 16">
			  <path d="M8.707 1.5a1 1 0 0 0-1.414 0L.646 8.146a.5.5 0 0 0 .708.708L8 2.207l6.646 6.647a.5.5 0 0 0 .708-.708L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293L8.707 1.5Z"/>
			  <path d="m8 3.293 6 6V13.5a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 2 13.5V9.293l6-6Z"/>
			</svg>
	    	HELLO!
	    </a>	    
	    
	    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
	      <span class="navbar-toggler-icon"></span>
	    </button>
	    <div class="collapse navbar-collapse" id="navbarNav">
	      <ul class="navbar-nav">	        
	        <li class="nav-item">
	          <a class="nav-link <%=thisPage.equals("study") ? "active": "" %>" href="${pageContext.request.contextPath }/private/study.jsp">회원전용공간(공부)</a>
	        </li>
	        <li class="nav-item">
	          <a class="nav-link <%=thisPage.equals("game") ? "active": "" %>" href="${pageContext.request.contextPath }/private/game.jsp">회원전용공간(게임)</a>
	        </li>
	        <li class="nav-item">
	          <a class="nav-link <%=thisPage.equals("file") ? "active": "" %>" href="${pageContext.request.contextPath }/file/list.jsp">자료실</a>
	        </li>
	        <li class="nav-item">
	          <a class="nav-link <%=thisPage.equals("cafe") ? "active": "" %>" href="${pageContext.request.contextPath }/cafe/list.jsp">글목록보기</a>
	        </li>	       
	        
			<%if(id != null) {%>
			<%-- 회원정보 보기 --%>
	        <li class="nav-item">
	          <a class="nav-link <%=thisPage.equals("userinfo") ? "active": "" %>" href="${pageContext.request.contextPath }/users/private/info.jsp">
	          	<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-person-circle" viewBox="0 0 16 16">
				  <path d="M11 6a3 3 0 1 1-6 0 3 3 0 0 1 6 0z"/>
				  <path fill-rule="evenodd" d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm8-7a7 7 0 0 0-5.468 11.37C3.242 11.226 4.805 10 8 10s4.757 1.225 5.468 2.37A7 7 0 0 0 8 1z"/>
				</svg>	          	
	          </a>
	        </li>
	        <%-- 로그아웃 버튼 --%>
	        <li class="nav-item">
	          <a class="nav-link" href="${pageContext.request.contextPath }/users/logout.jsp">
	          	<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-box-arrow-right" viewBox="0 0 16 16">
				  <path fill-rule="evenodd" d="M10 12.5a.5.5 0 0 1-.5.5h-8a.5.5 0 0 1-.5-.5v-9a.5.5 0 0 1 .5-.5h8a.5.5 0 0 1 .5.5v2a.5.5 0 0 0 1 0v-2A1.5 1.5 0 0 0 9.5 2h-8A1.5 1.5 0 0 0 0 3.5v9A1.5 1.5 0 0 0 1.5 14h8a1.5 1.5 0 0 0 1.5-1.5v-2a.5.5 0 0 0-1 0v2z"/>
				  <path fill-rule="evenodd" d="M15.854 8.354a.5.5 0 0 0 0-.708l-3-3a.5.5 0 0 0-.708.708L14.293 7.5H5.5a.5.5 0 0 0 0 1h8.793l-2.147 2.146a.5.5 0 0 0 .708.708l3-3z"/>
				</svg>	          	
	          </a>
	        </li>
	        <%}else{ %>	        
	        <%-- 회원 가입하기 --%>
	        <li class="nav-item">
	          <a class="nav-link <%=thisPage.equals("signupform") ? "active": "" %>" href="${pageContext.request.contextPath }/users/signup_form.jsp">
	          	<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-person-plus-fill" viewBox="0 0 16 16">
				  <path d="M1 14s-1 0-1-1 1-4 6-4 6 3 6 4-1 1-1 1H1zm5-6a3 3 0 1 0 0-6 3 3 0 0 0 0 6z"/>
				  <path fill-rule="evenodd" d="M13.5 5a.5.5 0 0 1 .5.5V7h1.5a.5.5 0 0 1 0 1H14v1.5a.5.5 0 0 1-1 0V8h-1.5a.5.5 0 0 1 0-1H13V5.5a.5.5 0 0 1 .5-.5z"/>
				</svg>	          	
	          </a>
	        </li>
			<%-- 회원 로그인하기 --%>
	        <li class="nav-item">
	          <a class="nav-link <%=thisPage.equals("loginform") ? "active": "" %>" href="${pageContext.request.contextPath }/users/loginform.jsp">
	          	<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-box-arrow-in-right" viewBox="0 0 16 16">
				  <path fill-rule="evenodd" d="M6 3.5a.5.5 0 0 1 .5-.5h8a.5.5 0 0 1 .5.5v9a.5.5 0 0 1-.5.5h-8a.5.5 0 0 1-.5-.5v-2a.5.5 0 0 0-1 0v2A1.5 1.5 0 0 0 6.5 14h8a1.5 1.5 0 0 0 1.5-1.5v-9A1.5 1.5 0 0 0 14.5 2h-8A1.5 1.5 0 0 0 5 3.5v2a.5.5 0 0 0 1 0v-2z"/>
				  <path fill-rule="evenodd" d="M11.854 8.354a.5.5 0 0 0 0-.708l-3-3a.5.5 0 1 0-.708.708L10.293 7.5H1.5a.5.5 0 0 0 0 1h8.793l-2.147 2.146a.5.5 0 0 0 .708.708l3-3z"/>
				</svg>	          	
	          </a>
	        </li>
	        <%} %>
	      </ul>
	    </div>
	  </div>
	</nav>
</body>
</html>

 

- 네비바 추가하기 : 5개 게시판의 링크를 걸고, 폭에 따라 조정되도록 한다.

 

<li class="nav-item">
	<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>

- navbar 아이콘의 active 적용방법

 


 

<index.jsp>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>    
<%
	//session scope에 id라는 키값으로 저장된 값이 있는지 읽어와 본다.(없으면 null)
	String id=(String)session.getAttribute("id");
	
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>/index.jsp</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>
<style>
	.text-center{
		border: 1px solid;
		margin: 10px 0px 10px; 
	}
	
</style>
</head>
<body>
	<jsp:include page="/include/navbar.jsp">
	<jsp:param value="index" name="thisPage"/>
	</jsp:include>

	<div class="container">
		
		<h1 style="margin: 20px 0px 20px; border-bottom:3px solid #0d6efd; padding:10px 0px 10px;">인덱스 페이지입니다.</h1>
		
		<div id="carouselExampleIndicators" class="carousel slide" data-bs-ride="true">
		  <div class="carousel-indicators">
		    <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
		    <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="1" aria-label="Slide 2"></button>
		    <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="2" aria-label="Slide 3"></button>
		  </div>
		  <div class="carousel-inner">
		    <div class="carousel-item active">
		      <img src="https://cdn.pixabay.com/photo/2015/02/25/07/39/church-648430_960_720.jpg" class="d-block w-100" alt="...">
		    </div>
		    <div class="carousel-item">
		      <img src="https://cdn.pixabay.com/photo/2017/07/28/00/57/christmas-2547356_960_720.jpg" class="d-block w-100" alt="...">
		    </div>
		    <div class="carousel-item">
		      <img src="https://cdn.pixabay.com/photo/2019/12/19/10/56/christmas-market-4705885_960_720.jpg" class="d-block w-100" alt="...">
		    </div>
		  </div>
		  <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="prev">
		    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
		    <span class="visually-hidden">Previous</span>
		  </button>
		  <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="next">
		    <span class="carousel-control-next-icon" aria-hidden="true"></span>
		    <span class="visually-hidden">Next</span>
		  </button>
		</div>		
	</div>
	<jsp:include page="/include/footer.jsp"></jsp:include>
</body>
</html>

 

- include 형태로 네비바 추가하고, carrosel 적용

 


 

- 폭이 좁을 때는 자동으로 버튼형식으로 적용된다

 

 

<%if(id != null) {%>    
    <li>
      <a><%-- 회원정보 보기 버튼 --%></a>
    </li>    
    <li>
      <a><%-- 로그아웃 버튼 --%></a>
    </li>
<%}else{ %>	            
    <li>
      <a><%-- 회원 가입하기 버튼 --%></a>
    </li>    
    <li>
      <a><%-- 회원 로그인하기 버튼 --%></a>
    </li>
<%} %>

- 로그인 여부에 따라 네비바에 다른 항목이 노출되도록 적용 

 

- if로 분리해서 null이 아니면 회원정보, LOGOUT / null이면 JOIN, LOGIN 이 나타나도록!

 


 

 

- style을 사용해서 버튼 서식 적용(margin, padding 추가)

 제목 서식 적용(margin, padding 추가)

 

<style>
	h1{
    	margin: 20px 0px 20px; border-bottom:3px solid #0d6efd;
	}
</style>

 

- style을 사용해서 제목(h1) 서식 적용(margin, border 추가)

- 회원정보 페이지에 테이블 형식 적용(table에 bootstrap class 추가)

 

 

 

- 네비바 회원 관련 버튼 아이콘으로 수정

- 로그아웃했을때의 모습!

 


 

include/ <footer.jsp>

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>footer.jsp</title>
</head>
<body>
	<div class="container">
		<footer class="fixed-bottom bg-light text-center text-white">
		  <!-- Grid container -->
		  <div class="container p-4 pb-0">
		    <!-- Section: Social media -->
		    <section class="mb-4">
		      <!-- Facebook -->
		      <a
		        class="btn text-white btn-floating m-1"
		        style="background-color: #3b5998;"
		        href="#!"
		        role="button"
		        ><i class="fab fa-facebook-f"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-facebook" viewBox="0 0 16 16">
				  <path d="M16 8.049c0-4.446-3.582-8.05-8-8.05C3.58 0-.002 3.603-.002 8.05c0 4.017 2.926 7.347 6.75 7.951v-5.625h-2.03V8.05H6.75V6.275c0-2.017 1.195-3.131 3.022-3.131.876 0 1.791.157 1.791.157v1.98h-1.009c-.993 0-1.303.621-1.303 1.258v1.51h2.218l-.354 2.326H9.25V16c3.824-.604 6.75-3.934 6.75-7.951z"/>
				</svg></i
		      ></a>
		
		      <!-- Twitter -->
		      <a
		        class="btn text-white btn-floating m-1"
		        style="background-color: #55acee;"
		        href="#!"
		        role="button"
		        ><i class="fab fa-twitter"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-twitter" viewBox="0 0 16 16">
				  <path d="M5.026 15c6.038 0 9.341-5.003 9.341-9.334 0-.14 0-.282-.006-.422A6.685 6.685 0 0 0 16 3.542a6.658 6.658 0 0 1-1.889.518 3.301 3.301 0 0 0 1.447-1.817 6.533 6.533 0 0 1-2.087.793A3.286 3.286 0 0 0 7.875 6.03a9.325 9.325 0 0 1-6.767-3.429 3.289 3.289 0 0 0 1.018 4.382A3.323 3.323 0 0 1 .64 6.575v.045a3.288 3.288 0 0 0 2.632 3.218 3.203 3.203 0 0 1-.865.115 3.23 3.23 0 0 1-.614-.057 3.283 3.283 0 0 0 3.067 2.277A6.588 6.588 0 0 1 .78 13.58a6.32 6.32 0 0 1-.78-.045A9.344 9.344 0 0 0 5.026 15z"/>
				</svg></i
		      ></a>
		
		      <!-- Google -->
		      <a
		        class="btn text-white btn-floating m-1"
		        style="background-color: #dd4b39;"
		        href="#!"
		        role="button"
		        ><i class="fab fa-google"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-google" viewBox="0 0 16 16">
				  <path d="M15.545 6.558a9.42 9.42 0 0 1 .139 1.626c0 2.434-.87 4.492-2.384 5.885h.002C11.978 15.292 10.158 16 8 16A8 8 0 1 1 8 0a7.689 7.689 0 0 1 5.352 2.082l-2.284 2.284A4.347 4.347 0 0 0 8 3.166c-2.087 0-3.86 1.408-4.492 3.304a4.792 4.792 0 0 0 0 3.063h.003c.635 1.893 2.405 3.301 4.492 3.301 1.078 0 2.004-.276 2.722-.764h-.003a3.702 3.702 0 0 0 1.599-2.431H8v-3.08h7.545z"/>
				</svg></i
		      >		        
		      </a>
		
		      <!-- Instagram -->
		      <a
		        class="btn text-white btn-floating m-1"
		        style="background-color: #ac2bac;"
		        href="#!"
		        role="button"
		        ><i class="fab fa-instagram"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-instagram" viewBox="0 0 16 16">
				  <path d="M8 0C5.829 0 5.556.01 4.703.048 3.85.088 3.269.222 2.76.42a3.917 3.917 0 0 0-1.417.923A3.927 3.927 0 0 0 .42 2.76C.222 3.268.087 3.85.048 4.7.01 5.555 0 5.827 0 8.001c0 2.172.01 2.444.048 3.297.04.852.174 1.433.372 1.942.205.526.478.972.923 1.417.444.445.89.719 1.416.923.51.198 1.09.333 1.942.372C5.555 15.99 5.827 16 8 16s2.444-.01 3.298-.048c.851-.04 1.434-.174 1.943-.372a3.916 3.916 0 0 0 1.416-.923c.445-.445.718-.891.923-1.417.197-.509.332-1.09.372-1.942C15.99 10.445 16 10.173 16 8s-.01-2.445-.048-3.299c-.04-.851-.175-1.433-.372-1.941a3.926 3.926 0 0 0-.923-1.417A3.911 3.911 0 0 0 13.24.42c-.51-.198-1.092-.333-1.943-.372C10.443.01 10.172 0 7.998 0h.003zm-.717 1.442h.718c2.136 0 2.389.007 3.232.046.78.035 1.204.166 1.486.275.373.145.64.319.92.599.28.28.453.546.598.92.11.281.24.705.275 1.485.039.843.047 1.096.047 3.231s-.008 2.389-.047 3.232c-.035.78-.166 1.203-.275 1.485a2.47 2.47 0 0 1-.599.919c-.28.28-.546.453-.92.598-.28.11-.704.24-1.485.276-.843.038-1.096.047-3.232.047s-2.39-.009-3.233-.047c-.78-.036-1.203-.166-1.485-.276a2.478 2.478 0 0 1-.92-.598 2.48 2.48 0 0 1-.6-.92c-.109-.281-.24-.705-.275-1.485-.038-.843-.046-1.096-.046-3.233 0-2.136.008-2.388.046-3.231.036-.78.166-1.204.276-1.486.145-.373.319-.64.599-.92.28-.28.546-.453.92-.598.282-.11.705-.24 1.485-.276.738-.034 1.024-.044 2.515-.045v.002zm4.988 1.328a.96.96 0 1 0 0 1.92.96.96 0 0 0 0-1.92zm-4.27 1.122a4.109 4.109 0 1 0 0 8.217 4.109 4.109 0 0 0 0-8.217zm0 1.441a2.667 2.667 0 1 1 0 5.334 2.667 2.667 0 0 1 0-5.334z"/>
				</svg></i
		      ></a>
		
		      <!-- Linkedin -->
		      <a
		        class="btn text-white btn-floating m-1"
		        style="background-color: #0082ca;"
		        href="#!"
		        role="button"
		        ><i class="fab fa-linkedin-in"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-linkedin" viewBox="0 0 16 16">
				  <path d="M0 1.146C0 .513.526 0 1.175 0h13.65C15.474 0 16 .513 16 1.146v13.708c0 .633-.526 1.146-1.175 1.146H1.175C.526 16 0 15.487 0 14.854V1.146zm4.943 12.248V6.169H2.542v7.225h2.401zm-1.2-8.212c.837 0 1.358-.554 1.358-1.248-.015-.709-.52-1.248-1.342-1.248-.822 0-1.359.54-1.359 1.248 0 .694.521 1.248 1.327 1.248h.016zm4.908 8.212V9.359c0-.216.016-.432.08-.586.173-.431.568-.878 1.232-.878.869 0 1.216.662 1.216 1.634v3.865h2.401V9.25c0-2.22-1.184-3.252-2.764-3.252-1.274 0-1.845.7-2.165 1.193v.025h-.016a5.54 5.54 0 0 1 .016-.025V6.169h-2.4c.03.678 0 7.225 0 7.225h2.4z"/>
				</svg></i
		      ></a>
		      <!-- Github -->
		      <a
		        class="btn text-white btn-floating m-1"
		        style="background-color: #333333;"
		        href="#!"
		        role="button"
		        ><i class="fab fa-github"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-github" viewBox="0 0 16 16">
				  <path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"/>
				</svg></i
		      ></a>
		    </section>
		    <!-- Section: Social media -->
		  </div>
		  <!-- Grid container -->
		
		  <!-- Copyright -->
		  <div class="text-center p-3" style="background-color: rgba(0, 0, 0, 0.2);">
		    © 2022 Copyright:
		    <a class="text-white" href="https://github.com/SY58/">github.com/SY58</a>
		  </div>
		  <!-- Copyright -->
		</footer>	
	</div>	
</body>
</html>

 

- include 사용해서 푸터 적용

- footer class="fixed-bottom" 로 푸터는 하단 고정

 

 

- class="text-center" 를 사용한 표 가운데 정렬

 


 

- 글 상세보기(detail) 페이지에 테이블 형식 적용하기

 


 

- navbar 아이콘 크기 키우기 (svg 아이콘의 width,height 조정)

- navbar 아이콘에도 active 넣어주기

 


 

- CSS 작업을 별도의 branch에서 작업했는데, merge하고 gitHub에도 push 해주었다.

(Team-merge → Team-push branch master)

 

- 필요없어진 branch는 merge/push 후 삭제해준다.(Local, Remote 에서 각각)

(Team-advanced-delete branch)