Tag HTML <legend>

Definicja i użycie

<legend> Definicja znacznika <fieldset> element tytuł (caption).

Zobacz również:

Podręcznik HTML DOM:Obiekt Legend

Przykład

Przykład 1

Grupowanie elementów w formularzu:

<form action="/action_page.php">
  <fieldset>
    <legend>Informacje osobowe:</legend>
    <label for="fname">Imię:</label>
    <input type="text" id="fname" name="fname"><br><br>
    <label for="lname">Nazwisko:</label>
    <input type="text" id="lname" name="lname"><br><br>
    <label for="email">E-mail:</label>
    <input type="email" id="email" name="email"><br><br>
    <label for="birthday">Data urodzenia:</label>
    <input type="date" id="birthday" name="birthday"><br><br>
    <input type="submit" value="Wyślij">
  </fieldset>
</form>

Spróbuj sam

Przykład 2

Przesuń tytuł sekcji w prawo (używając CSS):

<form action="/action_page.php">
  <fieldset>
    <legend style="float:right">Informacje osobowe:</legend>
    <label for="fname">Imię:</label>
    <input type="text" id="fname" name="fname"><br><br>
    <label for="lname">Nazwisko:</label>
    <input type="text" id="lname" name="lname"><br><br>
    <label for="email">E-mail:</label>
    <input type="email" id="email" name="email"><br><br>
    <label for="birthday">Data urodzenia:</label>
    <input type="date" id="birthday" name="birthday"><br><br>
    <input type="submit" value="Wyślij">
  </fieldset>
</form>

Spróbuj sam

Przykład 3

ustawianie za pomocą CSS <fieldset> i <legend> Styl:

<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>Informacje osobowe:</legend>
    <label for="fname">Imię:</label>
    <input type="text" id="fname" name="fname"><br><br>
    <label for="lname">Nazwisko:</label>
    <input type="text" id="lname" name="lname"><br><br>
    <label for="email">E-mail:</label>
    <input type="email" id="email" name="email"><br><br>
    <label for="birthday">Data urodzenia:</label>
    <input type="date" id="birthday" name="birthday"><br><br>
    <input type="submit" value="Wyślij">
  </fieldset>
</form>
</body>
</html>

Spróbuj sam

Globalne atrybuty

<legend> Tagi te obsługują również Globalne atrybuty HTML.

Atrybuty wydarzeń

<legend> Tagi te obsługują również Atrybuty wydarzeń w HTML.

Domyślne ustawienia CSS

Większość przeglądarek wyświetli następujące wartości domyślne <legend> Element:

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

Spróbuj sam

Obsługa przeglądarek

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Wsparcie Wsparcie Wsparcie Wsparcie Wsparcie