0

我正在尝试使图像响应浏览器的大小,以便当浏览器较小时,图像会响应,从而不涉及滚动。我在这里发现了一个类似的问题How can I resize an image dynamic with CSS as the browser width/height changes?,但我无法使该解决方案发挥作用。我错过了什么?

我在下面包含我的代码 - 我使用的是 Wordpress,所以它会自动在我的图像周围放置一个“p”标签,将我的图像包装在一个段落中。另外,我不确定我是否为此目的包含了太多代码,但我想确保它都在那里,以防万一在一个可能导致问题的奇怪地方出现错误......

这是我的html:

<body>
<div id="pop_up_page">
    <div class="content_well_pop">
        <div class="content_pop">
            <div class="portfolio_workspace_9">
                <h2>Here's the Header</h2>
            </div>
            <div class="portfolio_workspace_8">
                <p>
                    <img src="heres_the_image"/>
                </p>
            </div>
        </div>
    </div>
</div>
</body>

这是我的CSS:

body {
background-attachment: fixed;
margin-top: 0px;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
padding: 0;
height: 100%;
}

#pop_up_page {
background-attachment: fixed;
margin-top: 0px;
margin-bottom: 0px;
margin-left: 0px;
margin-right: 0px;
padding: 0;
height: 100%;

.content_well_pop {
left: 0;
width: 100%;
}

.portfolio_workspace_9 {
width: 1000px;
margin: 15px 0 0 0px;
position: relative;
float: left;
display:block;}

.portfolio_workspace_8 {
width: 1000px;
margin: 0px 0 50px 0px;
position: relative;
float: left;
height: auto;
display:block;}

p{font-family: "Franklin Gothic Book";
font-size: 15px;
color: #757372;
display: block;
}

.portfolio_workspace_8 img {
margin-left: auto;
margin-right: auto;
display: block;
max-width: 100%;
height: auto;
}

谢谢

4

2 回答 2

2

这个CSS规则在这里:

.portfolio_workspace_8 {
width: 1000px; 
margin: 0px 0 50px 0px;
position: relative;
float: left;
height: auto;
display:block;
}

您在图像的父容器上指定宽度。将其更改为最大宽度而不是宽度。

于 2013-05-24T17:18:25.460 回答
0

这是您正在寻找的无 javascrpt、跨浏览器稳定的解决方案。我过去曾在该网站上实施过它:http ://www.gardinenhaus-morgen.de/ 。

HTML:

<html>
    <body>
    <div id="page-wrapper">
        <div id="inner-wrapper">

        <!-- your content here -->    

        </div>
    </div>
        <div id="bg">
           <div>
               <table cellpadding="0" cellspacing="0">
                   <tr>
                       <td>
                           <img alt="background" src="<bild>" />
                       </td>
                   </tr>
               </table>
           </div>
        </div>
    </body>
</html>

CSS:

#bg div
{
    position: absolute;
    width: 200%;
    height: 200%;
    top: -50%;
    left: -50%;
}

#bg td
{
    vertical-align: middle;
    text-align: center;
}

#page-wrapper
{
    position: absolute;
    top: 0;
    left: 0;
    z-index: 70;
    overflow: auto;
    width: 100%;
    height: 100%;
}

#inner-wrapper
{
   margin: 30px auto;
   width: 1000px;
}
于 2013-05-24T21:20:26.207 回答