css - 当屏幕尺寸缩小时停止图像跳出位置

标签 css html

当我在运行下面的代码后缩小屏幕尺寸时,图像 phone.png 和所有文本跳出位置。我怎样才能阻止这种情况发生。

CSS:

    <style type="text/css">
    #wrapperlp {
        width: 100%;
        height:700px;
        margin-left:13%;
        margin-top:5%;
        background-image:url(https://***/blackbg.png);
        background-repeat:no-repeat;
        opacity:1;

    }

    #designbg {
        background-repeat:no-repeat;
        margin-left: 5%;
        padding-top: 3%;           
    }

文本样式

    #ad_head {           
        color: #f2852d;
        font-weight: bold;
        margin-left: 28%;
        margin-top: -21.5%;
        font-size: 21px;
    }

     #ad_message {
        margin-left: 28%;
        font-size:10px;
        color:white;
        font-weight:normal;
    }

phone.png 图片样式:

    #ad_logo {
        height: 500px;
        margin-left: 2%;
        margin-top: -42%;

    }

    #logobtm {
        margin-left: 2%;
        margin-top: -42%;
    }
</style>

HTML:

<div id="wrapperlp">
    <div id="designbg"><img src="https://*****/image.png" />
       <div id="ad_logo"><img src="https://****phone.png" /></div>

        <div>   
            <div id="ad_head">Text1<br />Text...</div>
            <div id="ad_message">Text2</div>
            <div id="logobtm"><img src="**.png" /></div>
        </div>

    </div>
</div>

最佳答案

您正在使用 margin-top 百分比。但是,边距的百分比是相对于窗口宽度而不是窗口高度来衡量的!

参见 http://www.w3.org/TR/CSS2/box.html#value-def-margin-width

解决方案:使用其他单位来表示元素的边距,或者使用其他方式在屏幕上定位它们(​​例如 top:5% 结合 position:absolute )。

关于css - 当屏幕尺寸缩小时停止图像跳出位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21673904/

相关文章:

html - 在 Mozilla 中热衷于使用 CSS3 过滤器?

jquery - IE 不加载 .load() 元素的 css & js 不工作

javascript - 使用 jquery 在不同的功能之间切换,而不是在它离开的地方恢复

javascript - 使用 Alert() 显示实际的 HTML 代码

javascript - 在 &lt;script&gt; 中调用还是使用 JavaScript?

html - CSS:Chrome 中的按钮大小与 Firefox 不同

css - Primefaces Accordion 面板背景颜色不起作用

带有更改标签的CSS复选框

PHP/MySQL : Values in a select box associate to values in associative array

javascript - 有没有办法通过重新呈现页面上的特定元素来强制浏览器修复无效标记?