Jaï*_*man 5 html css iframe height center
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;
}Run Code Online (Sandbox Code Playgroud)
<!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>Run Code Online (Sandbox Code Playgroud)
我已经将 iframe 的高度设置为 80% 但不起作用。当身体高度设置为 100% 时它确实有效,但我现在使用 min-height 并且出现了这个问题。另外,我无法使用 margin-left 和 margin-right:auto; 将 iframe 居中。有谁知道为什么 CSS 属性不起作用以及如何修复它?
非常感谢!
这句话对高度继承给出了非常清晰的解释:
当您使用高度的百分比值时,它将始终相对于父元素的指定高度。不是父元素的实际高度,而是 CSS 中指定的高度。
所以当你的body元素没有指定高度时(只有min-height,但这不算),100%将无法生效。
没有一个简单的解决方案(我肯定搜索过),既可以允许最小高度,又可以使元素在使用时适应屏幕溢出html,并且body顶层没有绝对尺寸。所以这将是最简单的选择:
iframe {
height: 80vh;
}
Run Code Online (Sandbox Code Playgroud)
不需要这样在任一根元素上设置任何高度......
另一种选择是为 iframe 提供绝对定位。如果没有定位的父级,它将恢复到视口的高度。它的效果与上面基本相同,但具有更深入的浏览器支持(尽管所有现代浏览器都已经支持它一段时间了)。另一方面,不使用绝对定位在语义上更正确,并且提供更好的页面流。
使用display: table也是一种可能性,因为高度被视为表格元素的最小高度,但这将是最简单的方法。
边距问题可以通过将样式设置为display: block或给父级一个 来解决text-align: center。iframe 是一个内联元素...
http://codepen.io/anon/pen/dobdYZ?editors=110
| 归档时间: |
|
| 查看次数: |
22938 次 |
| 最近记录: |