Tag HTML <legenda>
Esempio
Raggruppa elementi correlati in una forma:
<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>
Altri esempi "Provalo da solo" di seguito.
Definizione e utilizzo
Il <legend>
tag definisce una didascalia per l' elemento <fieldset> .
Supporto browser
Element | |||||
---|---|---|---|---|---|
<legend> | Yes | Yes | Yes | Yes | Yes |
Attributi globali
Il <legend>
tag supporta anche gli attributi globali in HTML .
Attributi dell'evento
Il <legend>
tag supporta anche gli attributi dell'evento in HTML .
Altri esempi
Esempio
Lascia che la didascalia del fieldset si muova verso destra (con 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>
Esempio
Usa CSS per lo stile <fieldset> e <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>
Pagine correlate
Riferimento HTML DOM: Legend Object
Impostazioni CSS predefinite
La maggior parte dei browser visualizzerà l' <legend>
elemento con i seguenti valori predefiniti:
Esempio
legend {
display: block;
padding-left: 2px;
padding-right: 2px;
border: none;
}