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

CSS로 채팅 메시지를 만드는 방법은 무엇입니까?


CSS로 채팅 메시지를 작성하려면 코드는 다음과 같습니다 -

예시

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
   body {
      margin: 0 auto;
      max-width: 800px;
      padding: 0 20px;
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
   }
   .message {
      font-size: 18px;
      font-weight:500;
      border: 2px solid #dedede;
      background-color: #55e4a8;
      color:rgb(0, 0, 0);
      border-radius: 12px;
      padding: 10px;
      margin: 10px 0;
   }
   .darker {
      border-color: #ccc;
      background-color: rgb(111, 25, 182);
      color:white;
   }
   .message::after {
      content: "";
      clear: both;
      display: table;
   }
   .profilePic{
      width: 100%;
   }
   .message img {
      float: left;
      max-width: 60px;
      width: 100%;
      margin-right: 20px;
      border-radius: 50%;
   }
   .message img.right {
      float: right;
      margin-left: 20px;
      margin-right:0;
   }
   .timeStampRight {
      float: right;
      color: rgb(0, 0, 0);
      font-weight: bold;
   }
   .timeStampLeft {
      float: left;
      color: rgb(255, 255, 255);
      font-weight: bold;
   }
</style>
</head>
<body>
<h1>Chat Messages Example</h1>
<div class="message">
<img class="profilePic" src="https://i.picsum.photos/id/295/200/200.jpg">
<p>Hello. How are your holidays going?</p>
<span class="timeStampRight">9:00</span>
</div>
<div class="message darker">
<img class="profilePic" src="https://i.picsum.photos/id/255/200/200.jpg">
<p>They are going pretty good.Thanks for asking!</p>
<span class="timeStampLeft">9:05</span>
</div>
<div class="message">
<img class="profilePic" src="https://i.picsum.photos/id/295/200/200.jpg">
<p>Are you visiting somewhere in holidays?</p>
<span class="timeStampRight">9:07</span>
</div>
<div class="message darker">
<img class="profilePic" src="https://i.picsum.photos/id/255/200/200.jpg">
<p>Yes! Thinking of going to Disneyland.</p>
<span class="timeStampLeft">9:10</span>
</div>
</body>
</html>

출력

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

CSS로 채팅 메시지를 만드는 방법은 무엇입니까?