Hello,

kok nae-ga ha-myun an-dweneun MAGIC...🧚

웹 프로그래밍/공부일지

모달창 만들기 :P

✿도담도담 2019. 12. 20. 18:55

단순 모달창이었다면 포스팅하지 않았겠지만..!

오늘 일을하다가 모달창을 만들었는데 길이 길어서 스크롤이 이중으로 생겨버렸다.

그걸본 사수분이 스크롤 두개는 싫어..! 하시며 fixed시키면 돼요~ 하셨는데

무슨 말인지 못알아 먹어서 하는 포스팅이다.

 

한마디로 모달창에 스크롤이 생길때 뒤에 있는 친구까지 스크롤이 되는 현상을 막는 방법이다.

정말 간단하지만 생각치 못한거였으므로 살포시 포스팅한다 :D

 

 

 

HTML 

<html>
	<head>
		<meta http-equiv="Content-type" content="text/html; charset=utf-8">
		<link rel="stylesheet" type="text/css" href="./style.css">
	</head>
	<body>	
		<div id="content">
			<div class="content">
				What is Lorem Ipsum?
				Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
				Why do we use it?
				It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
				Where does it come from?
				Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
				The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
				Where can I get some?
				There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.	
			</div>			
		</div>
		<div class="modal">
			<button class="btn-close"><img src="./ico_close.svg" alt="닫기"/></button>
			까꿍 :d<br/>
			What is Lorem Ipsum?
			Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
			Why do we use it?
			It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
			Where does it come from?
			Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
			The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
			Where can I get some?
			There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.	
		</div>		
	</body>
</html>

HTML에서 볼 것 없다고 생각했겠지만 짚고 넘어가야할게 있다.

content(클래스)와 modal을 분리 시켜 놓을것.

한마디로 뒷 배경이 되는 친구안에 모달창이 있는게 아니라 밖에 있어야한다.

 

 

CSS

body, html{padding:0;margin:0;background-color:#f3f3f3;}

#content{width:100%;position:fixed;}
.content{width:300px;margin:0 auto;}
.modal{position:absolute;top:100px;left:calc(50% - 250px);width:500px;background-color:#fff;padding:50px 20px 20px;border:1px solid #ddd;box-shadow:0px 6px 6px #33333333;margin-bottom:100px;}
.modal button{border:0;background-color:transparent;position:absolute;top:20px;right:20px;outline:none;cursor:pointer;}

음.. 모달창 열고 닫는 스크립트도 할걸 그랬다😅

첨부한 CSS는 모달창이 열려 있는 상태다.

큰 부모는 fixed되어 고정해준다.

#content가 고정되면서 .content또한 같이 고정될 것이다. 

하지만 우리의 모달친구는 스크롤이 되어야하니..가 아니라 굳이 스크롤이 아니여도 위에 띄워야 하니 absoulte!

 

 

완성본

아 말로 풀어 설명하기가 너무 어렵다.

간단하게 설명하자면 모달창을 띄웠을때 뒤에 배경을 fixed해줘 버리는거다!

끝XD