[确认:IE9遭受同样的错误! :'(]
我有一个div,就像一个相框风格的东西,它包含一个img和两个div。这个外部div具有最大宽度(80%),可以很好地工作。
问题是,如果我设置了最大高度,我会得到以下行为:
有什么建议吗? Doc-type是<!doctype html>
,完全有效,通常效果很好。我甚至沮丧地添加了<meta http-equiv="X-UA-Compatible" content="IE=9">
。
编辑:
这是我认为相关的html / css:
<!doctype> <html> <head> <meta http-equiv="X-UA-Compatible" content="IE=9"> <script type="text/javascript" src="https://getfirebug.com/firebug-lite-beta.js"></script> <style type="text/css"> html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video { margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline; } /* HTML5 display-role reset for older browsers */ article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; } body { line-height: 1; } ol, ul { list-style: none; } blockquote, q { quotes: none; } blockquote:before, blockquote:after, q:before, q:after { content: ''; content: none; } table { border-collapse: collapse; border-spacing: 0; } body { background-color:black; color:black; font-size:80%; font-family:'Merriweather',georgia,serif; max-width:1600px; min-width:780px; text-align:center; margin:0 auto; line-height:1.1; } div#container { text-align:left; padding:1em 15px; margin:2em 5px; position:relative; background:#FFE4BE; } div.image { background:white; max-width:80%; max-height:20%; <--- HAS NO EFFECT! overflow:hidden; margin:0 auto; display:block; padding:2em 2% 1em 2%; } div.image img { width:100%; margin:0 auto; display:block; } div.image div.title { font-size:160%; font-weight:bold; text-align:center; margin-top:0.25em; } div.image div.caption { font-style:italic; text-align:center; } </style> </head> <body> <div id="container"> <div id="body"> <div class="image"> <img src="construction.jpg"> <div class="title">Construction</div> <div class="caption"> <p>Turns out, we're not ready for beta users yet.</p> <p>We'll have a mailing list available soon. Check back periodically!</p> </div> </div> </div> </div> </body> </html>
答案 0 :(得分:0)
使用* html
即可。
* html .whatever{
height:100%;
}
答案 1 :(得分:0)
对于您正在做的事情,将图像容器设置为具有良好的边距并将最大宽度设置为100%会更容易。您可能不希望强制最大高度小于视口,因为人们习惯于垂直滚动以查看大/长图像。
答案 2 :(得分:0)
你需要采用一种新的方法 - 使用max-height来缩放图像只是错误的方法,你很可能永远不会达到你喜欢的解决方案。
如果我是你,我会回到绘图板并重新考虑布局(不是设计,只是标记和css),并试图以另一种方式达到设计目标。