a:hover{
cursor:url(files/link.cur),progress;
}
body{
width:80%;
background-color:rgba(255,255,255,0.75);
margin:auto;
height: 100%;
min-height: 100%;
}
html{
Background-color:#8888FF;
background-image:url(files/bg.jpg);
background-attachment:fixed;
background-position:center;
background-size:cover;
height:100%;
}
html, body{
cursor:url(files/cursor.cur),progress;
}
iframe{
overflow:hidden;
height:80%;
width:100%;
border-width:1px;
}
img{
display:block;
margin-left:auto;
margin-right:auto;
width:90%;
}
p{
margin-right:10px;
margin-left:10px;
text-align:center;
font-family:calibri;
font-size:16px;
}
#menu a{
display:inline-block;
background-color:#0066FF;
text-decoration:none;
font-family:calibri;
color:#FFFFFF;
padding:10px 10px;
}
#menu a:hover{
background-color:#00AAFF;
}
a.active{
background-color:#0088FF !important;
}
a.active:hover{
background-color:#00AAFF !important;
}<!DOCTYPE html>
<html>
<head>
<title>
Foto's
</title>
<link rel="icon" type="image/png" href="files/icon.png">
<link rel="stylesheet" href="style.css">
<script src="files/javascript.js">
</script>
</head>
<body onload="start()">
<br>
<div id="menu">
<p style="font-size:20px;">
<a href="index.html">
Welkom
</a><a href="agenda.html">
Agenda
</a><a href="fotos.html">
Foto's
</a><a href="contact.html">
Contact
</a>
</p>
<p style="font-size:16px;">
<a onclick="go('camera/1993-1994.html', this)">
1993-1994
</a><a onclick="go('camera/1994-2003.html', this)">
1994-2003
</a><a onclick="go('camera/2003-2004.html', this)">
2003-2004
</a><a onclick="go('camera/2005-2006.html', this)">
2005-2006
</a><a onclick="go('camera/2006-2007.html', this)">
2006-2007
</a><a onclick="go('camera/2007-2008.html', this)">
2007-2008
</a><a onclick="go('camera/2008-2009.html', this)">
2008-2009
</a><a onclick="go('camera/2009-2010.html', this)">
2009-2010
</a><a onclick="go('camera/2011-2012.html', this)">
2011-2012
</a><a onclick="go('camera/2013-2014.html', this)">
2013-2014
</a><a onclick="go('camera/2014-2015.html', this)" id="one">
2014-2015
</a>
</p>
</div>
<iframe id="iframe">
</iframe>
</body>
</html>
我已经将iframe的高度设置为80%,但它不起作用。当主体的高度设置为100%时,它确实可以工作,但我现在使用的是min-height,这个问题就出现了。另外,我也不能使用margin left和margin right:auto;将iframe居中。有人知道为什么CSS属性不起作用以及如何修复它吗?
非常感谢!
发布于 2015-04-20 00:00:17
这句话对height继承做了一个非常清晰的解释:
当您对高度使用百分比值时,它将始终相对于父元素的指定高度。不是父元素的实际高度,而是CSS中指定的高度。
因此,当你的body元素没有指定高度(只有min- height,但这不算)时,100%将不能生效。
https://stackoverflow.com/a/20681480/3168107
对于这个问题,没有一个简单的解决方法(我确实搜索过了),它可以允许最小高度,但也可以使元素在使用html和body时适应屏幕溢出,而顶层没有绝对尺寸。所以这将是最简单的替代方案:
iframe {
height: 80vh;
}不需要以这种方式在任何根元素上设置任何高度...
另一种选择是给iframe绝对定位。如果没有定位的父对象,它将恢复为视口的高度。它基本上与上面的效果相同,但有更深的浏览器支持(尽管所有现代浏览器都支持它有一段时间了)。另一方面,不使用绝对定位在语义上更正确,并提供更好的页面流。
使用display: table也是可能的,因为高度被视为表元素的最小高度,但这将是最老套的方法。
边距问题可以通过将样式设置为display: block或为父级提供text-align: center来解决。iframe是一个内联元素...
https://stackoverflow.com/questions/29730977
复制相似问题