我已经成功将它应用于白色背景:
header
),所有元素都设置了 display
属性,使它们显示为 table-cell
(example)。
<header>
<span class="spacer"></span><!-- Place this wherever you want the border -->
<h1>Title</h1>
<!-- Spacing is automatically added next to elements (but not on ends) -->
<span class="spacer"></span>
<a href="http://www.example.com/">View Blog</a>
</header>
header {
display:table-row;
line-height:1.5em;
font-size:2em;
white-space:nowrap; /* Prevent titles from wrapping when more than one word is used */
}
header h1 {
font-size:inherit; /* Change font-size in header */
overflow:hidden;
display:table-cell;
vertical-align:middle;
}
header span.spacer { /* Makes spacers stretch */
display:table-cell;
width:50%;
}
header span.spacer { /* Adds spacing on both sides of spacers */
padding:0 10px;
}
header span.spacer:first-child { /* Adds spacing only on right side of first spacer */
padding:0 10px 0 0;
}
header span.spacer:last-child { /* Adds spacing only on left side of last spacer */
padding:0 0 0 10px;
}
header span.spacer:after { /* Adds border to spacer */
display:inline-block;
width:100%;
content:".";
font-size:0;
color:transparent;
height:2px;
background:#000;
vertical-align:middle;
position:relative;
top:-1px;
}
header > a { /* Styles links according to example */
font-size:.4em;
vertical-align:middle;
background:#25a2a4;
color:#fff;
text-transform:uppercase;
font-family:monospace;
border-radius:.5em;
padding:.3em .5em;
text-decoration:none;
}
background:rgba(255,255,255,0.0);
alpha属性有助于设置不透明度的级别。
<fieldset>
标签来实现这个功能。<form>
<fieldset>
<legend class="blogLegend">New Blog Post</legend>
blog details here
</fieldset>
</form>
CSS
.blogLegend {
font-weight: 600;
color: rgb(63, 169, 196);
padding: 10px;
text-align: center;
}