CSS 솔루션 :
는 DIV 요소 조정의 종횡비를 유지하기위한 간단한 솔루션을 제공합니다. 다음 CSS 코드는 이것을 달성하는 방법을 보여줍니다 :
body { 높이 : 100VH; 여백 : 0; 디스플레이 : Flex; 정당화 컨텐츠 : 센터; 정렬 구조 : 센터; 배경 : 회색; } .Stage { ---- : 960 / 540; // 원하는 종횡비 정의 (너비 / 높이) 종횡비 : var (-r); // 종횡비를 설정합니다 너비 : 최소 (90%, min (960px, 90vh*(var (-r))); // 비율을 보존하는 동안 최대 너비와 높이를 설정 디스플레이 : Flex; 정당화 컨텐츠 : 센터; 정렬 구조 : 센터; 배경: Linear-Gradient (30deg, 빨간색 50%, 투명 50%), // 보존 된 종횡비를 시각화하기 위해 그라디언트 추가 초콜릿; }
body { height: 100vh; margin: 0; display: flex; justify-content: center; align-items: center; background: gray; } .stage { --r: 960 / 540; // Define the desired aspect ratio (width / height) aspect-ratio: var(--r); // Set the aspect ratio width:min(90%, min(960px, 90vh*(var(--r)))); // Set the maximum width and height while preserving ratio display: flex; justify-content: center; align-items: center; background: linear-gradient(30deg,red 50%,transparent 50%), // Add a gradient to visualize the preserved aspect ratio chocolate; }
설명 :
부인 성명: 제공된 모든 리소스는 부분적으로 인터넷에서 가져온 것입니다. 귀하의 저작권이나 기타 권리 및 이익이 침해된 경우 자세한 이유를 설명하고 저작권 또는 권리 및 이익에 대한 증거를 제공한 후 이메일([email protected])로 보내주십시오. 최대한 빨리 처리해 드리겠습니다.
Copyright© 2022 湘ICP备2022001581号-3