[英]How do I place the legend outside the fieldset border
I am going crazy trying to figure out how to make this work. 我疯了试图找出如何使这项工作。 I would like the legend to be outside of the border.
我希望图例在边界之外。 How can I make this happen while keeping the legend tag?
如何在保留图例标签的同时实现此目的? As you can see below I tried using span but it is not working.
如您在下面看到的,我尝试使用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>
Use position: absolute
for your legend, and add a margin-top
on your fiedset to compensate this shift: 在您的图例中使用
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>
Add the following to your legend
: 将以下内容添加到您的
legend
:
legend {
position: absolute;
top: -1em;
width: 100%;
}
Hope this helps 希望这可以帮助
You could use absolute positioning. 您可以使用绝对定位。
HTML: 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: 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.