Computer >> 컴퓨터 >  >> 프로그램 작성 >> CSS

CSS를 사용하여 버튼 요소를 수직 및 수평으로 가운데에 맞추는 방법은 무엇입니까?


CSS를 사용하여 버튼을 세로 및 가로 가운데에 맞추려면 코드는 다음과 같습니다. -

예시

<!DOCTYPE html>
<html>
<head>
<style>
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   }
   .centered {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 200px;
      border: 3px solid rgb(0, 70, 128);
   }
   button{
      font-size: 18px;
      border: none;
      padding:10px;
      background-color: darkblue;
      color:white;
   }
</style>
</head>
<body>
<h1>Centering Example</h1>
<div class="centered">
<button>This button is centered</button>
</div>
</body>
</html>

출력

위의 코드는 다음 출력을 생성합니다 -

CSS를 사용하여 버튼 요소를 수직 및 수평으로 가운데에 맞추는 방법은 무엇입니까?