首页 > 解决方案 > 将 css 框移动到屏幕顶部

问题描述

CSS完整的新手在这里。我正在尝试将我的“框”推到页面顶部。我玩过css文件,但不知道如何完美地放置它。我认为我面临的挑战是高度和边距。我在这里从 codepen 复制了 css 。

我的目标是将盒子从底部移动到(几乎)顶部。

#box-dynamic {
  width: 420px;
  line-height: 25px;
  background: rgba(0, 0, 0, 0.2);
  float: left;
  position: absolute;
  bottom: 0;
  z-index: 500 !important;
  -ms-transition: all 0.3s ease-out;
  -moz-transition: all 0.3s ease-out;
  -webkit-transition: all 0.3s ease-out;
  -o-transition: all 0.3s ease-out;
  transition: all 0.3s ease-out;
}

#box-dynamic.minimize {
  height: 50px;
  line-height: 5px;
}

#box-dynamic h1 {
  margin-right: 5px;
  color: #fff;
  font-size: 20px;
  font-family: 'Roboto Condensed', sans-serif;
  margin-left: 5px;
  -ms-transition: all 0.3s ease-out;
  -moz-transition: all 0.3s ease-out;
  -webkit-transition: all 0.3s ease-out;
  -o-transition: all 0.3s ease-out;
  transition: all 0.3s ease-out;
}

#box-dynamic.minimize h1 {
  font-size: 20px;
  text-align: center;
}

#box-dynamic p {
  color: #ccc;
  font-size: 15px;
  line-height: 1.4;
  margin-left: 5px;
  font-family: 'Roboto Condensed', sans-serif;
  -ms-transition: all 0.3s ease-out;
  -moz-transition: all 0.3s ease-out;
  -webkit-transition: all 0.3s ease-out;
  -o-transition: all 0.3s ease-out;
  transition: all 0.3s ease-out;
}

#box-dynamic.minimize p {
  font-size: 0px;
}

#box-dynamic small {
  color: #ccc;
  font-size: 11px;
  font-family: 'Roboto Condensed', sans-serif;
  margin-left: 5px;
  margin-top: 0;
  -ms-transition: all 0.3s ease-out;
  -moz-transition: all 0.3s ease-out;
  -webkit-transition: all 0.3s ease-out;
  -o-transition: all 0.3s ease-out;
  transition: all 0.3s ease-out;
}

#box-dynamic.minimize small {
  font-size: 10px;
  margin-right: 5px;
  float: right;
}

#box-dynamic img {
  float: left;
  width: 0;
  height: 0;
  visibility: hidden;
  -ms-transition: all 0.3s ease-out;
  -moz-transition: all 0.3s ease-out;
  -webkit-transition: all 0.3s ease-out;
  -o-transition: all 0.3s ease-out;
  transition: all 0.3s ease-out;
}

#box-dynamic.minimize img {
  float: left;
  width: 50px;
  height: 50px;
  visibility: visible;
}
<div class="box">
  <div id="box-dynamic" onclick=panelView()>
    <h1>This is my title</h1>
    <p>few words about my paragraph so it goes like this...</p>
    <br><br>
  </div>
</div>

在此处输入图像描述

标签: htmljquerycss

解决方案


给top :0 insted of bottom。对于水平中心给左:50%;和变换:translateX(-50%):


推荐阅读