skip to Main Content

I want to make the date of the post to be shown like this, but I failed 🙁

Can anyone teach me how to make it?
I also wonder if I have made it too complicated in the CSS…

The result that I want

Here is my HTML code

<div class="post-date">
 <hr class="left" />
 <p>2023/06/25</p>
 <hr class="right" />
</div>

Here is my CSS code

.post-container .blog-post .post-date hr {
    color: #212931;
    width: 30%;
    vertical-align: middle;
}

.post-date .right {
    position: absolute;
    right: 0;
    top: 0;
    margin-right: 5%;
}

.post-date p {
    font-size: 20px;
    display: inline-block;
    position: absolute;
    transform: translateY(-15px);
    color: #212931;
    margin: 0 auto;
}

2

Answers


  1. Don’t Use hr left or right Just use before , after

    .post-date {
      font-size: 30px;
      display: flex;
      align-items: center;
    }
    
    .post-date::before, .post-date::after {
      flex: 1;
      content: '';
      padding: 1px;
      background-color: grey;
      margin: 5px;
    }
    <div class="post-date">2023/06/25</div>
    Login or Signup to reply.
  2. Using your code, it’s like this:

    .post-container .blog-post .post-date hr {
      color: #212931;
      width: 30%;
      vertical-align: middle;
    }
    
    .post-date .right {
      position: absolute;
      right: 0;
      top: 0;
      margin-right: 5%;
    }
    
    .post-date p {
      font-size: 20px;
      display: inline-block;
      position: absolute;
      transform: translateY(-15px);
      color: #212931;
      margin: 0 auto;
    }
    
    
    /*new code*/
    
    p {
      font-family: "Times New Roman", Times, serif; 
      background: #ffffff;
      padding: 20px;
      line-height: 20px;
    }
    
    .post-date {
      text-align: center;
    }
    
    .left,
    .right {
      top: 25px;
      position: relative;
    }
    <div class="post-date">
      <hr class="left" />
      <p>2023/06/25</p>
      <hr class="right" />
    </div>

    But better "listen" to Syed Muhammad Ali Raza’s answer, instead of mine.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search