如何水平定位?

问题描述 投票:0回答:3

我想在我的光滑滑块旁边显示一个预告片和信息文本。然而,无论我尝试什么,它们都是彼此重叠的。

我尝试过flexbox,并将它们放在行中。我也尝试了内联显示,并为每个div左右浮动。

/* Styling the Trailer Slick Slider */

.single-item-rtl {
  max-width: 1100px;
  position: relative;
  top: 0;
  left: 0;
  display: block;
  margin-left: auto;
  margin-right: auto;
  float: left;
}


/* Styling the Trailer Content */

#captain-marvel,
#endgame {
  display: inline-flex;
  flex-direction: row;
  max-width: 1000px;
}
<article id="secondThirdArticle">
  <div class="middleh3">Trailers & New Releases</div>
  </br>
  <div class="inner-grid">
    <div dir="rtl" class="single-item-rtl">
      <div id="captain-marvel">
        <div>
          <h4> Captain Marvel </h4>
          <p>The MCU’s most powerful hero is set to land on the big screen. Brie Larson stars as Carol Danvers, aka Captain Marvel, alongside Samuel L. Jackson as Nick Fury, and Jude Law as Walter Lawson. In the midst of an inter-galactic war that threatens
            to destroy the Earth, Carol Danvers must rise to a seemingly impossible challenge. Following the post-credit teaser of Avengers: Infinity War Part One, Captain Marvel is one of the most eagerly anticipated films of the year.</p>
        </div>
        <div>
          <iframe width="504" height="284" src="https://www.youtube.com/embed/Z1BCujX3pw8" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        </div>
        </br>
      </div>
      <div id="endgame">
        <div>
          <h4> Avengers: Endgame </h4>
          <p>The grave course of events set in motion by Thanos that wiped out half the universe and fractured the Avengers ranks compels the remaining Avengers to take one final stand in Marvel Studios' grand conclusion to twenty-two films, Avengers: Endgame.</p>
        </div>
        <div>
          <iframe width="504" height="284" src="https://www.youtube.com/embed/TcMBFSGVi1c" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        </div>
        </br>
      </div>
    </div>
  </div>
  </br>
  <a href="#" class="myButton">See All Trailers</a>
</article>
`

我想要一些带有标题的中心文本在预告片的一侧。他们最终在彼此之上。见网站:http://www.student.city.ac.uk/~aczc972/

html css positioning
3个回答
2
投票

在父母身上,使用

display: flex;
align-items: center;

它会将它们排成左右。只需确保其他组件是您放置这些样式的父项的直接子项!


0
投票

使用网格展览布局。基本上你设置了两列:text列和trailer列,并确保两者都占用了父div的角色。通过这样做,您将正确分离两个内容。您还可以搜索其中的更多属性,例如间距以及组织模板的更好方法。但基本上,您可以按如下方式分隔div:

HTML:

<div id="captain-marvel">
    <div id="captain-marvel-title><h4> Captain Marvel </h4>
        <p>The MCU’s most powerful hero is set to land on the big screen. Brie Larson stars as Carol Danvers, aka Captain Marvel, alongside Samuel L. Jackson as Nick Fury, and Jude Law as Walter Lawson. In the midst of an inter-galactic war that threatens to destroy the Earth, Carol Danvers must rise to a seemingly impossible challenge. Following the post-credit teaser of Avengers: Infinity War Part One, Captain Marvel is one of the most eagerly anticipated films of the year.</p>
    </div>
    <div id="captain-marvel-trailer">  
        <iframe width="504" height="284" src="https://www.youtube.com/embed/Z1BCujX3pw8" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
    </div>
</div>

CSS:

#captain-marvel{
    display:grid;
    grid-template-columns: 1fr 1fr;        
}
#captain-marvel-title{
    grid-column:1;
    background: red;
}
#captain-marvel-trailer{
    grid-column:2;
    background: blue;
}

我给div着色,这样你就可以看到两者之间的界限。

有关更多信息,请查看此link

希望能帮助到你!


0
投票
/* Styling the Trailer Content */
#captain-marvel, #endgame {
  display: inline-flex;
  flex-direction: row;
  max-width: 1000px;
  width: 100%;
}

.left {
  float: left;
  width: 50%;
}

.right {
  float: right;
  width: 50%;
}
© www.soinside.com 2019 - 2024. All rights reserved.