[英]How do I place the legend outside the fieldset border
我瘋了試圖找出如何使這項工作。 我希望圖例在邊界之外。 如何在保留圖例標簽的同時實現此目的? 如您在下面看到的,我嘗試使用span,但是它不起作用。
body { background-color: #996600; color: black; } fieldset { border: 10px solid #ffffff; border-radius: 10px; background-color: #999900; box-shadow: 10px 10px 5px #888888; position: relative; } legend { font-size: 20px; float: left; } legend span { top: 0px; left: 0px; position: absolute; } input[type=text] { border: 2px solid black; border-radius: 10px; background-color: #cccc80; } input[type=button] { background-color: #996600; border: 2px solid black; border-radius: 5px; color: #c9ae78; font-weight: bolder; } p { font-size: 12px; font-style: italic; }
<form method="post" id="contactForm" action="#"> <fieldset> <legend><span>Newsletter Signup</span> </legend> <p>To sign up for our fabulous campaign of useless information that you will never, ever read, please submit your email address here.</p> <label for="email" id="emailLabel">Email</label> <input type="text" id="email" /> <input type="button" name="submit" value="Submit" id="submitButton" /> </fieldset> </form>
在您的圖例中使用position: absolute
,並在Fiedset上添加margin-top
以補償此偏移:
body { background-color: #996600; color: black; } fieldset { border: 10px solid #ffffff; border-radius: 10px; background-color: #999900; box-shadow: 10px 10px 5px #888888; position: relative; margin-top: 35px; } fieldset legend { position: absolute; top: -35px; left: 10px; font-size: 20px; } input[type=text] { border: 2px solid black; border-radius: 10px; background-color: #cccc80; } input[type=button] { background-color: #996600; border: 2px solid black; border-radius: 5px; color: #c9ae78; font-weight: bolder; } p { font-size: 12px; font-style: italic; }
<form method="post" id="contactForm" action="#"> <fieldset> <legend>Newsletter Signup</legend> <p>To sign up for our fabulous campaign of useless information that you will never, ever read, please submit your email address here.</p> <label for="email" id="emailLabel">Email</label> <input type="text" id="email" /> <input type="button" name="submit" value="Submit" id="submitButton" /> </fieldset> </form>
將以下內容添加到您的legend
:
legend {
position: absolute;
top: -1em;
width: 100%;
}
希望這可以幫助
您可以使用絕對定位。
HTML:
<form method="post" id="contactForm" action="#">
<fieldset>
<legend>Newsletter Signup</legend>
<p>To sign up for our fabulous campaign of useless information that you will never, ever read, please submit your email address here.</p>
<label for="email" id="emailLabel">Email</label>
<input type="text" id="email" />
<input type="button" name="submit" value="Submit" id="submitButton" />
</fieldset>
</form>
CSS:
body {
background-color: #996600;
color: black;
}
form { margin-top:30px; }
fieldset {
border: 10px solid #ffffff;
border-radius: 10px;
background-color: #999900;
box-shadow: 10px 10px 5px #888888;
position: absolute;
}
legend {
font-size: 20px;
text-align: left;
position:absolute;
top:-38px;
}
input[type=text] {
border: 2px solid black;
border-radius: 10px;
background-color: #cccc80;
}
input[type=button] {
background-color: #996600;
border: 2px solid black;
border-radius: 5px;
color: #c9ae78;
font-weight: bolder;
}
p {
font-size: 12px;
font-style: italic;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.