悬停时更改标签和输入元素的字体大小 - 使用 CSS 的 HTML

Nav*_*r V 3 html css label input hover

HTML:
<fieldset>
  <legend> XXX </legend>
  <label for="photo"> Photo </label>
  <input type="file" name="photo" id="photo">
  <br>
  <label for="imagePreview"> Preview: </label>
  <img id="preview">
</fieldset>

CSS:
// 1. In this order, only input:hover works.
  label:hover { font-size: 25px;}
  input:hover { font-size: 20px;}

// 2. In this order, only label:hover works.
  input:hover { font-size: 20px;}
  label:hover { font-size: 25px;}
Run Code Online (Sandbox Code Playgroud)

我被要求做这两件事都应该调整它们的字体大小。

例如:将鼠标悬停在标签上,应该更改其字体大小。将鼠标悬停在输入上,也应该更改其字体大小。

为什么不同时改变字体大小呢?我怎样才能实现它?

Kis*_*han 6

fieldset { font-size: 20px;}
label:hover , input:hover { font-size: 25px;}
Run Code Online (Sandbox Code Playgroud)
<fieldset>
  <legend> XXX </legend>
  <label for="photo"> Photo </label>
  <input type="file" name="photo" id="photo">
  <br>
  <label for="imagePreview"> Preview: </label>
  <img id="preview">
</fieldset>
Run Code Online (Sandbox Code Playgroud)