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

CSS를 사용하여 값이 자동인 여백 속성의 역할


값이 auto인 margin 속성은 컨테이너 내에서 요소를 수평으로 가운데에 맞추는 데 사용됩니다. 다음 코드를 실행하여 여백을 구현할 수 있습니다. auto;

예시

<!DOCTYPE html>
<html>
   <head>
      <style>
         div {
            width: 200px;
            margin: auto;
            border: 2px dashed blue;
         }
      </style>
   </head>
   <body>
      <p>This is demo text</p>
      <div>
         This is horizontally centered because it has margin: auto;
      </div>
   </body>
</html>

출력

CSS를 사용하여 값이 자동인 여백 속성의 역할