简体   繁体   English

调整浏览器大小时如何阻止元素移动?

[英]How do i stop elements from moving when resizing the browser?

When i resize my browser my div tags resize themselves. 当我调整浏览器大小时,我的div标签会自行调整大小。 I've added min-width: which i thought would stop it but it does not. 我添加了min-width:我以为它可以停止它,但是不会。

html: 的HTML:

<div id="wrapper">
<div id="adleft"></div>
<div id="adright"></div>

css: CSS:

#wrapper{ 
  max-width: 50%;
  margin: 0 auto;
}

#adleft {
  height: 500px;
  min-width: 48%;
  background-color: red;
  float: left;
}
#adright {
  height: 500px;
  min-width: 48%;
  background-color: red;
  float: right;
}

The reason is that you are applying a min-width as a % not in px . 原因是您将min-width%而不是px

Using a % means that when the browser window shrinks 48% becomes less and less pixels. 使用%表示当浏览器窗口缩小时48%的像素越来越少。 If you define the min-width in pixels it will stop shrinking when it hits the minimum number of pixels you declare. 如果您定义min-width以像素为单位),则当达到您声明的最小像素数时,它将停止缩小。

Html: HTML:

<div id="wrapper">
<div id="ad">
    <div id="adleft"></div>
    <div id="adright"></div>
</div>

Include this in your Css: 将此包含在您的CSS中:

#ad
{
    Display: table;
    Margin-left: auto;
    Margin-right: auto;

}
#adleft 
{
    height: 500px;
    min-width: 48%;
    background-color: red;
    Margin-right:20px;
}
#adright
{
    height: 500px;
    min-width: 48%;
    background-color: red;
}

This worked for me : Html: 这对我有用:HTML:

<div id="wrapper">
<div id="adleft"></div>
<div id="adright"></div>

css: CSS:

#wrapper{ 
max-width: 960px;
min-width: 960px;
margin: 0 auto;
margin-top: 30px;
}

#adleft {
height: 500px;
width: 48%;
background-color: red;
float: left;
}
#adright {
height: 500px;
width: 48%;
background-color: red;
float: right;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM