What is the best way to vertically center all content, including borders, within the columns?

To view the codepen for reference, please click on the following link: http://codepen.io/rezasan/pen/apvMOR

I am attempting to align all the content within the columns (Date, Title, and Button, including the separator) vertically. I have tried using display table but it did not work as expected. Seeking assistance from the experts in this community.

Here is the HTML code snippet:


    <ul class="ir_home_news">                 
        <li class="si_fixed">
            <div class="ir_home_newsDate">18 November 2016</div>
            <div class="ir_home_newsTitle">Disclosure Of Interest</div>
            <div class="ir_home_button"><a href=""><button>VIEW DETAILS</button></a></div>
        </li>
        <li class="si_fixed">
            <div class="ir_home_newsDate">18 November 2016</div>
            <div class="ir_home_newsTitle">Disclosure Of Interest</div>
            <div class="ir_home_button"><a href=""><button>VIEW DETAILS</button></a></div>
        </li>
        <li class="si_fixed">
            <div class="ir_home_newsDate">18 November 2016</div>
            <div class="ir_home_newsTitle">Disclosure Of Interest</div>
            <div class="ir_home_button"><a href=""><button>VIEW DETAILS</button></a></div>
        </li>
    </ul>

Below is the CSS styling applied:


    ul, li {
      margin: 0;
      padding: 0;
    }

    li {
      list-style-type: none;
    }
    
    .ir_home_news li {
      border-top: 1px solid #ebebeb;
      padding: 10px;
    }

    .ir_home_news li:nth-child(even){
      background-color: #f8f8f8;
    }

    .ir_home_news li::after {
        content: "";
        clear: both;
        display: table;
    }

    .ir_home_news li div {
      display: table-cell;
      vertical-align: middle;
      padding: 0px 15px;
      border-right: 1px solid red;
    }

    .ir_home_news li div:last-child{
      border-right: none;
    }

    .ir_home_newsDate {
      float: left;
      width: 18%;
      margin-bottom: 10px;
      font-size: 18px;
      color:#003087;
    }

    .ir_home_newsTitle {
      float: left;
      width: 65%;
      font-size: 17px;
      color:#003087;
    }

    .ir_home_button {
      float: left;
      width: 10%;
    }
    .ir_home_button button {

      background-color: #003087;
      color: #fff;
      padding: 15px 25px;
      border-radius: 0;
      font-size: 13px;
    } 

Hope these snippets help in understanding the structure of the code!

Answer №1

Avoid using floar: left within your li element as it can cause issues with the vertical-align.

ul,
    li {
        margin: 0;
        padding: 0
    }
    
    li {
        list-style-type: none;
    }
    
    .ir_home_news li {
        border-top: 1px solid #ebebeb;
        padding: 10px;
    }
    
    .ir_home_news li:nth-child(even) {
        background-color: #f8f8f8;
    }
    
    .ir_home_news li::after {
        content: "";
        clear: both;
        display: table;
    }
    
    .ir_home_news li div {
        display: table-cell;
        vertical-align: middle;
        padding: 0px 15px;
        border-right: 1px solid red;
    }
    
    .ir_home_news li div:last-child {
        border-right: none;
    }
    
    .ir_home_newsDate {
        width: 18%;
        margin-bottom: 10px;
        font-size: 18px;
        color: #003087;
    }
    
    .ir_home_newsTitle {
        width: 65%;
        font-size: 17px;
        color: #003087;
    }
    
    .ir_home_button {
        width: 10%;
    }
    
    .ir_home_button button {
        background-color: #003087;
        color: #fff;
        padding: 15px 25px;
        border-radius: 0;
        font-size: 13px;
    }
<ul class="ir_home_news">
        <li class="si_fixed">
            <div class="ir_home_newsDate">18 November 2016</div>
            <div class="ir_home_newsTitle">Disclosure Of Interest</div>
            <div class="ir_home_button">
                <a href="">
                    <button>VIEW DETAILS</button>
                </a>
            </div>
        </li>
        <li class="si_fixed">
            <div class="ir_home_newsDate">18 November 2016</div>
            <div class="ir_home_newsTitle">Disclosure Of Interest</div>
            <div class="ir_home_button">
                <a href="">
                    <button>VIEW DETAILS</button>
                </a>
            </div>
        </li>
        <li class="si_fixed">
            <div class="ir_home_newsDate">18 November 2016</div>
            <div class="ir_home_newsTitle">Disclosure Of Interest</div>
            <div class="ir_home_button">
                <a href="">
                    <button>VIEW DETAILS</button>
                </a>
            </div>
        </li>
    </ul>

I have revised the code to remove all instances of float: left within your li elements.

.ir_home_newsDate {
    width: 18%;
    margin-bottom: 10px;
    font-size: 18px;
    color: #003087;
}

.ir_home_newsTitle {
    width: 65%;
    font-size: 17px;
    color: #003087;
}

.ir_home_button {
    width: 10%;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Examine the spans and delete the first-child node

Basically, this functionality allows the user to cycle through hidden information by clicking on it. Here is how you can structure your HTML: <div id="facts"> <span>click to cycle</span> <span>fact 1</span> <s ...

Guide on utilizing getelementsbytagname for retrieving LI values

As I attempt to locate a specific product on amazon.com, my goal is to extract the ASIN for each item. This particular code snippet runs through various search options and retrieves the price of each product from Amazon one by one. However, in addition to ...

Increasing the size of a card beyond the container using the CSS PRE tag

I am facing an issue with a card on my webpage. It contains a pre tag inside it, which is causing the size of the card to extend beyond its container, resulting in a horizontal scroll bar appearing. How can I make the content within the pre tag scroll hori ...

Is there a way to trigger two distinct CSS transitions simultaneously with a single click?

Below is a script that rotates two images in opposite directions when clicked. One image spins clockwise while the other spins counter-clockwise. The challenge is that each image requires an individual click to rotate. My goal is to make both images rotate ...

Preventing duplicate submissions in Ajax by serializing form data

I'm having trouble preventing double submissions on my form when I rapidly press the button that triggers a click event. I attempted to disable the button after a successful submission, but it still submits twice. Here is my code: <script> $(do ...

Tips for showcasing array values on an HTML webpage

Having trouble displaying the "latitude" and "longitude" in html. I attempted to use a forEach loop, but it was not successful this.otherService.getList().subscribe( (response: any) => { this.atm = response; HTML <div class="item" * ...

The background image constantly shifts while scrolling on a mobile device

Just sharing my first post here. There's been something bothering me on my personal website for quite some time. Whenever I visit the site on my Android phone and start scrolling through the page, the background image seems to 'adjust' itse ...

Tips for accessing the 'index' variable in *ngFor directive and making modifications (restriction on deleting only one item at a time from a list)

Here is the code snippet I'm working with: HTML: <ion-item-sliding *ngFor="let object of objectList; let idx = index"> <ion-item> <ion-input type="text" text-left [(ngModel)]="objectList[idx].name" placeholder="Nam ...

The particular division is failing to display in its designated location

This is quite an interesting predicament I am facing! Currently, I am in the process of coding a website and incorporating the three.js flocking birds animation on a specific div labeled 'canvas-div'. My intention is to have this animation displa ...

Ways to incorporate a reverse transition effect

I am encountering an issue with a sliding effect on a div. When it has a class hddn, the overlay will have right: -100% from the viewport. However, when the hddn class is removed, it should return to the viewport with right: 0. How can I animate this movem ...

External CSS file unable to load background image as referenced

I am facing an issue with this code in my external CSS file as it doesn't seem to work at all. Strangely, when I move it internally, everything functions perfectly. Any thoughts on what could be causing this discrepancy? html { background-image:url(i ...

Enhancing User Experience with Interactive React Hover Effects

Hello, I have tried various combinations but still cannot get the desired background color to display when hovering over my <p> element. I am looking for a CSS-only solution and not interested in using JavaScript hover events. I would appreciate it ...

Strange glitch in the rendering of rectangles on HTML5 canvas?

While experimenting with pre-rendering sprites using HTML5 canvas, I encountered some strange behavior that appears to be a rendering bug. The issue can be seen in the following minimal example: var CT = document.getElementById("myCanvas").getContext("2 ...

Choose an XPath formula that will target every single element, text node, and comment node in the original sequence

How can we write an XPath expression that selects all elements, text nodes, and comment nodes in the order they appear in the document? The code below selects all elements but not text nodes and comment nodes: let result = document.evaluate('//*&apo ...

Spacing issues in Bootstrap footer on mobile devices when resizing left and right

Recently, I added a new footer to my Twitter Bootstrap website and noticed that when I resize the window, gaps appear on the left and right sides. I understand that this issue is related to the following CSS code... @media (max-width: 767px) { body { ...

Get the HTML file converted to a DOCX format that is compatible with Mac Pages

I am currently working on a Next.js application using TypeScript, and I want to give users the ability to download a page as a DOCX file. Initially, I was excited to discover that this could be easily accomplished by following this method. However, after ...

Can someone provide guidance on how to align the navigation bar to the right in Bootstrap?

Having trouble setting up the navigation menu on the right hand side with Bootstrap, like most modern websites. <nav class="navbar navbar-expand-lg navbar-light bg-light"> <button class="navbar-toggler" type="button" data-togg ...

Empty Github page displayed on individual professional website

Hello everyone, I am new to development. I recently put together my own personal portfolio and stored it in this GitHub repository -> https://github.com/LuisssM/Portfolio. However, when I try to launch the website at , it shows the content of the read-m ...

What is the best way to erase information displayed when hovering over an element using mouseout?

Whenever the user hovers over an image, an information box appears regarding that specific image. The information inside the box changes as I move over another image, but when not hovering over any images, the information box remains visible. Unfortunately ...

I am experiencing issues with the functionality of the jQuery function

I am currently diving into the world of jquery. I put together a script, but unfortunately it's not functioning as expected. 1 Here is a snippet of my HTML code <ul id="recur" class="elasticstack"> <li id=<?=$item['id']?> ...