这是我的第一个问题,所以请指出我犯的任何错误。
我被迫创建了一个看起来像团队旗帜的网页。我已经设法做到这一点,但只有固定大小的元素:
在其他分辨率,它只是不适合屏幕。
代码:
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