Trouble with vertical alignment and height in a floating division

After scouring through numerous discussions on Stackoverflow regarding vertical alignment and 100% height issues, we have not found a solution. Some of the topics we explored include:

Vertical-align middle not working in CSS

How to fill height of a floating nested div

CSS div 100% height issue

Despite these and similar resources, none have provided us with a solution.


Access our JSfiddle code here: JSfiddle Code

HTML code:

<div id="header">
<div id="logo_container">
    <a href="main-catalog"><img src="img/logo-finder.png" alt="Logo Example"></a>
</div><!--Logo container-->
    <a href="main-catalog" id="aplication_lookup_button" class="button_link">Search by application</a>
    <a href="search-product-catalog" id="search_product_button" class="button_link">Search by part number</a>
</div><!-- Main header where logo and buttons are displayed -->

CSS code:

#header
{
  width:100%;
  background: #000;
  float:left;
}

#logo_container
{
  width: 14.0056%;
  text-align: center;
  float: left;
}

#logo_container img
{
  max-width: 50%;
  height: auto;
}

.button_link{
  text-align: center;  
  color: white;
  text-decoration:none;
  text-transform: uppercase;
  width: 25%;
  height: 4.1em;
  float: left;
}

#aplication_lookup_button
{
  background: #424242;
  border-bottom: 4px solid #2eaeb8
}

#search_product_button:hover
{
  color: #2eaeb8;
  font-weight: bold;
}

Shown below is a snapshot of the current layout:


We aim to vertically align the text within the anchor tags and prefer to use height:100% instead of the current usage of em.

Answer №1

One way to achieve this is by using a pseudo-element along with the inline-block property:

.button_link:before {
    content:'';
    display:inline-block;
    height:100%;
    vertical-align:middle;
}

Check out this example on jsFiddle

This method can come in handy when you need to wrap text within an inline-block element and show multiple lines Another example here

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

Achieving inline display of material-ui components through styling props override

I am struggling to position a checkbox to the right of the "answer input one" field. I've tried adjusting the display property without success. You can see the current layout here. Below is the code for rendering the answer input: <div> ...

Delivering Background Videos with Node.JS

Apologies if my question seems off base or confusing, as I am not very knowledgeable in the world of nodejs. I have been comfortable using just plain PHP and Apache for a while until I discovered ZURB Foundation's stack with Handlebars and SASS, along ...

The applied style of NextUI Components may be inconsistent, appearing to not apply in certain instances even though it does work

I've hit a roadblock trying to solve this issue. While using NextUI, I've managed to successfully apply styles to some components like the navbar, indicating that I have correctly installed NextUI and configured Tailwind. However, I'm facing ...

Guide on displaying the <html> tag within text using AngularJS

I need to display some data in HTML, which looks like this: <p>abcd efg hijk....(<a href=\"http:\/\/www.facebook.com\/stock\/NBR\">NYSE:NBR<\/a>),, however, there are some HTML tags within ...

"Employing the ScrollSpy feature in Bootstrap allows you to effortlessly monitor

Recently, I came across a document containing Bootstrap 4 code like the following: <div className="container"> <nav class="navbar navbar-expand-lg navbar-light"> <a class="navbar-brand active" aria-current="true" href="/"> ...

Styling Text with Shadow Effects in Mobile Web Browsers

I'm attempting to apply a text-stroke effect using text-shadow like this: .text-stroke { text-shadow: -1px -1px 0 white, 1px -1px 0 white, -1px 1px 0 white, 1px 1px 0 white; } Unfortunately, it's not rendering correctly on mobile versions of Fi ...

Steps for designing a stationary footer in HTML and CSS

I have implemented a static footer on my website: HTML <div class="card fixedFooter"> <div class="card-body space-around"> <button type="button" class="buttonFooter" routerLink="/myRouter" > <i class ...

Detecting collisions using CSS animation

I'm currently working on a unique "game" project. Check out the code snippet here: jsfiddle function update() { coyote.applyForce(gravity); coyote.edges(); coyote.update(); cactus.update(); if (coyote.intersects(cactus)){ alert("colisio ...

Problem with styling a CSS table

I am having an issue with the table style. My goal is to set the table radius to 8px, but my code doesn't seem to be working. Can someone assist me with this? Thank you! //ps I also require border-collapse in my code. Here is the link to my jsfidd ...

What is the best way to ensure that every item on a list can be

Is there a way to make both the left and right sides of a list item clickable? Currently, only the right side is clickable in my case. Any suggestions? This is my HTML: <body> <aside id = "aside"> <div id="column"> ...

Which domain do I need to use: Google or my own, in order to bypass the Access Denied issue in JQuery

I'm currently experiencing a puzzling issue with my website while using Internet Explorer. Despite loading fine in other browsers, I keep encountering a permission denied error within my JQuery code. What's even more perplexing is that this error ...

Accessing PHP parameters in JSP files can be accomplished by utilizing specific

The PHP code snippet below checks for a username and password match before redirecting to a JSP page. if($userName==$dbUserName&&md5($passWord)==$dbPassWord){ echo "<input name='username' type='hidden' value='$userN ...

Steps to inserting a div element in the middle of two distinct background designs

I am looking to insert a div between two contrasting backgrounds. Here is an example of what it should look like: https://i.sstatic.net/5XUao.png As shown in the image, the div is positioned between a white and blue background. Can you help me achieve t ...

Is there a reason we are able to simultaneously assign the disabled and selected attributes to <option> elements?

What is the rationale behind permitting the simultaneous setting of disabled and selected attributes on <option> elements, knowing that their values will not be submitted to a server? I was surprised that I did not receive an error in VS Code when I ...

Can someone help clear up this confusion with CSS?

Why is image 6.png selected, when all the images are direct descendants of the div shape? Thank you for your assistance, it's greatly appreciated. As far as I know, it should select all the divs because they are all direct descendants of the div #shap ...

a guide on combining values for identical dates in a JSON file

I'm currently working on an Android app that involves displaying graph values, and I could use some help. The server is returning a JSON object in the following format: [{ "date": "01-03-2018", "value": "12", }, { "id": "01-03-201 ...

The navigation bar triggers the opening of all icon menus in their designated positions at the same time

This code snippet represents the navigation bar for an admin user, featuring 3 icons: navigation menu, user menu, and manage button icons. The problem arises when clicking on any of these icons, as all dropdown items from each icon are displayed in their ...

Incorporating .json files into an HTML template with the help of an HTML form designed for selecting a particular

I am faced with a collection of various .json files that I wish to specify by name on an HTML page (local) form, enabling me to load this data onto a table. This is how my HTML form appears: <form> File: <input type="text" Id="file_name"&g ...

Looking to capture a specific div in a React JS component? I initially tried using the "use-screenshot-hook" package, but unfortunately, it captured the entire page instead

const reference = useRef(null); const { capturedImage, takeScreenshot } = useScreenshot(); const imageStyle = { height: imgHeight, width: imgWidth }; const fetchImage = () => takeScreenshot({reference}); const saveImage = () => ...

Validating phone numbers with regular expressions in Java

I recently started learning Java and Regex, and I'm currently facing a challenge with phone number validations. The task at hand is to create simple phone number validations. I already have an input field in my HTML code that has the attribute type=" ...