如何设置<div>中的文本格式以使动画平滑滚动?

时间:2018-09-03 19:14:02

标签: html css html5 text

我有这个JSfiddle。这是我网站的进行中部分。我的代码片段存在的问题是,调整CSS百分比值的高度,宽度以及最重要的是顶部和左侧位置时,文本的大小无法正确调整。我不知道我的定位是否正确。我不是最擅长知道何时在特定实例上使用哪个职位。

代码:

@charset "utf-8";

/* CSS Document */

.Experience_Target {
  display: inline-block;
}

.EXP1Box {
  height: 100vh;
  overflow: hidden;
}

#Hangar {
  top: 0;
  height: 50%;
}

#Virtual {
  top: 0;
  height: 50%;
}

.Hangar {
  background: url(https://s8.postimg.cc/d56er2eut/Hangar_Phot.png);
  height: 50%;
  width: 100%;
  background-position: 75%;
  background-repeat: no-repeat;
  transition: all .5s ease;
  -moz-transition: all .5s ease;
  -ms-transition: all .5s ease;
  -webkit-transition: all .5s ease;
  -o-transition: all .5s ease;
  webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

.Hangar:hover {
  box-shadow: inset 0 0 0 150vw rgba(0, 0, 0, 0.7);
  -moz-transform: scale(1.1);
  -webkit-transform: scale(1.1);
  -o-transform: scale(1.1);
  -ms-transform: scale(1.1);
  /* IE 9 */
  transform: scale(1.1);
  -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=1.5, M12=0, M21=0, M22=1.5, SizingMethod='auto expand')";
  filter: progid:DXImageTransform.Microsoft.Matrix(M11=1.5, M12=0, M21=0, M22=1.5, SizingMethod='auto expand');
}

.NextEra {
  position: relative;
  width: 0%;
  height: 0%;
  top: 3.5%;
  left: 40%;
  z-index: 1;
  transition: .5s ease;
  -moz-transition: .5s ease;
  -ms-transition: .5s ease;
  -webkit-transition: .5s ease;
  -o-transition: .5s ease;
}

.Hangar:hover .NextEra {
  position: relative;
  width: 70%;
  height: auto;
  top: 0.0%;
  left: 26.3%;
  z-index: 1;
}

h3 {
  font-family: "Myriad Pro";
  font-size: 63px;
  color: white;
}

h4 {
  font-family: "Myriad Pro";
  font-size: 64px;
  color: white;
}

.Hangar:hover .NextText1 {
  position: relative;
  top: 60%;
  left: -18%;
  z-index: 2;
  font-style: italic;
}

.NextText1 {
  position: relative;
  top: -300%;
  left: 0%;
  z-index: 2;
}

.Hangar:hover .NextText2 {
  position: relative;
  top: -300%;
  left: 2%;
  z-index: 2;
  width: 30%
}

.NextText2 {
  position: relative;
  top: 100%;
  left: 18%;
  z-index: 2;
}
<section class="EXP1Box">
  <div class="Hangar">
    <div class="NextEra">
      <div class="NextEra">
        <img alt="NextEra" src="https://s8.postimg.cc/h1jqn4zv9/Next_Era_Pop.png" class="NextEra">
      </div>

      <div class="NextText1">
        <h4 class="NextText1">Future Ambitions</h4>
      </div>
      <div class="NextText2">
        <h3 class="NextText2">Internship Position With:</h3>
      </div>
    </div>
  </div>

  <div class="Virtual">
  </div>

</section>

我想发生的事情是,当有人没有将鼠标悬停在图片上方时,文本会变小并离开页面,但是当有人将鼠标悬停在图片上方时,它会变大并占据图像的一半左侧的NextEra徽标的动画。由于某些奇怪的原因,我暂时无法在当前位置放置任何文本。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

我认为对您来说,一种选择是使用display:nonevisibility:hidden隐藏您不想显示的文本,而不是弄乱z索引和过渡。从代码中还不清楚,是否希望文本在可见时溢出框。.我将其放置在框内。我调整了文本大小,但是如果您希望它们更大或更小,可以进行调整。我添加了颜色(只是我可以看到它们的开始位置)..再次可调整。

这是fiddle和摘要:

@charset "utf-8";
/* CSS Document */

.Experience_Target {
  display: inline-block;
}

.EXP1Box {
  height: 100vh;
  overflow: hidden;
}

#Hangar {
  top: 0;
  height: 50%;
}

#Virtual {
  top: 0;
  height: 50%;
}

.Hangar {
  background: url(https://s8.postimg.cc/d56er2eut/Hangar_Phot.png);
  height: 50%;
  width: 100%;
  background-position: 75%;
  background-repeat: no-repeat;
  transition: all .5s ease;
  -moz-transition: all .5s ease;
  -ms-transition: all .5s ease;
  -webkit-transition: all .5s ease;
  -o-transition: all .5s ease;
  webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  /*background-attachment: fixed;
Really wish I could make this work.
Fucks up because of zoom*/
}

.Hangar:hover {
  box-shadow: inset 0 0 0 150vw rgba(0, 0, 0, 0.7);
  -moz-transform: scale(1.1);
  -webkit-transform: scale(1.1);
  -o-transform: scale(1.1);
  -ms-transform: scale(1.1);
  /* IE 9 */
  transform: scale(1.1);
  -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=1.5, M12=0, M21=0, M22=1.5, SizingMethod='auto expand')";
  filter: progid:DXImageTransform.Microsoft.Matrix(M11=1.5, M12=0, M21=0, M22=1.5, SizingMethod='auto expand');
}

.NextEra {
  position: relative;
  width: 0%;
  height: 0%;
  top: 3.5%;
  left: 40%;
  z-index: 1;
  transition: .5s ease;
  -moz-transition: .5s ease;
  -ms-transition: .5s ease;
  -webkit-transition: .5s ease;
  -o-transition: .5s ease;
}

.Hangar:hover .NextEra {
  position: relative;
  width: 70%;
  height: auto;
  top: 0.0%;
  left: 26.3%;
  z-index: 1;
}

h3 {
  font-family: "Myriad Pro";
  font-size: 63px;
  color: blue;
}

h4 {
  font-family: "Myriad Pro";
  font-size: 64px;
  color: green;
}

.NextText1 {
  color: forestgreen;
  margin-left: 30px;
  margin-top: 10px;
  position: relative;
  z-index: 2;
  font-style: italic;
  visibility: visible;
}

.Hangar:hover .NextText1 {
  /*margin-left: 18%;
  z-index: 2;*/
  visibility: hidden;
}

.Hangar:hover .NextText2 {
  position: fixed;
  visibility: visible;
  top: 10%;
  left: 2%;
  z-index: 2;
  width: 30%;
  margin-left: 18%;
  font-size: 30px;
  color: red;
}

.NextText2 {
  visibility: hidden;
}
<section class="EXP1Box">
  <div class="Hangar">
    <div class="NextEra">
      <div class="NextEra">
        <img alt="NextEra" src="https://s8.postimg.cc/h1jqn4zv9/Next_Era_Pop.png" class="NextEra">
      </div>
      <div class="NextText1">
        <h4 class="NextText1">Future Ambitions</h4>
      </div>
      <div class="NextText2">
        <h3 class="NextText2">Internship Position With:</h3>
      </div>
    </div>
  </div>

  <div class="Virtual">
  </div>

</section>