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

CSS로 반응형 플로팅 요소를 만드는 방법은 무엇입니까?

<시간/>

CSS로 반응형 플로팅 요소를 생성하기 위한 코드는 다음과 같습니다 -

예시

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   }
   .floatRight, .floatLeft {
      color: white;
      font-size: 20px;
      padding: 10px;
      font-weight: 500;
   }
   .floatRight {
      background-color: rgb(0, 2, 95);
      float: right;
   }
   .floatLeft {
      background-color: rgb(85, 0, 74);
      float: left;
   }
   @media (max-width: 768px) {
      .floatRight {
         float: left;
      }
      .floatLeft {
         float: right;
      }
   }
</style>
</head>
<body>
<h1>Responsive Float Example</h1>
<h2>The floats will swap their position on smaller screens</h2>
<div class="clearfix">
<div class="floatRight">Float Right ></div>
<div class="floatLeft">Float Left <</div>
<br />
</div>
</body>
</html>

출력

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

CSS로 반응형 플로팅 요소를 만드는 방법은 무엇입니까?

화면 크기를 조정할 때 수레는 다음과 같이 위치를 바꿉니다 -

CSS로 반응형 플로팅 요소를 만드는 방법은 무엇입니까?