--- title: <ratio> slug: Web/CSS/ratio translation_of: Web/CSS/ratio --- <div>{{CSSRef}}</div> <p> <ratio> CSS数据类型,用于描述媒体查询中的宽高比,表示两个无单位值之间的比例。</p> <h2 id="句法">句法</h2> <p> 在Media Queries Level 3中,<ratio>数据类型包括一个正数的<a href="/zh-CN/docs/Web/CSS/integer"><integer></a>值,后跟一个正斜杠('/',Unicode U + 002F SOLIDUS)和第二个正数的<a href="/zh-CN/docs/Web/CSS/integer"><integer></a>值。斜杠前后的空格是可选的。第一个数字代表宽度,第二个数字代表高度。</p> <p> 在Media Queries Level 4中,<ratio>数据类型包括一个正数的<a href="/zh-CN/docs/Web/CSS/number"><number></a>值,后跟一个正斜杠('/',Unicode U + 002F SOLIDUS)和第二个正数的<a href="/zh-CN/docs/Web/CSS/number"><number></a>值。此外,允许使用单个<a href="/zh-CN/docs/Web/CSS/number"><number></a>作为值。</p> <h2 id="例子">例子</h2> <h3 id="在媒体查询中使用">在媒体查询中使用</h3> <pre class="brush: css notranslate">@media screen和(min-aspect-ratio:16/9){...}</pre> <h3 id="常见的宽高比">常见的宽高比</h3> <p>( (</p> <table class="standard-table"> <thead> <tr> <th scope="col"></th> <th scope="col">比</th> <th scope="col">用法</th> </tr> </thead> <tbody> <tr> <td><img alt="Ratio4_3.png" class="default internal" src="/@api/deki/files/5714/=Ratio4_3.png"></td> <td><code>4/3</code></td> <td>在20传统电视制式<span style="font-size: 13.3333px;">格式</span>。</td> </tr> <tr> <td><img alt="Ratio16_9.png" src="/@api/deki/files/5711/=Ratio16_9.png"></td> <td><code>16/9</code></td> <td>现代"宽屏”电视格式。</td> </tr> <tr> <td><img alt="Ratio1_1.85.png" src="/@api/deki/files/5712/=Ratio1_1.85.png"></td> <td><code>185/100</code>= <code>91/50</code><br> <em>(不允许非整数除数和除数)</em></td> <td>自20世纪60年代以来最常见的电影格式。</td> </tr> <tr> <td><img alt="Ratio1_2.39.png" src="/@api/deki/files/5713/=Ratio1_2.39.png"></td> <td><code>239/100</code><br> <em>(不允许使用非整数红利和除数)</em></td> <td>"宽屏”,变形电影格式。</td> </tr> </tbody> </table> <h2 id="产品规格">产品规格</h2> <table class="standard-table"> <thead> <tr> <th scope="col">规范</th> <th scope="col">状态</th> <th scope="col">评论</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('CSS3 Media Queries','#value','<ratio>')}}</td> <td>{{Spec2('CSS3 Media Queries')}}</td> <td>初步定义。</td> </tr> </tbody> </table> <h2 id="浏览器兼容性">浏览器兼容性</h2> <p>{{COMPAT("css.types.ratio")}}</p> <h2 id="也可以看看">也可以看看</h2> <ul> <li><code><a href="/en-US/docs/Web/CSS/@media/aspect-ratio">aspect-ratio</a></code> 媒体功能</li> </ul>