구글 AMP – 스타일 및 CSS

2 min read

Amp는 많은 주의를 기울인 후 화면에 페이지를 렌더링합니다. 로드된 페이지에는 http 요청이 더 많은 이미지, 동영상, iframe 등이 포함됩니다. 따라서 수행해야 할 http 요청이 지연되어 페이지의 콘텐츠가 표시되고 이미지, 동영상, iframe이 로드되는 데 필요한 공간이 생성됩니다.

Amp에는 페이지가 반응하도록하고 페이지의 콘텐츠가 방해받지 않도록 하는 placeholder, fallback, srcset 및 layout 속성과 같은 기능이 있습니다. 이 글에서는 이 모든 것에 대해 자세히 설명하겠습니다.

Amp 스타일 태그

Amp에는 아래와 같이 amp-custom이 있는 스타일 태그가 있습니다.

<style amp-custom>
  button{ 
    background-color: #ACAD5C; 
    color: white; 
    padding: 12px 20px; 
    border: none; 
    border-radius: 4px; 
    cursor: pointer; 
    float: left;
  }
 
  amp-img {
    border: 1px solid black;
    border-radius: 4px;
    padding: 5px;
  }

  p {
    padding: 1rem;
    font-size:25px;
  }

  largeText {
    font-size:30px;
    background-color:red;
  }
</style>

amp-custom 속성은 기본적으로 amp 페이지에 필요한 사용자 정의 CSS를 작성하는 데 사용됩니다. amp-custom 속성을 추가하는 것을 잊지 마십시오. 그렇지 않으면 아래와 같이 amp 유효성 검사에 실패합니다.

구글 AMP – 스타일 및 CSS

Amp는 또한 아래와 같이 HTML 요소에 대한 인라인 CSS를 지원합니다.

<p style="color:green;margin-left:30px;">Welcome to TutorialsPoint</p>

외부 스타일 시트 태그

Amp는 외부 스타일 시트를 지원하지 않으며 amp에 대해 유효성을 검사할 때 유효성 검사에 실패합니다.

예제

<!doctype html>
<html ⚡ lang="ko">
<head>
  <meta charset="utf-8">
  <script async src="https://cdn.ampproject.org/v0.js"></script>
  <title>Google AMP - Styles and Custom CSS</title>
  <link rel="canonical" href="https://googleblogamp.blogspot.com/2021/01/google-amp-styles-and-custom-css.html">
  <meta name="viewport" content="width=device-width,minimum-scale=1">
  <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.0/css/materialize.min.css">
  <style amp-custom>
    p {
      padding: 1rem;
      font-size:25px;
    }
  </style>
</head>
<body>
<h3>Google AMP - Styles and Custom CSS</h3>
<p style="color:green;margin-left:30px;">Welcome to TutorialsPoint</p>
</body>
</html>

AMP 유효성 검사기로 유효성을 검사하면 다음 오류가 발생합니다.

페이지의 요소를 반응형으로 표시하려면 amp 요소가 페이지에서 요소가 차지할 너비와 높이를 지정해야 합니다. layout="responsive"을 추가하면 페이지에서 요소가 종횡비를 유지하면서 반응하게 됩니다.

레이아웃 속성에 대한 자세한 내용은 Google AMP – 레이아웃에서 자세히 설명합니다.

방문해주셔서 감사합니다. 즐거운 하루 되세요!

관심 있을 만한 글

  • AMP는 HTML 태그와 유사한 기능을 하는 대체 가능한 AMP HTML 태그를 제공하지만, 이는 제한적이고 성능에 최적화된 방식으로 제공합니다. 이를 AMP Components 또는 AMP Custom Elements라고 합니다. AMP 구성 요소에는 세 가지 유형이 …
  • AMP의 주요 구성 요소에는 AMP-HTML, AMP-JS, AMP-Cache 이렇게 세 가지가 있습니다. 아래에서 이 세 가지 주요 구성 요소에 대해서 살펴보겠습니다. AMP-HTML AMP-HTML은 AMP 콘텐츠를 작성하는 데 사용되는 HTML5 기반의 마크 업…
  • 폭포형 차트(Waterfall charts)는 브라우저가 웹 페이지 리소스를 다운로드하고 처리하는 과정을 타임 라인에 표시합니다. 항목이 다운로드 되는 순서 또는 성능 저하 지점이 어딘지 등을 시각적으로 명확하게 표현합니다. 이것은 사용자에게 좋은 웹 성능을 제공하기 위해 없어서는 안 될 필수 요소입니다.…
  • 접을 수 있는 메뉴는 화면 공간이 제한된 모바일 장치에서 사용자 경험을 개선하는 데 도움이 될 수 있습니다. 아코디언 구성 요소는 확장 또는 축소할 수 있는 콘텐츠 목록입니다. 예를 들어, 댓글 섹션을 접거나 내비게이션 메뉴에서 카테고리를 접었다 펴는 것과 같이 다양한 …
  • 구글 페이지스피드 인사이트(Google PageSpeed Insights)는 사용하기 쉬운 웹 성능 테스트 도구입니다. Google에서 운영하는 무료 서비스이며 사이트에 점수를 매겨 웹 페이지에 대한 빠르고 간단한 분석을 제공합니다. 입력창에 URL주소를 입력하면 테스트가 진행되며, 페이지 내 콘텐츠…
  • AMP 프로젝트는 전용 사이트인 AMP Start (ampstart.com)를 제공합니다. 이 사이트는 무료로 사용 및 수정이 가능하고 이미 완성된 표준 AMP 템플릿을 지원합니다. 바로 사용할 수 있게 미리 만들어진 템플릿 및 구성 요소를 찾고 있다면 참고할 수 있습니…

댓글 쓰기