【问题标题】:popup alert going off the screen when resizing调整大小时弹出警报离开屏幕
【发布时间】:2013-03-25 19:00:55
【问题描述】:

当用户在图标上移动鼠标时,我有一个弹出框。悬停的css如下:-

.profile-bubble {
background-color: #EDEDED;
border: 2px solid #666666;
font-size: 15px;
font-weight: bold;
line-height: 1.3em;
margin: 0.6% 2% 2% 90%;
padding: 10px;
position: absolute;
text-align: center;
width: 150px;
opacity: 0.9;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
-moz-box-shadow: 0 0 5px #888888;
-webkit-box-shadow: 0 0 5px #888888;

}

这很好用,但问题是当我调整屏幕大小时,或者如果用户的分辨率比我小,那么警报框就会消失在屏幕之外。

如何修改这个 css 使其与屏幕大小成比例?

感谢您的帮助和时间。

更新--------------------------------- -------- 这是标题 css:-

/* Header*/

标题{ 底部填充:5px; }

#headerContainer {
height: 33px;
background-position: 10px 2px;
padding-top: 2px;

}

.headerProfileNotifications {
float: right;
padding-right: 4px;
margin: 3px;
position: relative;

}

.headerProfilePhoto {
float: right;
position: relative;
margin: 3px;

}

img {
border: 1px solid #D5D5D5;    

}

img {
border: 1px solid #D5D5D5;    

}

img:hover {
border: 2px solid #000000;    

}

.headerProfileDetails {
float: right;
padding-right: 4px;
font-size: 11px;
text-align: right;

}

.headerProfileName {
margin-top: 2px;

}

.headerProfileEmail {
clear:both;
float:right;
margin-top: 0px;

}

和 html:-

<header>
        <div class="content-wrapper">
            <div id="headerContainer">
                <div class="headerProfileNotifications">
                        <img src="Images/" alt="notification" />
                </div>
                <div class="headerProfilePhoto">
                        <img src="Images/" alt="profile_photo" />
                </div>
                <div class="headerProfileDetails">
                    <div class="headerProfileName">
                            John Smith
                    </div>
                    <div class="headerProfileEmail">
                            john.smith@somemail.co.uk
                    </div>

                </div>
            </div>
         </div>
    </header>

【问题讨论】:

  • 你是在 JS 中添加定位吗,因为我看到你设置了绝对定位,但是没有上/左/下/右?

标签: jquery asp.net html css


【解决方案1】:

宽度和高度也是百分比 -

width:50%;
height:50%;

并将框大小设置为边框框,这样您就不必考虑边距、填充等。这一切都只进入宽度。

然后相应地定位它(你有position:absolute) -

top:20%;
left:20%;

您的图片和气泡必须位于容器内,且容器内没有其他元素。
看到这个example on codepen.
此容器必须相对定位。

【讨论】:

  • 我确实放了百分比,虽然现在看起来好多了,但它仍然没有在图像下正确对齐。
  • 我试过了:0;和顶部:5%,这是最好的位置,但是在调整大小时仍然没有正确对齐
  • 您希望此气泡对齐的图像是否具有位置:静态?它必须是除此之外的任何内容,否则 position:absolute 将不起作用。
  • 我有以下图片的css:- .headerProfilePhoto { float: right;高度:33px;宽度:22px;边距:5px; }
  • 感谢 Vineet 的示例,它帮助我解决了我的问题!
【解决方案2】:

尝试将lefttop 属性放入css:

.profile-bubble {
    background-color: #EDEDED;
    border: 2px solid #666666;
    font-size: 15px;
    font-weight: bold;
    line-height: 1.3em;
    margin: 0.6% 2% 2% 90%;
    padding: 10px;
    position: absolute;
    text-align: center;
    width: 150px;
    opacity: 0.9;
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    -moz-box-shadow: 0 0 5px #888888;
    -webkit-box-shadow: 0 0 5px #888888;
    left:25%; //<-------------------------------add this
    top:25%;  //<-------------------------------and this
 }

【讨论】:

  • 我试过了:0;和顶部:5%,但仍未正确对齐
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-08-21
  • 2014-06-20
  • 2011-09-01
  • 2016-04-20
  • 2011-02-03
  • 2017-07-06
  • 1970-01-01
相关资源
最近更新 更多