简体   繁体   English

CSS padding top div修改下面的div

[英]CSS padding top div modify the below div

I've been working on an Angular plugin that uses a template. 我一直在研究使用模板的Angular插件。 My goal is to add more padding-top to the section "loader-wrap", but when I do this, the second div called "message-wrap" is modified and moved as well. 我的目标是在“ loader-wrap”部分添加更多的padding-top ,但是当我这样做时,第二个div称为“ message-wrap”也将被修改和移动。 I need add padding-top: 100px to 'loader-wrap' without moving down 'message-wrap' along with it. 我需要在'loader-wrap'中添加padding-top: 100px而不将'message-wrap'一起移动。 How do I fix this? 我该如何解决?

Basic Structure HTML 基本结构HTML

<div id="page-wrap">
  <section id="loader-wrap"></section>
  <section id="message-wrap"></section>
</div>

CSS 的CSS

gp-splash-loader #page-wrap {
  z-index: 999;
  position: fixed;
  background: #FFFFFF;
  width: 100%;
  height: 80%;
  top: 10%;
  margin: 0 auto;
  -webkit-transition: opacity .5s;
  -moz-transition: opacity .5s;
  transition: opacity .5s;
  -webkit-backface-visibility: hidden;
}

@media ( max-height: 735px) {
  gp-splash-loader #page-wrap.opened{  
    height: 100%;
    top: 0;
  };
}

gp-splash-loader #page-wrap.closed {
  opacity: 0;
}

gp-splash-loader #page-wrap.opened {
  opacity: 1;
  -webkit-transition: opacity 0.5s;
  -moz-transition: opacity 0.5s;
  transition: opacity 0.5s;
}

gp-splash-loader #loader-wrap {
  width: 30%;
  height: 70%;
  min-width: 300px;
  max-width: 600px;
  margin: 10px auto;
  padding-top: 50px; 
}
gp-splash-loader #message-wrap {
  min-width: 1px;
  margin: 0 auto;
  height: 30%;
  min-height: 30%;
}

  gp-splash-loader #header-wrap {
    display: inline-block;
  }

check in codepen: http://codepen.io/gpincheiraa/pen/obdXEx 签入Codepen: http ://codepen.io/gpincheiraa/pen/obdXEx

Here's the deal. 这是交易。 You can't move that loader down with padding, otherwise it will affect the message. 您不能使用填充向下移动该加载程序,否则它将影响消息。 you need a different solution. 您需要其他解决方案。 try the below html/css. 尝试下面的html / css。

Basically I set it up so the loader and the message are in a div that will be centered. 基本上,我将其设置为使加载程序和消息位于将居中的div中。 then inside of that centered div, you can do whatever you want. 然后在该居中的div内,您可以执行任何操作。 But the loader and message will be in the middle 但是加载器和消息将在中间

if you want only the loader to be centered, then you can take the message out of the 'loader-message-box' div, and apply different styles to it. 如果只希望使加载程序居中,则可以从“ loader-message-box” div中取出消息,并对其应用不同的样式。 I'll work up a another fiddle for that solution 我将为该解决方案另辟f径

https://jsfiddle.net/ahmadabdul3/huf5zjkv/ - both message and loader are centered https://jsfiddle.net/ahmadabdul3/huf5zjkv/-消息和加载器均居中

https://jsfiddle.net/ahmadabdul3/huf5zjkv/1/ - this one will keep the message on the bottom https://jsfiddle.net/ahmadabdul3/huf5zjkv/1/-此消息会将消息保留在底部

code: 码:

html html

<div class='loader-message-box'>
  <div class='loader-message'>
    <div class='loader'>

    </div>
    <div class='message'>
      Message
    </div>
  </div>
  <div class='vertical-mid-hack'>
  </div>
</div>

css 的CSS

body, html {
  height: 100%;
  margin: 0;
}
.loader-message-box {
  width: 100%;
  height: 100%;
  text-align: center;
}
.loader-message {
  display: inline-block;
  vertical-align: middle;
  margin: 0 -2px;
}
.vertical-mid-hack {
  display: inline-block;
  vertical-align: middle;
  margin: 0 -2px;
  height: 100%;
}
.loader {
  width: 100px;
  height: 100px;
  background-color: teal;
  border-radius: 100px;
  margin: 0 auto;
  margin-bottom: 20px;
}
.message {
  background-color: white;
  border-radius: 3px;
  font-family: arial;
  padding: 20px 0;
  margin: 0 auto;
  margin-top: 20px: 
}

I removed any instance of gp-splash-loader from CSS. 我从CSS中删除了gp-splash-loader任何实例。 I don't know ng but I do know gp-splash-loader is not a valid selector. 我不知道ng,但我知道gp-splash-loader不是有效的选择器。 Other than that, the following CSS is the important part: 除此之外,以下CSS是重要的部分:

CSS: CSS:

    body {
      margin: 0;
      padding: 0;
      background: slateblue;
      text-align: center;
      top: 0;
      position: relative;
    }
    #loader-wrap {
      width: 30%;
      height: 70%;
      min-width: 300px;
      max-width: 600px;
      margin: 10px auto;
      padding-top: 100px;
      position: relative;
      z-index: 10;
    }
   #message-wrap {
      min-width: 1px;
      margin: 0 auto;
      height: 30%;
      min-height: 30%;
      position: relative;
      z-index: 11;
    }
  • Added 50px padding-top 添加了50px padding-top
  • Positioned both relative (and body as well) 定位于relative位置(也定位于身体)
  • Made sure that one never touches the other by using different z-index 确保使用不同的z-index永远不会碰到另一个

http://codepen.io/zer00ne/full/qbYMMQ/ http://codepen.io/zer00ne/full/qbYMMQ/

BTW, if you want to adjust either section up or down, add top and a negative value if you want the section to go up and vice versa. 顺便说一句,如果您想向上或向下调整部分,请增加top和负值,如果您希望该部分向上调整,反之亦然。 ex. 例如

  #message-wrap {
      min-width: 1px;
      margin: 0 auto;
      height: 30%;
      min-height: 30%;
      position: relative;
      z-index: 11;
      top: -100px;
  }

That should place #message-wrap 100px higher. 这应该将#message-wrap提高100像素。

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

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