The alignment of items to the top, center, and bottom is experiencing difficulties

I am facing an issue with positioning elements within a div. The layout consists of an image on the left, followed by information on the right (a span, an h3, and another span). My goal is to align the first span at the top, center the h3, and position the other span at the bottom to create a visually appealing arrangement. However, my current setup is not achieving this desired outcome.

Can you identify where the problem lies?

To better understand the issue, you can view an example here: https://jsfiddle.net/ct1ghpk2/2/

HTML:

<div class="item">
        <img src="">
        <div class="item_info">
            <span class="align-t">Span aligned at the top</span>
            <h3>Title aligned at the center</h3>
            <span class="align-b">Span aligned at the bottom</span>
        </div>
        <div class="item_separator"></div>
        <div class="item_details">
            <span>Span aligned at the center</span>
            <a href="">Link aligned at the bottom</a>
        </div>
    </div>
    

CSS:

.item{
        background-color: white;
        display: flex;
        margin-bottom: 20px;
        align-items: flex-start;
        padding: 10px;
        justify-content: space-between;
        height: 10em;
        border: 1px solid red;
    }
    
    /* Remaining CSS styles */
    

Answer №1

To ensure that .item-info takes up the full height of its parent, set its height to 100%. Then, add the flex box property justify-content: space-between; to .item-info in order to create the desired spacing for the content within the div.

.item-info {
    #yourStyles
    height: 100%;
    justify-content: space-between;
}

For more information on CSS flexbox and its properties, you can refer to this resource.

Regarding .item-details...

.item_details{
    #yourStyles
    height: 100%;
    justify-content: flex-end;
}

.item_details span{
    #yourStyles
    margin-top: 25%;
    text-align: center;
}

When using justify-content: flex-end; for a column, the content will align starting from the bottom and moving upward. By adding a 25% top margin to the span element inside that div, you will achieve the desired top spacing while keeping everything else aligned towards the bottom.

Answer №2

This is the solution you requested based on my understanding.

Here are the modifications I have implemented:

.item_details{
  flex-basis: 30%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  position: relative;
}

.item_details span{
  font-size: 0.85em;
  color:gray;
}

.item_details a{
  font-size: 0.85em;
  border-radius: 4px;
  width: 100%;
  text-align: center;
  position: absolute;
  bottom:0;
}

Fiddle: https://jsfiddle.net/ct1ghpk2/6/

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 best way to customize image transparency using javascript?

Looking to create a webpage that shows an image for a specified duration before smoothly transitioning to another image that includes a clickable link. Wondering how to accomplish this using javascript? I am aware that it can be done with Flash, but it mu ...

The values in my JavaScript don't correspond to the values in my CSS

Is it possible to retrieve the display value (display:none; or display:block;) of a div with the ID "navmenu" using JavaScript? I have encountered an issue where I can successfully read the style values when they are set within the same HTML file, but not ...

Retrieving Files using Ajax Across Different File Types

I recently came across the following code snippet: DOM_imgDir = "img/UI/DOM/"; fileextension = ".jpg"; $.ajax({ url: DOM_imgDir, success: function (data) { $(data).find("a:contains(" + fileextension + ")").each(function () { filename = thi ...

Strategies for limiting a table row in JavaScript or jQuery without utilizing the style tag or class attribute for that specific row

I am looking for a way to limit the display of records in a table. Currently, I can restrict the table rows using the style property, but this causes UI issues such as missing mouse-over effects for the entire row. I need to ensure that mouse-over functi ...

Steps to create a floating navbar using tailwindcss

Here is the code snippet for the site header component: export function SiteHeader() { return ( <header className="fixed top-0 z-50 w-full border-b border-border/40 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60&qu ...

The toggle feature in Bootstrap is stuck in the "on" position and refuses to "untoggle."

Currently, I am working on developing a basic website using Laravel and Vue.js. To ensure that the website is responsive, I integrated Bootstrap 4 into the project. For the most part, everything appears to be functioning correctly - the navbar collapses as ...

Implementing AngularJS drag and drop functionality in a custom directive

I am in search of an example that demonstrates similar functionality to the HTML5 File API using Angular-js. While researching directives for Angular 1.0.4, I found outdated examples that heavily rely on DOM manipulation. Here is a snippet of the pure Ja ...

Creating a CSS container with a uniquely shaped rounded triangle/arrow design

I would like to create a container background with a rounded arrow design. The arrow should always stretch to the full width of the container and be able to adjust its height dynamically (I can use JavaScript if needed to adjust the height). Here's a ...

Tips for implementing an image placeholder in an AngularJS project

I have a search input box and I want to change the placeholder text "Search here" to an image. Is this possible? code <input id="autoComplete" type="text" ng-model="selected" typeahead="task.name for task in taskList | filter:$viewValue | limitTo:20" ...

Tips for maintaining grid width when columns are rearranged in the column menu

Is it possible to stop jqgrid from changing its width to full screen after column selection? I attempted the code below, following guidance from How to change column name in column chooser pop up in jqgrid? My aim was to create a column switcher function ...

Looking for assistance with changing the class of a span when a radio button is selected

I'm facing an issue with toggling the class of a <span> when a radio button is clicked. <html> <head></head> <style type="text/css"> .eHide { display:none; } </style> <script type="text/javas ...

Is It Acceptable for CSS Code to Contradict Default CSS Code?

Imagine if my CSS looks like this: div { margin: 0; overflow: auto; padding: 1%; text-align: center; word-wrap: break-word; } This is supposed to be the default styling for all div elements. But what happens if there's another div with conflicting c ...

Execute PHP function by clicking on an HTML anchor tag

I'm curious - can a PHP function be triggered simply by clicking a link, or is it better to stick with the form submit method? If linking works, where should the reference point to? Check out this code snippet: <?php session_start(); func ...

Easy ways to manipulate the style of array components in Vue.js

Hey there all you programmers, I'm reaching out to see if any of you have insight on how I can modify the style of a specific component within an Object array. This is the code snippet: <template> <div> <ul> <li v-fo ...

Discovering the page load times of web elements on a website with the help of Selenium WebDriver

On my HTML5 webpage, there are 4 charts that each take a different amount of time to load after the static content has already loaded. The loading process is indicated by a 'rendering' circle image for all 4 charts. I am looking for a way to dete ...

Enhancing Responsive Tables with Vertical Alignment in Bootstrap 4

When utilizing Bootstrap 4 and adding table-responsive to a table, the text may no longer be centered vertically. Is this a bug? If not, is there an easy solution available to center the text in the middle? A pure Bootstrap solution would be greatly apprec ...

I am attempting to assign a default value to a TextField by retrieving data from a GetMapping call in React, however, the value is not being successfully set

I am facing an issue with setting a default value for a TextField in my code. Even though I am trying to populate it with data from a GetMapping call, the value is not being set as expected. Here is the JSON response I receive from the API call: { "id": 1 ...

Step-by-step guide on positioning an image to show at the bottom of a div

I am trying to create a div that covers 100% of the screen height, with a table at the top and white space below it for an image. However, when I add the image, it ends up directly under the table instead of at the bottom of the DIV. I have searched on G ...

How to retrieve the dimensions of an image for a specified CSS class with Selenium or PIL in Python

I am interested in using Python to determine the size of specific images. Is it possible to automate this process so that I can identify only images with certain classes? I am unfamiliar with PIL. Could I define the CSS class/name/id after specifying the U ...

Every time I attempt to create a detail page for a table, I am consistently greeted with an error message

Error: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /var/www/2909kher/entabell/detaljer.php on line 23 <!doctype ...