Znacznik HTML <legenda>


Przykład

Pogrupuj powiązane elementy w formie:

<form action="/action_page.php">
  <fieldset>
    <legend>Personalia:</legend>
    <label for="fname">First name:</label>
    <input type="text" id="fname" name="fname"><br><br>
    <label for="lname">Last name:</label>
    <input type="text" id="lname" name="lname"><br><br>
    <label for="email">Email:</label>
    <input type="email" id="email" name="email"><br><br>
    <label for="birthday">Birthday:</label>
    <input type="date" id="birthday" name="birthday"><br><br>
    <input type="submit" value="Submit">
  </fieldset>
</form>

Więcej przykładów „Wypróbuj sam” poniżej.


Definicja i użycie

Znacznik <legend>definiuje podpis dla elementu <fieldset> .


Obsługa przeglądarki

Element
<legend> Yes Yes Yes Yes Yes

Atrybuty globalne

Znacznik <legend>obsługuje również atrybuty globalne w HTML .


Atrybuty wydarzenia

Tag <legend>obsługuje również Atrybuty Zdarzeń w HTML .



Więcej przykładów

Przykład

Niech podpis zestawu pól unosi się po prawej stronie (z CSS):

<form action="/action_page.php">
  <fieldset>
    <legend style="float:right">Personalia:</legend>
    <label for="fname">First name:</label>
    <input type="text" id="fname" name="fname"><br><br>
    <label for="lname">Last name:</label>
    <input type="text" id="lname" name="lname"><br><br>
    <label for="email">Email:</label>
    <input type="email" id="email" name="email"><br><br>
    <label for="birthday">Birthday:</label>
    <input type="date" id="birthday" name="birthday"><br><br>
    <input type="submit" value="Submit">
  </fieldset>
</form>

Przykład

Użyj CSS do stylizacji <fieldset> i <legend>:

<html>
<head>
<style>
fieldset {
  background-color: #eeeeee;
}

legend {
  background-color: gray;
  color: white;
  padding: 5px 10px;
}

input {
  margin: 5px;
}
</style>
</head>
<body>

<form action="/action_page.php">
  <fieldset>
    <legend>Personalia:</legend>
    <label for="fname">First name:</label>
    <input type="text" id="fname" name="fname"><br><br>
    <label for="lname">Last name:</label>
    <input type="text" id="lname" name="lname"><br><br>
    <label for="email">Email:</label>
    <input type="email" id="email" name="email"><br><br>
    <label for="birthday">Birthday:</label>
    <input type="date" id="birthday" name="birthday"><br><br>
    <input type="submit" value="Submit">
  </fieldset>
</form>

</body>
</html>

Powiązane strony

Odniesienie HTML DOM: Obiekt legendy


Domyślne ustawienia CSS

Większość przeglądarek wyświetla <legend>element z następującymi wartościami domyślnymi:

Przykład

legend {
  display: block;
  padding-left: 2px;
  padding-right: 2px;
  border: none;
}