我試圖創建標頭與傾斜的邊緣,保持其縱橫比無論他們出現什麼樣的高度。這是可能完成使用CSS單獨?DIV與傾斜的邊緣,保持長寬比
此圖像顯示了頭的樣子,如果他們只有一條線長:
,如果他們兩個或更多的線長,他們應該出現像:
我正在運行的問題是我無法使白色半邊三角形覆蓋標題的右側部分來調整大小,更不用說調整其相同寬高比。下面是多線會發生什麼原樣:
現在顯示標題的代碼是:
HTML:
<header>
<nav>
<ul>
<li><a href="#">Public Information</a></li>
</ul>
</nav>
<h1>Board Meeting Schedule</h1>
</header>
CSS:
* {
font-family: sans-serif;
font-size: 16px;
font-weight: normal;
line-height: normal;
margin: 0;
}
header {
background: #0D3C5B;
display: inline-block;
overflow: hidden;
padding: 18px 80px 12px 20px;
position: relative;
}
header:before {
border-left: 58px solid transparent;
border-top: 62px solid #FFF;
content: "\0020";
display: block;
height: 0;
position: absolute;
right: 0;
top: 0;
width: 0;
}
header nav {
float: left;
margin: 0 6px 0 0;
}
header nav ul {
color: #42AFE3;
display: inline-block;
font-size: 0.75em;
font-weight: bold;
line-height: 1.6666666666666666666666666666667em;
line-height: 2.25em;
list-style: normal;
margin: 0;
padding: 0;
text-transform: uppercase;
}
header nav ul li {
display: inline-block;
}
header nav ul li a {
color: #42AFE3;
text-decoration: none;
}
header nav ul li:after {
content: "\003E";
padding: 0 4px;
}
header h1 {
color: #FFF;
float: left;
font-size: 1.25em;
font-weight: bold;
line-height: 1em;
text-transform: uppercase;
}
header:after {
clear: both;
content: "\0020";
display: block;
visibility: hidden;
}
這裏是一個小提琴:http://jsfiddle.net/doLuj6me/
我寧願通過使用背景圖像來解決它 –
我不會,因爲背景圖像不能很好地縮放。我總是喜歡儘可能使用CSS。 – JacobTheDev