document.write
""
''
같은 따옴표 안에 넣어서 표시가능
class="ball ball1"
중에서
ball
은 형태에 대해서 스타일속성을 지정했고ball1
은 배경색에 대해서 스타일 속성을 지정했다.if
의 조건문에 lotto.length < 6
이라고 작성했어야 됐는데
lotto().length < 6
이라고 작성했다
()는 무언가를 행동? 실행하는 함수일때 사용한다!!
lotto
는 배열일 뿐이니 그냥 lotto
라고 사용하자
float: left;
margin-right: 6px;
width: 60px;
height: 60px;
border-radius: 100%;
line-height: 60px;
font-size: 28px;
text-align: center;
color: #fff;
font-weight: 500;
text-shadow: 0px 0px 3px rgba(73, 57, 0, .8);
line-height
을 지정해주지 않으면vertical-align: middle
가 작동되지 않는다vertical-align: middle;
line-height: 60px;
그래서 둘의 상관관계를 찾기위해 검색을 했더니, 아래와 같은 블로그를 찾았다. 아직은 이해하기 어렵지만 보면 좋을 것 같다.
inline formatting context를 형성하는 주요한 역할
line-height와 vertical-align
출처 : https://wit.nts-corp.com/2017/09/25/4903
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>로또 번호 추첨기</title>
<!-- 외부스타일시트 추가 -->
<link rel="stylesheet" href="style.css" />
<!-- CSS 스타일속성 -->
<style>
.ball {
float: left;
width: 60px;
height: 60px;
line-height: 60px;
font-size: 28px;
border-radius: 100%;
text-align: center;
vertical-align: middle;
color: #fff;
font-weight: 500;
text-shadow: 0px 0px 3px rgba(73, 57, 0, .8);
margin-right: 6px;
}
.ball1 { background: #fbc400; }
.ball2 { background: #69c8f2; }
.ball3 { background: #ff7272; }
.ball4 { background: #aaa; }
.ball5 { background: #b0d840; }
.ball6 { background: #c7c7c7; }
</style>
</head>
<body>
<h1>로또 번호 추첨기</h1>
<script>
var lotto = [];
while (lotto.length < 6) {
var num = parseInt(Math.random() * 45 + 1);
if (lotto.indexOf(num) == -1) {
lotto.push(num);
}
}
lotto.sort((a, b) => a - b);
// 화면에 보이도록 하는 코드 추가
document.write("<div class='ball ball1'>" + lotto[0] + "</div>");
document.write("<div class='ball ball2'>" + lotto[1] + "</div>");
document.write("<div class='ball ball3'>" + lotto[2] + "</div>");
document.write("<div class='ball ball4'>" + lotto[3] + "</div>");
document.write("<div class='ball ball5'>" + lotto[4] + "</div>");
document.write("<div class='ball ball6'>" + lotto[5] + "</div>");
</script>
</body>
</html>