How can I use flexbox to position this footer at the bottom of its parent container?

I'm not an experienced designer and it's been a while since I last worked with CSS. I'm diving into using flexbox layout for the first time and feeling a bit overwhelmed.

Here is the existing HTML structure that I need to work with and cannot modify:

<section class="infobox">
  <main class="popup">
    <aside class="thumb"><img class="mini" src="image.jpg" /></aside>
    <article class="info">
    <h1>Heading Text</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Quis ipsum suspendisse ultrices gravida. Risus commodo viverra maecenas accumsan lacus vel facilisis.</p>
    </article>
    <footer class="infofoot">
      <a target="windowid" href="http://example.com">A single line of linked text.</a>
    </footer>
  </main>
</section>

This is my current CSS code snippet:

<style type="text/css">
/* <![CDATA[ */
a {
  text-decoration: none;
}

img.mini {
  width: 20vw;
  height: 20vh;
  float:left;
  padding: 20px 10px 10px 10px;
}

.infobox { 
  display: flex;
  flex-direction: column;
}
.popup { 
  width: 50vw;
  flex-direction: row;
}

When rendered, it looks like this...

https://i.sstatic.net/XnGFG.png

I'm struggling to get the footer section positioned below the image in the aside. I've experimented with align-self and flex-grow properties but haven't found a working solution yet. Can you provide guidance on how to achieve this?

Answer №1

When working with the float property, one method is to add clear: both to the element you want to display on a new line after the floated element:

a {
  text-decoration: none;
}

img.mini {
  width: 20vw;
  height: 20vh;
  float: left;
  padding: 20px 10px 10px 10px;
}

.infobox {
  display: flex;
  flex-direction: column;
}

.popup {
  width: 50vw;
  flex-direction: row;
}

/* forces the selected element(s) to a new line: */
.infofoot {
  clear: both;
}
<section class="infobox">
  <main class="popup">
    <aside class="thumb"><img class="mini" src="image.jpg" /></aside>
    <article class="info">
      <h1>Heading Text</h1>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Quis ipsum suspendisse ultrices gravida. Risus commodo viverra maecenas accumsan lacus vel facilisis.</p>
    </article>
    <footer class="infofoot">
      <a target="windowid" href="http://example.com">A single line of linked text.</a>
    </footer>
  </main>
</section>

JS Fiddle demo.

To achieve a similar layout using CSS grid instead of flex-box:

a {
  text-decoration: none;
}

img.mini {
  width: 20vw;
  height: 20vh;
  float: left;
  padding: 20px 10px 10px 10px;
}

.popup {
  width: 50vw;
  /* using grid layout: */
  display: grid;
  gap: 0.5em;
  grid-template-areas: "thumb article" "footer footer";
}

.infofoot {
  grid-column: span 2;
}
<section class="infobox">
  <main class="popup">
    <aside class="thumb">
      <img class="mini" src="image.jpg">
    </aside>
    <article class="info">
      <h1>Heading Text</h1>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Quis ipsum suspendisse ultrices gravida. Risus commodo viverra maecenas accumsan lacus vel facilisis.</p>
    </article>
    <footer class="infofoot">
      <a target="windowid" href="http://example.com">A single line of linked text.</a>
    </footer>
  </main>
</section>

Another option is to utilize CSS flexbox for card layouts:

*,
 ::before,
 ::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.infobox {
  display: flex;
  flex-direction: column;
}

.popup {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.5em;
  width: 50vw;
}

.thumb {
  flex-basis: 30%;
}

.info {
  flex-basis: 65%;
}

.mini {
  object-fit: cover;
  width: 100%;
}

.infofoot {
  background-color: azure;
  flex-basis: 100%;
}
<section class="infobox">
  <main class="popup">
    <aside class="thumb">
      <img class="mini" src="https://www.fillmurray.com/200/300">
    </aside>
    <article class="info">
      <h1>Heading Text</h1>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Quis ipsum suspendisse ultrices gravida. Risus commodo viverra maecenas accumsan lacus vel facilisis.</p>
    </article>
    <footer class="infofoot">
      <a target="windowid" href="http://example.com">A single line of linked text.</a>
    </footer>
  </main>
</section>

Additional Resources:

Answer №2

    <section class="infobox">
  <main class="popup flex-column">//make it flex column
<div class="flex-row">//make it flex row

    <aside class="thumb"><img class="mini" src="image.jpg" /></aside>
    <article class="info">
    <h1>Heading Text</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 
     tempor incididunt ut labore et dolore magna aliqua. Quis ipsum suspendisse 
      ultrices gravida. Risus commodo viverra maecenas accumsan lacus vel 
      facilisis.</p>
    </article>
</div>

    <footer class="infofoot">
      <a target="windowid" href="http://example.com">A single line of linked text.</a>
    </footer>

  </main>
</section>

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

Add a CSS style to an element when its parent container is hovered using Angular

I am looking for a way to change the appearance of an element when its container is hovered over using CSS or SCSS. Here are my requirements: - The solution must be implemented within the child component or the sass file, without knowledge of parent-child ...

Increase the bottom padding or add some extra space to the Bootstrap form or page

I am currently working on enhancing a Bootstrap Form that includes reset/submit buttons positioned at the bottom. A common issue is when iPhone users attempt to click the Submit button, which initially displays Safari icons before requiring an extra tap to ...

What is the best way to modify the underline style of a tab in Material UI?

I'm trying to customize the underline of: https://i.stack.imgur.com/J2R1z.png Currently, I am using material ui version 4.12.3 The code snippet for generating my tabs is below: function renderTabs(): JSX.Element { return ( <Tabs className={cla ...

Three brothers and sisters - One must expand responsively while the remaining two maintain minimum content sizes

Attempting to outline the limitations at hand. We have 3 containers named .content, .left, and .bottom, along with a resize handler that governs the available space. I aim for the .container to expand as the space increases, utilizing all available area. ...

What are the steps to incorporating the League Gothic font into my website design?

Is there a way to incorporate League Gothic font into my website design? Visit the League Gothic GitHub repository Appreciate any guidance on this matter, ...

Discover the row and column of a selected table cell using vanilla JavaScript, no need for jQuery

In my JavaScript code, I am currently working on creating an onclick function that will display the row and column of a specifically clicked cell in a table. I have successfully implemented functionality to return the column number when the cell is click ...

Is there a way to combine fixed and dynamic size elements within a flexbox container?

Currently, I am working on creating a layout that combines the automatic sizing feature of flexbox with fixed-size elements: <View style={{ height: 70, alignItems: "center" }}> <Text style={{ flex: 1, textAlign: "right", paddingRight: 10 }}&g ...

LESS — transforming data URIs with a painting mixin

Trying to create a custom mixin for underlining text, similar to a polyfill for CSS3 text-decoration properties (line, style, color) that are not yet supported by browsers. The idea is to draw the proper line on a canvas, convert it to a data-uri, and the ...

Optimizing responsiveness and side margins for high-resolution displays

Struggling with creating a website design with Bootstrap. My goal is to add margins on the sides when the screen size increases, but once I achieved it, the responsiveness of the page got disrupted. To incorporate the side margins, I enclosed the entire b ...

Struggling to design a functional mobile keyboard

I've been working on creating a mobile keyboard, but I'm facing some issues with the JavaScript part. The problem seems to be in my code as the keyboard isn't responding when I try to type. Here's a snippet of the JavaScript I'm us ...

Is it possible to smoothly switch between two states using just a single animation class?

I am trying to trigger an animation with a single class, and then have that animation play in reverse when the class is removed. To better explain, I have created a CodePen example of my current progress. In the CodePen, you can see that when the class . ...

Exploring the functionality of the block grid and its purpose within Foundation5

I recently came across Foundation5's Block Grid feature, which seems to have a limited online presence in terms of use cases demonstrating its importance. Unlike Bootstrap3, which does not include Block Grid, I am curious about how significant of a fu ...

Having trouble getting rid of the border-bottom?

I have been attempting to customize the appearance of the React Material UI tabs in order to achieve a design similar to this: https://i.stack.imgur.com/tBS1K.png My efforts involved setting box-shadow for the selected tab and removing the bottom border. ...

Arrange the image in a way that flows smoothly with the text

I want to achieve the effect of having a picture of a Pen positioned behind the text "Create" on the left side. It looks good at full size, but the positioning gets messed up when the screen size is adjusted. How can I make it responsive so that the image ...

Ways to slightly boost the default font-size values when using wicked-pdf

In the wicked-pdf report, I have body content with varying font sizes. When I apply a font-size of 16px to the paragraph like so: p { font-size: 16px !important; } The entire paragraph's font size becomes 16px, which may include words with diff ...

What is the best way to make a CSS class appear in my javascript using the method I have been using before?

I am facing an issue in making this code work properly. It functions correctly for my caption element as there is only one caption tag in my HTML. However, the same code does not work for my TR element since it requires a for loop to iterate through multip ...

Can you please explain the purpose of the white space in the HTML code?

Currently, I am working on developing a mobile application, and as I start adding styles, I notice a mysterious blank space that seems to be appearing out of nowhere. Can anyone provide any insights or suggestions to help me troubleshoot this issue? https ...

Header components struggling with proper alignment in CSS

I'm facing an issue with the navigation bar elements in my header. They are currently aligned to the left side of the screen, but I want them to move to the right. Does anyone know why they are not moving? Also, is there a specific rule or method for ...

"Enhance Navigation: Sublevel Dropdowns with the Power of Twitter

Here is a link to my fiddle: http://jsfiddle.net/xkXdy/ I am trying to create submenus for the dropdown input box in my project. Currently, it only shows the category, but I want it to display subcategories when hovered over. The dropdown functionality wo ...

Creating aesthetically pleasing and flexible rows with left-floated div elements of varying heights

I need to arrange a series of elements in rows that look like tables, with fixed width but variable height determined by the content. Each element is set to float left and have the same width value. The issue I'm facing is that sometimes the elements ...