--- title: hover slug: Web/CSS/@media/hover tags: - '@media' - CSS - Reference - media feature translation_of: Web/CSS/@media/hover --- <div>{{cssref}}</div> <p>该<strong><code>hover</code></strong> <a href="/en-US/docs/CSS">CSS</a> {{cssxref("@media")}} 可以根据用户的主要输入机制是否可以悬停在元素之上来应用样式。</p> <h2 id="语法">语法</h2> <p>悬停功能指定为从下面列表中选择的关键字值。</p> <dl> <dt><code>none</code></dt> <dd>主要输入机制无法悬停或不方便悬停(例如,当用户执行不方便的长按操作时,许多移动设备模拟悬停),或者没有主指示输入机制。</dd> <dt><code>hover</code></dt> <dd>主要输入机制可以方便地悬停在元素上。</dd> </dl> <h2 id="例子">例子</h2> <h3 id="HTML">HTML</h3> <pre class="brush: html"><a href="#">Try hovering over me!</a></pre> <h3 id="CSS">CSS</h3> <pre class="brush: css">@media (hover: hover) { a:hover { background: yellow; } }</pre> <h3 id="结果">结果</h3> <p>{{EmbedLiveSample("Example")}}</p> <h2 id="规范">规范</h2> <table class="standard-table"> <thead> <tr> <th scope="col">Specification</th> <th scope="col">Status</th> <th scope="col">Comment</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('CSS4 Media Queries', '#hover', 'hover')}}</td> <td>{{Spec2('CSS4 Media Queries')}}</td> <td>Initial definition.</td> </tr> </tbody> </table> <h2 id="Browser_compatibility" name="Browser_compatibility">浏览器兼容性</h2> <p>{{Compat("css.at-rules.media.hover")}}</p> <h2 id="See_also">See also</h2> <ul> <li><a href="/en-US/docs/Web/CSS/@media/any-hover">the <code>any-hover</code> media feature</a></li> </ul>