這是我的第一個問題,所以請指出我犯的任何錯誤。
我被迫創建了一個看起來像團隊旗幟的網頁。我已經設法做到這一點,但只有固定大小的元素:
在其他分辨率,它只是不適合屏幕。
代碼:
HTML
創建可調整大小的網站缺乏CSS技能 - CSS形狀
<div id="centered">
<div id="triangle-down"></div>
<div id="triangle-right"></div>
<div id="triangle-left"></div>
<div id="triangle-up"></div>
<div id="diamond-narrow"></div>
</div>
CSS
#centered {
position:relative; clear:left;
height:766px; width:1245;
margin:0 auto;
background:#fff;
z-index: 0;
}
#triangle-up {
position: absolute;
margin-left: 281px;
margin-top: 555px;
width: 0;
height: 0;
border-left: 341px solid transparent;
border-right: 341px solid transparent;
border-bottom: 211px solid #3b5998;
z-index: 1;
}
#triangle-down {
position: absolute;
margin-left: 281px;
width: 0;
height: 0;
border-left: 341px solid transparent;
border-right: 341px solid transparent;
border-top: 211px solid #3b5998;
z-index: 1;
}
#triangle-left {
position: absolute;
margin-left: 902px;
margin-top: 171px;
width: 0;
height: 0;
border-top: 211px solid transparent;
border-right: 343px solid #3b5998;
border-bottom: 211px solid transparent;
z-index: 1;
}
#triangle-right {
position: absolute;
margin-top: 171px;
width: 0;
height: 0;
border-top: 211px solid transparent;
border-left: 343px solid #3b5998;
border-bottom: 211px solid transparent;
z-index: 1;
}
#diamond-narrow {
margin-left: 342px;
width: 0;
height: 0;
border: 280px solid transparent;
border-bottom: 173px solid red;
position: absolute;
top: -70px;
}
#diamond-narrow:after {
content: '';
position: absolute;
left: -280px; top: 173px;
width: 0;
height: 0;
border: 280px solid transparent;
border-top: 173px solid red;
}
這裏是我的標誌的的jsfiddle:click
正如你可以看到我使用的CSS形狀繪製三角形和菱形。我的問題是:
如何讓該標誌(網頁)適合不同的屏幕分辨率?如何以百分比呈現我的形狀的寬度和高度?
正如我讀到here,例如。邊界左側的值不能以%表示。
編輯
感謝@joe_coolish,我設法讓該網頁調整大小。但是,我還有一個問題。
這裏是我的html:
<table width="100%" style="height: 100%;">
<tr>
<td width="10%" height="10%"></td>
<td></td>
<td width="10%" height="10%"></td>
</tr>
<tr>
<td width="10%" height="10%"></td>
<td id="centered" bgcolor="white">
<div id="main"/>
</td>
<td width="10%" height="10%"></td>
</tr>
<tr>
<td width="10%" height="10%"></td>
<td></td>
<td width="10%" height="10%"></td>
</tr>
</table>
更改喬代碼:
var main = $('#main');
function update() {
var height = $('#centered').height();
var width = $('#centered').width();
...
$('#centered').resize(function() {
update();
});
現在,當我打開我的網頁,出現這種情況:
我要檢查一些元素才能正常工作了。爲什麼?
有時圖像是正確的道路要走。 –
請不要鏈接到您的網站 - 一旦它發生變化,它就會與您的問題無關,從而降低其對其他用戶的價值。 –
如果你想調整窗口大小,你可以使用jquery。看到這個例子:http://stackoverflow.com/questions/2758651/how-to-change-height-div-on-window-resize – zehelvion