我正在尝试制作一条响应 div 高度的垂直线

发布于 2025-01-10 08:58:32 字数 1982 浏览 2 评论 0原文

我的垂直线位于我想要的位置,但我似乎不知道如何让它与我的 p 元素和放映时间的 div 高度相同。理想情况下,当用户调整页面大小时,线条将随元素一起调整大小。我是编码新手,我确信这是一个简单的解决方案,但我已经用尽了我一直在尝试解决这个问题的资源。

.wrapper {
    max-width: 2400px;
    margin: 0 auto;
}

h3{
    font-family: fino;
    color: #BF2035;
    text-align: center;
    font-size: 6em;
    padding: 25px 25px 40px 25px;
}

.showtimes{
    width: 50%;
    
}

p{
    font-family: bookmania, serif;
    font-weight: 400;
    font-size: 3em;
    font-style: normal;
    text-align: center;
    width: 50%;
    padding: 40px;
}

.dates{
    font-family: bookmania, serif;
    font-weight: 400;
    font-style: normal;
    font-size: 3em;
    display: list-item;
    text-align: center;
    list-style: none;
    padding-left: 0%;
    padding-right: 65px;
}

.vl {
    border-left: 6px solid black;
    height: 50%;
    position: absolute;
    left: 55%;
    margin-left: -3px;
  }
 </div>  
        <section class="wrapper row">
            <p>Pages of a Love Manifesto is a devised theatre piece that, at its core, explores love: our definitions of love, how we relate to love, how we can come to know love and be better practitioners of love, etc. Guided by bell hooks narrative, All About Love, this show is a radical deep dive into love (and heartbreak) inspired by personal tales and testimonies.
            </p>

        <div class="showtimes"> 
            <h3>Showtimes</h3>
            <ul>
                <li class="dates">Friday, April 29th, 8:00pm</li>
                <li class="dates">Saturday, April 30th, 8:00pm</li>
                <li class="dates">Sunday, May 1st, 8:00pm</li>
            </ul>
        </div>

        <div class="vl"></div>

        </section>
    </div>

I have my vertical line in the spot that I want it in, but I can't seem to figure out how to get it to be the same height as my divs for my p element and my showtimes. Ideally, the line would resize with the elements when the user resizes the page. I'm new to coding, and I'm sure this is an easy fix, but I've exhausted the resources that I've been using to try and figure it out.

.wrapper {
    max-width: 2400px;
    margin: 0 auto;
}

h3{
    font-family: fino;
    color: #BF2035;
    text-align: center;
    font-size: 6em;
    padding: 25px 25px 40px 25px;
}

.showtimes{
    width: 50%;
    
}

p{
    font-family: bookmania, serif;
    font-weight: 400;
    font-size: 3em;
    font-style: normal;
    text-align: center;
    width: 50%;
    padding: 40px;
}

.dates{
    font-family: bookmania, serif;
    font-weight: 400;
    font-style: normal;
    font-size: 3em;
    display: list-item;
    text-align: center;
    list-style: none;
    padding-left: 0%;
    padding-right: 65px;
}

.vl {
    border-left: 6px solid black;
    height: 50%;
    position: absolute;
    left: 55%;
    margin-left: -3px;
  }
 </div>  
        <section class="wrapper row">
            <p>Pages of a Love Manifesto is a devised theatre piece that, at its core, explores love: our definitions of love, how we relate to love, how we can come to know love and be better practitioners of love, etc. Guided by bell hooks narrative, All About Love, this show is a radical deep dive into love (and heartbreak) inspired by personal tales and testimonies.
            </p>

        <div class="showtimes"> 
            <h3>Showtimes</h3>
            <ul>
                <li class="dates">Friday, April 29th, 8:00pm</li>
                <li class="dates">Saturday, April 30th, 8:00pm</li>
                <li class="dates">Sunday, May 1st, 8:00pm</li>
            </ul>
        </div>

        <div class="vl"></div>

        </section>
    </div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只有影子陪我不离不弃 2025-01-17 08:58:32

使用 display: flex 使两个 div 正确对齐。 flex-direction: row 将进行处理,以便两个元素并排。

.wrapper {
    margin: 0 auto;
    display: flex;
    flex-direction: row;
}

h3{
    font-family: fino;
    color: #BF2035;
    text-align: center;
    font-size: 6em;
    padding: 25px 25px 40px 25px;
}

.showtimes{
    width: 50%;
    border-left: 6px solid black;
    
}

p{
    font-family: bookmania, serif;
    font-weight: 400;
    font-size: 3em;
    font-style: normal;
    text-align: center;
    width: 50%;
    padding: 40px;
}

.dates{
    font-family: bookmania, serif;
    font-weight: 400;
    font-style: normal;
    font-size: 3em;
    display: list-item;
    text-align: center;
    list-style: none;
    padding-left: 0%;
    padding-right: 65px;
}
</div>  
        <section class="wrapper row">
            <p>Pages of a Love Manifesto is a devised theatre piece that, at its core, explores love: our definitions of love, how we relate to love, how we can come to know love and be better practitioners of love, etc. Guided by bell hooks narrative, All About Love, this show is a radical deep dive into love (and heartbreak) inspired by personal tales and testimonies.
            </p>

        <div class="showtimes"> 
            <h3>Showtimes</h3>
            <ul>
                <li class="dates">Friday, April 29th, 8:00pm</li>
                <li class="dates">Saturday, April 30th, 8:00pm</li>
                <li class="dates">Sunday, May 1st, 8:00pm</li>
            </ul>
        </div>

        <div class="vl"></div>

        </section>
    </div>

Use display: flex so that both the divs are aligned properly. flex-direction: row will handle so that both the elements are side by side.

.wrapper {
    margin: 0 auto;
    display: flex;
    flex-direction: row;
}

h3{
    font-family: fino;
    color: #BF2035;
    text-align: center;
    font-size: 6em;
    padding: 25px 25px 40px 25px;
}

.showtimes{
    width: 50%;
    border-left: 6px solid black;
    
}

p{
    font-family: bookmania, serif;
    font-weight: 400;
    font-size: 3em;
    font-style: normal;
    text-align: center;
    width: 50%;
    padding: 40px;
}

.dates{
    font-family: bookmania, serif;
    font-weight: 400;
    font-style: normal;
    font-size: 3em;
    display: list-item;
    text-align: center;
    list-style: none;
    padding-left: 0%;
    padding-right: 65px;
}
</div>  
        <section class="wrapper row">
            <p>Pages of a Love Manifesto is a devised theatre piece that, at its core, explores love: our definitions of love, how we relate to love, how we can come to know love and be better practitioners of love, etc. Guided by bell hooks narrative, All About Love, this show is a radical deep dive into love (and heartbreak) inspired by personal tales and testimonies.
            </p>

        <div class="showtimes"> 
            <h3>Showtimes</h3>
            <ul>
                <li class="dates">Friday, April 29th, 8:00pm</li>
                <li class="dates">Saturday, April 30th, 8:00pm</li>
                <li class="dates">Sunday, May 1st, 8:00pm</li>
            </ul>
        </div>

        <div class="vl"></div>

        </section>
    </div>

冷了相思 2025-01-17 08:58:32

您可以使用 border-right 来达到相同的结果。如果您希望在 p 和类 showtimeul 上分别添加垂直线,您可以在每个元素上添加以下内容:

border-right: 5px solid black;

请参阅下面的代码片段供您参考:

.wrapper {
  max-width: 2400px;
  margin: 0 auto;
}

h3 {
  font-family: fino;
  color: #BF2035;
  text-align: center;
  font-size: 6em;
  padding: 25px 25px 40px 25px;
}

.showtimes {
  width: 50%;
}

.showtimes>ul {
  border-right: 5px solid black;
}

p {
  font-family: bookmania, serif;
  font-weight: 400;
  font-size: 3em;
  font-style: normal;
  text-align: center;
  width: 50%;
  padding: 40px;
  border-right: 5px solid black;
}

.dates {
  font-family: bookmania, serif;
  font-weight: 400;
  font-style: normal;
  font-size: 3em;
  display: list-item;
  text-align: center;
  list-style: none;
  padding-left: 0%;
  padding-right: 65px;
}

.vl {
  border-left: 6px solid black;
  height: 50%;
  position: absolute;
  left: 55%;
  margin-left: -3px;
}
</div>
<section class="wrapper row">
  <p>Pages of a Love Manifesto is a devised theatre piece that, at its core, explores love: our definitions of love, how we relate to love, how we can come to know love and be better practitioners of love, etc. Guided by bell hooks narrative, All About Love,
    this show is a radical deep dive into love (and heartbreak) inspired by personal tales and testimonies.
  </p>

  <div class="showtimes">
    <h3>Showtimes</h3>
    <ul>
      <li class="dates">Friday, April 29th, 8:00pm</li>
      <li class="dates">Saturday, April 30th, 8:00pm</li>
      <li class="dates">Sunday, May 1st, 8:00pm</li>
    </ul>
  </div>

</section>
</div>

You can use border-right to achieve the same result. If you want the vertical line separately on your p and class showtime's ul you can add the following on each element:

border-right: 5px solid black;

See the snippet below for your reference:

.wrapper {
  max-width: 2400px;
  margin: 0 auto;
}

h3 {
  font-family: fino;
  color: #BF2035;
  text-align: center;
  font-size: 6em;
  padding: 25px 25px 40px 25px;
}

.showtimes {
  width: 50%;
}

.showtimes>ul {
  border-right: 5px solid black;
}

p {
  font-family: bookmania, serif;
  font-weight: 400;
  font-size: 3em;
  font-style: normal;
  text-align: center;
  width: 50%;
  padding: 40px;
  border-right: 5px solid black;
}

.dates {
  font-family: bookmania, serif;
  font-weight: 400;
  font-style: normal;
  font-size: 3em;
  display: list-item;
  text-align: center;
  list-style: none;
  padding-left: 0%;
  padding-right: 65px;
}

.vl {
  border-left: 6px solid black;
  height: 50%;
  position: absolute;
  left: 55%;
  margin-left: -3px;
}
</div>
<section class="wrapper row">
  <p>Pages of a Love Manifesto is a devised theatre piece that, at its core, explores love: our definitions of love, how we relate to love, how we can come to know love and be better practitioners of love, etc. Guided by bell hooks narrative, All About Love,
    this show is a radical deep dive into love (and heartbreak) inspired by personal tales and testimonies.
  </p>

  <div class="showtimes">
    <h3>Showtimes</h3>
    <ul>
      <li class="dates">Friday, April 29th, 8:00pm</li>
      <li class="dates">Saturday, April 30th, 8:00pm</li>
      <li class="dates">Sunday, May 1st, 8:00pm</li>
    </ul>
  </div>

</section>
</div>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文