Ensure uniform height for inline-block divs in HTML styling

I'm currently working on a horizontal navigation that includes both icons and text for each item. The problem I'm facing is when an item has two lines of text compared to just one line. I've attempted adjusting the padding and height of the div in question, but so far, it hasn't produced the desired outcome. What steps can I take to ensure a consistent height for all navigation items regardless of text length?

For a live demo, check out this fiddle: Here

<div id="dashboard">
    <a class="actions" href="#">
        <div>
            <i class="fas fa-users"></i> <br />Employees
        </div>
    </a>
    <a class="actions" href="#">
        <div>
            <i class="fas fa-pencil-ruler"></i> <br />Check Stats
        </div>
    </a>
    <a class="actions" href="#"">
        <div>
            <i class="fas fa-table"></i> <br />Generate Census
        </div>
    </a>
    <a class="actions" href="#">
        <div>
            <i class="fas fa-paper-plane"></i> <br />Send Forms
        </div>
    </a>
    <a href="#" class="actions" data-toggle="modal" data-target="#deleteClientModal">
        <div>
            <i class="fas fa-trash-alt"></i> <br />Delete
        </div>
    </a>
</div>

.actions:first-child div {
  border-top-left-radius: 10px;
  border-bottom-left-radius: 10px;
}
.actions:last-child div {
  border-top-right-radius: 10px;
  border-bottom-right-radius: 10px;
}
.actions > div {
  display: block;
  background-color: #fafafa;
  color: #223a5c;
  border: 1px solid #d6d8db;
  padding: 15px 0;
  margin: 0 -6px 20px 0;
  width: 12.5%;
  text-align: center;
  display: inline-block;
}
.actions > div:hover {
  background-color: #f2f2f2;
}
.actions > div i {
  width: 1em;
  font-size: 2em;
}

Answer №1

One way to implement a flexbox solution is by using the following CSS:

#dashboard {
  display: flex;
}

div:first-child>.actions>div {
  border-top-left-radius: 10px;
  border-bottom-left-radius: 10px;
}

div:last-child>.actions>div {
  border-top-right-radius: 10px;
  border-bottom-right-radius: 10px;
}

.actions>div {
  background-color: #fafafa;
  color: #223a5c;
  border: 1px solid #d6d8db;
  padding: 15px 15px;
  text-align: center;
}

.actions>div:hover {
  background-color: #f2f2f2;
}

.actions>div i {
  width: 1em;
  font-size: 2em;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">

<div id="dashboard">
  <div>
    <a class="actions" href="#">
      <div>
        <i class="fas fa-users"></i> <br />Employees
      </div>
    </a>
  </div>
  <div>
    <a class="actions" href="#">
      <div>
        <i class="fas fa-pencil-ruler"></i> <br />Check Stats
      </div>
    </a>
  </div>
  <div>
    <a class="actions" href="#">
      <div>
        <i class="fas fa-table"></i> <br />Generate Census
      </div>
    </a>
  </div>
  <div>

    <a class="actions" href="#">
      <div>
        <i class="fas fa-paper-plane"></i> <br />Send Forms
      </div>
    </a>
  </div>
  <div>

    <a href="#" class="actions" data-toggle="modal" data-target="#deleteClientModal">
      <div>
        <i class="fas fa-trash-alt"></i> <br />Delete
      </div>
    </a>
  </div>

</div>

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

Adding or removing a class on hover in Tailwind: The simple way!

Is there a way to change the class upon hovering an object using tailwind classes? <span className='group inline-block relative'> Hello <span className='hidden absolute -top-16 left-16 group-hover:inline-block'>&#45; ...

Tips for customizing styles when an element is being dragged over in Material-UI?

If I want to alter the backgroundColor when hovering, I can utilize sx={{"&:hover":{backgroundColor:"yellow"}} Is there a way to adjust the backgroundColor on dragover? It appears that sx={{"&:dragOver":{backgroundCol ...

Can CSS be used to communicate to JavaScript which media queries are currently in effect?

Is there a way for Javascript to detect when a specific CSS media query is active without repeating the conditions of the media query in Javascript? Perhaps something similar to an HTML data attribute, but for CSS. For example: CSS @media (min-width: 94 ...

Tips for Automatically Keeping Bootstrap Dropdown Open When Selecting an Option

My bootstrap dropdown features a select box with specific options that I want to keep visible. However, when I click on it, the drop-down closes unexpectedly. How can I prevent the drop-down from closing when clicking on the select box? Check out this boo ...

Tips for customizing the default CSS styles of a table

This question has been raised on Stack Overflow before. However, the solutions provided do not seem to work for me. I am currently working on an Angular project and I am trying to align the 'Mode of comparison' and the corresponding 'Dropdow ...

Overlaying images on top of text

Is there a way to overlay an image on text, like a pattern image? Similar to applying color with a hex value in CSS: color: #ffffff; Any ideas on how this can be achieved? I want to have a pattern over text. https://i.sstatic.net/JaNZU.jpg Appreciate ...

Notification for Pinned Tabs Update

Is there a method to emphasize pinned tabs in web browsers when receiving new notifications similar to Gmail, Facebook, or Twitter? The attached image should provide clarity on my query. I am seeking a solution that works across all browsers. ...

In a Twitter Bootstrap environment, the button cursor transforms into an I-beam when activated

After utilizing twitter bootstrap to construct a small blog site and integrating a third-party file upload application into the project, I encountered an issue. The CSS files in the file uploader style the "upload button," but when my cursor hovers over it ...

How can we display the Recent Updates from our LinkedIn profile on our website using iframe or javascript?

Currently, I am in the process of developing a .NET web application for our company's website. We already maintain an active LinkedIn profile where we regularly post updates. https://i.stack.imgur.com/T2ziX.png My main query at this point is whether ...

How come the radio button cannot stay highlighted after being selected in a form group?

When creating a radio selection from a form group, I used the ngFor directive to populate the option list. Everything seemed to be working fine. However, in certain conditions, I needed to individually set each option as an input. Unfortunately, when I che ...

How to load an iframe only upon clicking on a link

I am struggling to make the iframe popup appear only when a specific class link is clicked. Here is my HTML and JS code: Unfortunately, nothing happens when I click the link with the class 'aclass'. I have updated my JavaScript, but the issue ...

How can jQuery select an element by its id attribute by referencing the href attribute of a different element?

Whenever the user interacts with a div.nav element, jQuery switches its class to active. Presently, it applies display: block to all three of the div.content elements. I aim for jQuery to only apply the display: block property to the div.content elements t ...

Troubleshooting issues with applying styles in Vue framework when configured with webpack

I'm facing an issue with setting up the Vue framework using webpack. Specifically, I'm having trouble with styles not being applied when included in the <style> tag within single file components. Despite following several tutorials on this ...

Decrease the gap between rows in CSS Grid

I'm struggling to minimize the space between the rows. I've attempted adjusting margins and paddings to 0, but nothing seems to be working effectively. Displaying desktop view on the left and mobile view on the right side. https://i.sstatic.net ...

Utilizing z-index for effective layering in scenarios involving a side navigation bar and modal pop-up

Mastering z-index proves to be quite challenging for me at the moment. I am working on a webpage (#s01) that includes a fixed side navigation bar (#s03). The issue arises when I want a modal (#s02) to cover the entire layer, including the side navigation. ...

Collapsible menu causing inline form elements to shift downwards

I am struggling with my inline Bootstrap 5 form that includes a collapsible menu for advanced search. The issue I'm facing is that when I open the advanced search menu, it pushes down box 1 and 2 instead of neatly expanding below. I tried setting the ...

Two flex boxes displayed next to each other on the screen

Within the .maroon section, there are two .whitewrap sections. I am puzzled as to why they are not wrapping onto another line and instead displaying side by side. The form should be positioned below the text and graphic with some maroon showing in between. ...

Analyzing text with improperly defined attributes

As I attempted to analyze an HTML document as XML by adding the XML start at the beginning, I encountered an issue with attributes within tags. <tr> <td class="yfnc_tabledata1" nowrap align="right">Jun 4, 2013</td> <td class="yfnc_tab ...

Shade your background picture to add some vibrancy

I'm looking for a way to colorize an image of a post-it note (similar to the one found here) based on an rgb value. The challenge I'm facing is that the edges of the image need to remain transparent, as it will be displayed against various backg ...

Toggler for the Bootstrap navbar

Recently, I've been experimenting with Bootstrap for the first time and trying to understand its functionalities. While I've managed to make some progress with navbars, I've encountered a roadblock when it comes to the navbar-toggler. <n ...