Achieving Perfect Alignment: Centering Logo and Icons Vertically in the First Row of the Footer

I'm currently working on a footer layout and struggling to align the elements as desired. My goal is to have the "Logo" and icons in the "icon-container" vertically centered in relation to the first line of text within the "text-container," rather than both lines of text. Additionally, I need the "Imprint" text to remain horizontally centered with respect to the longer text.

Here is the relevant HTML and CSS code:

html, body {
  margin: 0;
}

footer {
  background-color: black;
  color: white;
  display: flex;
  flex-direction: column;
  padding: 10px;

  p {
    margin: 0;
  }
}

div.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.text-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  row-gap: 20px;
}

.icon-container {
  display: flex;
  column-gap: 5px;
}
<footer>
  <div class="row">
    <p>Logo</p>
    <div class="text-container">
      <p>A long long text</p>
      <p>Imprint</p>
    </div>
    <div class="icon-container">
      <p>Icon 1</p>
      <p>Icon 2</p>
      <p>Icon 3</p>
    </div>
  </div>
</footer> 

I am looking for guidance on achieving the layout where the "Logo" and icons are vertically centered with the first line of text ("A long long text") and not the second line ("Imprint"). Moreover, I want to ensure that "Imprint" remains horizontally centered with "A long long text". How can I accomplish this positioning?

Answer №1

Ralph.m's code snippet is effective for handling a small amount of text:

.row {
 align-items: flex-start;
}

html, body {
  margin: 0;
}

footer {
  background-color: black;
  color: white;
  display: flex;
  flex-direction: column;
  padding: 10px;

  p {
    margin: 0;
  }
}

div.row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.text-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  row-gap: 20px;
}

.icon-container {
  display: flex;
  column-gap: 5px;
}
<footer>
  <div class="row">
    <p>Logo</p>
    <div class="text-container">
      <p>A long long text</p>
      <p>Imprint</p>
    </div>
    <div class="icon-container">
      <p>Icon 1</p>
      <p>Icon 2</p>
      <p>Icon 3</p>
    </div>
  </div>
</footer>

However, when dealing with multiple lines of text, the layout may not behave as expected:

html, body {
  margin: 0;
}

footer {
  background-color: black;
  color: white;
  display: flex;
  flex-direction: column;
  padding: 10px;

  p {
    margin: 0;
  }
}

div.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.text-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  row-gap: 20px;
}

.icon-container {
  display: flex;
  column-gap: 5px;
}
<footer>
  <div class="row">
    <p>Logo</p>
    <div class="text-container">
      <p>A long long text. A long long text...</p>
      <p>Imprint</p>
    </div>
    <div class="icon-container">
      <p>Icon 1</p>
      <p>Icon 2</p>
      <p>Icon 3</p>
    </div>
  </div>
</footer>

To address this issue using grid layout, you will need to adjust your markup and specify column sizes explicitly:

body {
  margin: 0;
}

footer {
  background-color: black;
  color: white;
  display: grid;
  grid-template-columns: 1fr 8fr 2fr;
  grid-template-rows: fit-content fit-content;
  padding: 10px;
  p {
    margin: 0;
  }
}

.icon-container {
  display: flex;
  align-items: center;
  column-gap: 5px;
}

footer>* {
  display: grid;
  place-content: center;
}

footer>p:last-child {
  grid-area: 2 / 2 / 3 / 3;
}
<footer>
  <p>Logo</p>
  <div class="text-container">
    <p>A long long text. A long long text...</p>

  </div>
  <div class="icon-container">
    <p>Icon 1</p>
    <p>Icon 2</p>
    <p>Icon 3</p>
  </div>
  <p>Imprint</p>
</footer>

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

What is the proper way for a browser to handle a srcset attribute containing the same path twice?

When the same path or similar sized images with different pixel density descriptors are used, how does the specification address it? An interesting case study is observed when viewing an image in desktop browsers like Windows Firefox 82.0b2 and Chrome 85. ...

Troubleshooting: Unresponsive behavior of CSS table

I have been working on implementing responsive CSS for a table. I recently came across a helpful tutorial on http://css-tricks.com/responsive-data-tables/ (How to create a responsive table using CSS). While the tutorial worked fine on some sample pages, I ...

jQuery - "Error: fadeIn is not a valid function"

Encountering an odd issue here. Attempting to execute fadeIn() but receiving the error ".fadeIn is not a function". Here is my code: body { display:none; } <!DOCTYPE html> <html lang="en> <head> <!-- Required meta tags --&g ...

Finding all anchor tags in raw HTML using htmlagilitypack

My HTML document contains the following code snippet: string htmlData = "<!DOCTYPE html><html><Head></Head><body>&lt;div&gt;&lt;a target=\"_blank\" href=\"http://blender.palmbeachschools.org/GetFile ...

Discrepancies in CSS3 Column Rendering Between Firefox and Chrome

My website includes an unordered list structured like this: <ul class="subnav-links"> <li class=""> <a href="/de/t/new">New In</a> </li> <li class=""> <a href="/de/t/ ...

When you zoom in, the HTML elements tend to shift out of place

Spent the entire day yesterday attempting to make my page responsive while Zooming In, but I just can't seem to get it right. Even after adding height and weight, elements still get mixed up when zooming in on the page. I've scoured countless w ...

CSS image cropping is a technique used to adjust the size

I have successfully created a grid of images with two columns, but I'm facing an issue with a portrait image disrupting the layout. I am looking for a way to adjust or "crop" the image so it matches the height of the landscape ones. I attempted to use ...

full-page overlay is covering the entire screen

Is there a CSS-based solution to create an overlay that remains visible even when the page is scrolled down? I want to use this overlay behind a popup. Using JavaScript to set the height of the overlay based on the page's content is one option, but I& ...

Utilizing tag keys for inserting text and adjusting text sizes within a Web application

Creating an online editing interface for coursework where keyboard events are used. The goal is to have the tab key insert text, while also reducing the size of the text on that line. However, upon using getElementById, an error message pops up stating: ...

How can I take a screenshot of an element in Selenium?

I am attempting to capture the image of the "canvas" element shown in the screenshot. The code I am currently using is as follows: driver.find_element_by_tag_name('canvas').screenshot("canvas.png") driver.find_element_by_tag_name('canvas&ap ...

What could possibly be causing the "Unexpected token (" error to appear in this code?

Sorry if this appears as a typo that I am struggling to identify. My browser (Chrome) is highlighting the following line <a class="carousel-link" onclick="function(){jQuery('#coffee-modal').modal('show');}">Book a coffee</a> ...

Utilizing the CSS Top and Left attributes along with Jquery animations

There are two divisions on a page, namely Left_Div and Right_Div. The images in the Right_Div are positioned using CSS properties such as Top and Left. The Left_Div acts as a left panel, and upon clicking a button, both Left_Div and Right_Div animate to sl ...

The jQuery .accordion() feature is not functioning properly due to the failure to load jQuery into the HTML document

I have exhaustively researched online and visited numerous resources, including Stack Overflow. Despite making countless adjustments to my code, it still refuses to function properly. The frustration is mounting as I struggle with jQuery - a technology tha ...

Disabling autocomplete for an HTML element is proving to be ineffective

I am encountering a challenge with the autocomplete attribute on my HTML <input> element. I assumed that setting it to off would disable auto fill. I have conducted extensive research and even consulted AI, but I have not been able to resolve the is ...

How does the 'v-show' command cause unexpected changes to the normal layout of HTML elements (such as the position of divs)?

I'm looking to create unique custom components, similar to the one shown in this image: https://i.sstatic.net/MLj1a.png Just to clarify, this is a component from an element(). When I hover over the picture, it displays a translucent background. So ...

The display:block links are not properly positioned within the absolute div

I'm having trouble figuring out why my links are not working for the .pushMenu divs on the left and right side, html: <header class="header"> <div class="pushMenu" id="left"> <a href="" title=""><p>l</p>< ...

Effortless navigation with smooth scrolling on anchor links in react/next.js

Can smooth scrolling be achieved using only CSS when clicking on an anchor link within a react component? ... render( <a href="#smooth-link">Link To There</a> .... <div id="smooth-link"> .... ...

What is the proper way to utilize Vue and Buefy Tab components?

I'm currently designing a Vue page that includes the Buefy b-tab element. My request is quite simple, as outlined below: The page consists of a Buefy Tab element and a button. https://i.sstatic.net/TkiVYfJj.png Upon clicking the tick button, it sho ...

Having trouble with jQuery's recursive animation functionality

I have developed a function to scroll multiple images horizontally in the header of my website. Inside my header, I have implemented code that looks like this: <div class='images'> <!-- this div is 150% wide with overflow hidden --> ...

Using JavaScript's document.write method to display HTML code, along with a variable retrieved from a Flash application

Can I ask two questions at once? Firstly, how can I achieve the following? document.write(' <div id="jwplayer"> <center> <div id='mediaplayer'></div> <script type="text/javascript"> jwplayer('mediapl ...