将div粘贴到页面左侧

时间:2015-12-23 23:00:46

标签: html5 css3

我有一个容器,里面我有一个div我想坚持到屏幕的左角,但我总是有差距

我如何获得这样的东西?提前致谢

https://onedrive.live.com/redir?resid=22090721B1B171B7!12771&authkey=!AEDRyX0320pmcLk&v=3&ithint=photo%2cjpg

3 个答案:

答案 0 :(得分:1)

达到此目标的最基本方法是:

html, body {
    margin: 0;
    padding: 0;
}

并确保您的div左侧没有任何marginpadding(例如,当您使用时{{1}它将为您提供15px的左右填充。

答案 1 :(得分:1)

我希望能帮助你使用margin-top

这个例子https://jsfiddle.net/step/L9rn4fkg/
.sticky {
  width:100px;
  height:100px;
  float: left;
  position: fixed;
  background-color: #30cff0;
  margin-top:50px;
  z-index:1000;
}

答案 2 :(得分:1)

我认为你应该重置你的身体(或你想要坚持的元素)保证金 你可以使用:

* { /* it's a hard method */
  margin: 0;
  padding: 0;
}


.fix-el {
  position: fixed;
  width: 100px;
  height: 100px;
  
  /* center it */
  line-height: 100px;
  border: 1px solid #EEE;
  top: 50%;
  margin-top: -50px;
  text-align: center;
}
<div class="fix-el">
    fix this
</div>

希望你能解决它

相关问题