Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在调整浏览器大小时,如何保持图像的位置?_Javascript_Html_Css - Fatal编程技术网

Javascript 在调整浏览器大小时,如何保持图像的位置?

Javascript 在调整浏览器大小时,如何保持图像的位置?,javascript,html,css,Javascript,Html,Css,您好,在我的页面上,我有两个字符的图像,我把它们放在文本和横幅的两侧,这是一张图片,但问题是,当我重新使用浏览器时,图像会跟随浏览器,它们不会停留在相同的位置,我不希望发生这种情况,因为我有一个固定的布局,这是css代码,我不知道如何把它贴好,但无论如何 .support-text { width: 600px; margin-left: auto; margin-right: auto; line-height: -2px; margin-bottom: 1

您好,在我的页面上,我有两个字符的图像,我把它们放在文本和横幅的两侧,这是一张图片,但问题是,当我重新使用浏览器时,图像会跟随浏览器,它们不会停留在相同的位置,我不希望发生这种情况,因为我有一个固定的布局,这是css代码,我不知道如何把它贴好,但无论如何

.support-text {
  width: 600px;
    margin-left: auto;
    margin-right: auto;
    line-height: -2px;
    margin-bottom: 130px;

}

.support-text h1 {
  font-size: 30px;
}

.support-text {
  clear: left;
}

.support-text {
  font-size: 23px;
}

.support-img {
  margin-top: -80px;
  margin-bottom: 80px;
  z-index: 1;
}

.ct-pic {
  position: absolute;
  right: 10px;
  bottom: 30px;
  float: right;
}

.ct-pic:hover {
  -webkit-filter: brightness(180%);
}

.t-pic:hover {
  -webkit-filter: brightness(180%);
}

.t-pic {
  position: absolute;
  left: 40px;
  bottom: 30px;
  float: left;
}
这是html

<section class="support-text">
          <div class="ct-pic"> </div>
     <div class="t-pic" width="867" height="569"></div>
      <img src="img/support-us.png" class="support-img">
      <p>Hello, if this site has helped you improve your gameplay, and learn useful stuff, feel free to support us, so we can keep this website up, so more people can learn. You can support through Steam or throught paypal. Keep in mind that you do not have to support, but if you do, we appreciate it alot. and we can continue to upload new content (Smokes, flashes, tactics) to the website. </p>

    </section>

您好,如果这个网站帮助您提高了游戏性,并学习了有用的东西,请随时支持我们,这样我们就可以保持这个网站,让更多的人可以学习。您可以通过Steam或paypal提供支持。请记住,您不必支持,但如果您支持,我们将非常感谢。我们还可以继续向网站上传新内容(烟熏、闪光、战术)


以下是一个示例,说明如何在调整窗口大小时,在不移动或改变位置的情况下将对象放置在彼此相邻的位置(div可以是img标记或任何您想要的标记)。只需将它们放在一个固定宽度的“容器”中,然后将它们漂浮在该容器内

<div id='container'> 
    <div id='image-1' class='image'></div>
    <div id='image-2' class='image'></div>
    <div id='image-3' class='image'></div>
</div>

#container {
    width: 200px;
    height: 100px;
    background: black;
}
.image {
    background: white;
    width: 20px;
    height: 20px;
    float: left;
    margin: 20px;
}

#容器{
宽度:200px;
高度:100px;
背景:黑色;
}
.形象{
背景:白色;
宽度:20px;
高度:20px;
浮动:左;
利润率:20px;
}

更新


你的css有问题。将子元素的位置设置为绝对,这会使它们忽略其父元素,并相对于整个窗口进行定位。当这种情况发生时,子元素会在调整窗口大小时开始移动。

您还需要包含html和任何javascript。不要使用图像
,使用
div
background
设置为图像链接,并给它一个固定的宽度。我们也需要查看html,但你不能完全浮动和定位某个内容…选择一个或另一个。你可以对生成的代码进行一些测试,看看要使用哪一个。这里有一个小提琴来演示你的选项调整提琴宽度以查看图像的变化情况我将它们放在一个容器中,并使用一个固定的WithWith。您的问题是您的子div有一个
位置:绝对
,这使得它们相对于窗口的位置,不是它们的父div。您需要删除
位置:绝对
并使用浮动或
位置:相对