CSS 16
CSS cơ bản dành cho responsive video youtube By boyquang on 27th July 2025 03:40:50 PM
  1. 1. CSS cơ bản dành cho responsive video:
  2.  
  3. /* Đảm bảo padding 0 và box-sizing phù hợp */
  4. * {
  5.     margin: 0;
  6.     padding: 0;
  7.     box-sizing: border-box;
  8. }
  9.  
  10. body {
  11.     font-family: Arial, sans-serif;
  12.     background: #000;
  13.     color: #fff;
  14.     padding: 10px;
  15. }
  16.  
  17. /* Container cho video */
  18. .video-container {
  19.     position: relative;
  20.     width: 100%;
  21.     padding-bottom: 56.25%; /* Tỷ lệ 16:9 */
  22.     height: 0;
  23.     overflow: hidden;
  24. }
  25.  
  26. /* iframe video Youtube */
  27. .video-container iframe {
  28.     position: absolute;
  29.     top: 0;
  30.     left: 0;
  31.     width: 100%;
  32.     height: 100%;
  33.     border: 0;
  34. }
  35.  
  36. /* Responsive text và layout */
  37. h1, h2, h3, p {
  38.     font-size: 1rem;
  39.     line-height: 1.5;
  40. }
  41.  
  42. /* Tùy chỉnh thêm cho màn hình nhỏ */
  43. @media (max-width: 768px) {
  44.     body {
  45.         font-size: 14px;
  46.         padding: 8px;
  47.     }
  48.  
  49.     h1 {
  50.         font-size: 20px;
  51.     }
  52. }
  53.  
  54. 2. HTML mẫu tương ứng:
  55.  
  56. Bạn cần đảm bảo rằng iframe YouTube nằm trong .video-container như sau:
  57.  
  58. <div class="video-container">
  59.     <iframe src="https://www.youtube.com/embed/q6f_a6viEBI" frameborder="0" allowfullscreen></iframe>
  60. </div>
  61.  
  62. 3. Gợi ý thêm (nếu bạn nhúng video qua PHP):
  63. Trong file player_video.php, đảm bảo phần nhúng iframe giống như:
  64.  
  65. <?php
  66.     $url = $_GET['url'];
  67.     parse_str(parse_url($url, PHP_URL_QUERY), $params);
  68.     $videoId = $params['v'] ?? '';
  69.     if ($videoId) {
  70.         echo '<div class="video-container">';
  71.         echo '<iframe src="https://www.youtube.com/embed/' . htmlspecialchars($videoId) . '" allowfullscreen></iframe>';
  72.         echo '</div>';
  73.     } else {
  74.         echo 'Video không hợp lệ';
  75.     }
  76. ?>
  77.  
  78. https://boyquang.com/player_video.php?url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dq6f_a6viEBI

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.