【发布时间】:2022-05-10 17:19:45
【问题描述】:
我想要一个如下所示的 div:
这可能与 HTML + CSS 相关吗?我还将使用 jQuery 为这个 div 设置动画。当 div 被隐藏时,我希望显示标题和顶行。
【问题讨论】:
我想要一个如下所示的 div:
这可能与 HTML + CSS 相关吗?我还将使用 jQuery 为这个 div 设置动画。当 div 被隐藏时,我希望显示标题和顶行。
【问题讨论】:
是的,但不是div,而是fieldset
fieldset {
border: 1px solid #000;
}
<fieldset>
<legend>AAA</legend>
</fieldset>
【讨论】:
display:fieldset CSS 设置。可惜没有。
您可以这样做,在h1(或您正在使用的任何标题)上设置一个否定的margin
div{
height:100px;
width:100px;
border:2px solid black;
}
h1{
width:30px;
margin-top:-10px;
margin-left:5px;
background:white;
}
注意:您需要在h1 上设置background 和width
编辑
为了使它能够隐藏div,你可以使用一些像这样的jQuery
$('a').click(function(){
var a = $('h1').detach();
$('div').hide();
$(a).prependTo('body');
});
(您需要修改...)
示例 #2: http://jsfiddle.net/ZgEMM/4/
【讨论】:
float: left;代替width: XXpx;。
我知道聚会有点晚了,但我觉得答案可以通过更多调查/输入来完成。 我已经设法在不使用 fieldset 标记的情况下创建了这种情况 - 无论如何这都是错误的,就好像我不在一个表单中那么这不是我应该做的。
/* Styles go here */
#info-block section {
border: 2px solid black;
}
.file-marker > div {
padding: 0 3px;
height: 100px;
margin-top: -0.8em;
}
.box-title {
background: white none repeat scroll 0 0;
display: inline-block;
padding: 0 2px;
margin-left: 8em;
}
<aside id="info-block">
<section class="file-marker">
<div>
<div class="box-title">
Audit Trail
</div>
<div class="box-contents">
<div id="audit-trail">
</div>
</div>
</div>
</section>
</aside>
这可以在这个plunk中查看:
这样做的结果如下:
不使用字段集。
如果 CSS 仅使用一些填充来创建效果,则最少使用。
使用“em”页边距创建字体相对标题。
使用显示内联块来实现文本周围的自然宽度。
无论如何,我希望这对未来的造型师有所帮助,你永远不会知道。
【讨论】:
.box{
background-image: url("https://i.stack.imgur.com/N39wV.jpg");
width: 350px;
padding: 10px;
}
/*begin first box*/
.first{
width: 300px;
height: 100px;
margin: 10px;
border-width: 0 2px 0 2px;
border-color: #333;
border-style: solid;
position: relative;
}
.first span {
position: absolute;
display: flex;
right: 0;
left: 0;
align-items: center;
}
.first .foo{
top: -8px;
}
.first .bar{
bottom: -8.5px;
}
.first span:before{
margin-right: 15px;
}
.first span:after {
margin-left: 15px;
}
.first span:before , .first span:after {
content: ' ';
height: 2px;
background: #333;
display: block;
width: 50%;
}
/*begin second box*/
.second{
width: 300px;
height: 100px;
margin: 10px;
border-width: 2px 0 2px 0;
border-color: #333;
border-style: solid;
position: relative;
}
.second span {
position: absolute;
top: 0;
bottom: 0;
display: flex;
flex-direction: column;
align-items: center;
}
.second .foo{
left: -15px;
}
.second .bar{
right: -15.5px;
}
.second span:before{
margin-bottom: 15px;
}
.second span:after {
margin-top: 15px;
}
.second span:before , .second span:after {
content: ' ';
width: 2px;
background: #333;
display: block;
height: 50%;
}
<div class="box">
<div class="first">
<span class="foo">FOO</span>
<span class="bar">BAR</span>
</div>
<br>
<div class="second">
<span class="foo">FOO</span>
<span class="bar">BAR</span>
</div>
</div>
【讨论】:
<fieldset>
<legend> YOUR TITLE </legend>
<p>
Lorem ipsum dolor sit amet, est et illum reformidans, at lorem propriae mei. Qui legere commodo mediocritatem no. Diam consetetur.
</p>
</fieldset>
【讨论】:
您可以使用字段集标签。
<!DOCTYPE html>
<html>
<body>
<form>
<fieldset>
<legend>Personalia:</legend>
Name: <input type="text"><br>
Email: <input type="text"><br>
Date of birth: <input type="text">
</fieldset>
</form>
</body>
</html>
查看此链接:HTML Tag
【讨论】:
对于duplicate,这里是另一个带有转换的选项,没有字段集(副本中需要圆角边框):
位置或变换也可以帮助您:
* { margin: 0; padding:0; box-sizing:border-box; } .fieldset { border: solid; color: #353fff; border-radius: 1em; margin: 2em 1em 1em; padding:0 1em 1em; } .legend { transform: translatey(-50%); width: max-content; background: white; padding: 0 0.15em; } .fieldset li { list-style-type: " - "; }<div class="fieldset"> <h1 class="legend">Some Title</h1> <ul> <li>Item</li> <li>Item</li> <li>Item</li> <li>Item</li> </ul> </div>
【讨论】:
如果您无法添加字段集,您可以为元素添加背景。在我的情况下,我在输入元素和输入元素之外有不同的颜色,而且我们有输入元素的悬停颜色。所以这是一个修复,我添加了线性渐变背景,上半部分为外部颜色,下半部分为透明颜色。 我在下半部分添加了透明颜色,以便在悬停时看到悬停颜色。
.class-name {
background: linear-gradient(to bottom, #2a2b2d 50%, transparent 50%);
}
【讨论】:
可以使用图例标签。 参考http://www.w3schools.com/html5/tag_legend.asp
【讨论】:
fieldset 和 legend 标签不是 HTML5
audio 是。