html - 展开窗口时按钮位置发生变化

标签 html css

我正在尝试设计一个网页,其中顶部部分是一个带有透明按钮的图像。问题是每次我最小化窗口时,按钮都会改变位置。谁能告诉我问题出在哪里?

<html lang=="en">
<meta name="viewport" content="width=device-width, initial-scale=1">

<head>
  <meta charset="utf-8">
  <title>Deut65</title>
  <link href="site.css" rel="stylesheet">
</head>

<body>

<ul id="nav">
  <img id="logo" src="logo.png"></img>
  <li><a href="#home">Home</a></li>
  <li><a href="#editor">Editor</a></li>
  <li><a href="#about">About</a></li>
</ul>


   <div id="image-div">
      <img id="top-image"src="fotoDeut65.jpeg">
      <button id="image-button">Button</button>
   </div>


<style>


 #image-div{ 
  top: -50%; 
  left: -50%; 
  width: 100%; 
  height: 100%;
 }

#top-image{
  position: absolute;  
  top: 0; 
  left: 0; 
  right: 0; 
  bottom: 0; 
  margin: auto; 
  min-width: 100%;
  min-height: 100%;
  width: 400px;
  height: auto;
}

#image-button{
    position: relative;
    z-index: 1;
  margin-left: auto;
  margin-right: auto;
   top: 191px;
    left: 420px;
    right: -420px;
    bottom: -191px;
}
</style>




<!--until here-->
</body>
</html>

最佳答案

设置position:absolute;如果你想让按钮在img上 float 上面的样式有错误,尝试下面的来综合:

<style>
 #image-div{ background:lightblue;
 }

#top-image{
 width:100px;height:100px;
}

#image-button{background:red;    
 position: absolute;
 left:0;
 width:100px;height:100px; 
}
</style>

关于html - 展开窗口时按钮位置发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38552145/

相关文章:

html - margin、padding、border 都为零后还有空间吗?

css - 使用 css IE8 在 <li> 中拉伸(stretch)图像

javascript - 目标高度未知(不固定)时如何实现元素高度过渡

javascript - 按钮单击事件触发错误的事件处理程序

javascript - D3 : change font size of axis labels

HTML CSS : Best way to Create Search Bar with Magnify Button

html - 在没有文本对齐中心的页脚中居中文本

css - 类 :before and class:after is not working in ie7

javascript - 未定义 Uncaught ReferenceError

php mysql 插入表工作一次,不再工作?