Utilize Flexbox's column direction to ensure that all flex items within the same column have uniform height

Having trouble creating a responsive web page. Here are the specifics:

Sharing my HTML and CSS code below: -

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link href="https://fonts.googleapis.com/css2?family=Manrope:wght@500;700&display=swap" rel="stylesheet" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css"
        integrity="sha512-5A8nwdMOWrSz20fDsjczgUidUBR8liPYU+WymTZP1lmY9G6Oc7HlZv156XqnsgNUzTyMefFTcsFH/tnJE/+xBg=="
        crossorigin="anonymous" />

    <title>Document</title>

    <style>
        /* CSS styles go here */
    </style>
</head>

<body>

    <div class="container">
        <div class="article">
            <div class="article-preview"></div>
            <div class="article-info">
                <h1>
                    Content goes here...
                </h1>
                <p>
                    More details inside...
                </p>
                <div class="article-author">
                    <i class="fa fa-apple" aria-hidden="true"></i>
                    <div class="author-info">
                        <span class="author-name">Author Name</span>
                        <span class="date">Date</span>
                    </div>

                </div>

            </div>
        </div>
    </div>


</body>

</html>

Trying to get the .article-preview flexbox item move up while the .article-info item moves below it.

To make the page responsive up to 763px browser width, added @media query with specified changes: -

@media (max-width: 763px) {
           /* Responsive CSS for smaller screens */
        }

Trouble is, when setting heights, elements still differ in size and overflow occurs from the container.

Desired outcome: 1) column direction, 2) same sizes for both items, 3) contained layout without overflow, and 4) responsive resizing within container. Seeking guidance on correcting this issue as a novice developer using HTML and CSS only.

PS: Important to implement solution exclusively using HTML and CSS.

Answer №1

After reviewing your code, it seems that when the article-info is displayed vertically, it grows to 305px instead of the expected 290px.

There are multiple solutions available, but ultimately, it depends on the design you prefer:

  1. Allow the card container to expand based on the content size.
  • If you keep the image at a fixed size, the upper and lower parts may not have the same height.
  • To maintain equal height, consider using background-size: cover for the image, though it may not display the entire image.
  1. Attempt to fit the article-info within the designated height.
  • You can adjust padding values in @media queries or experiment with the CSS clamp function. However, this may still disrupt the overall design if the information is too lengthy.
  1. Explore options to truncate text within the info section.
  • For a pure CSS approach, look into the text-overflow property. Alternatively, utilize JavaScript-based solutions like the text_overflow library.

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

Ensure uniform column width for recurring rows in CSS grid, irrespective of content width

Is there a way to ensure that a CSS grid maintains the same width for repeating rows, even if the content in each cell varies in length? I am attempting to set column 1 to be 10% width, column 2 to be 45% width, and allocate the remaining space to column ...

Utilize API or alternative methods for analyzing Instagram data

My master's thesis requires me to dissect multiple Instagram profiles, each containing over 1000 posts. I am in need of a comprehensive list including the following details: Type of Post (Image, Multi Image, Video) Description Likes Comments (total c ...

Issue with CSS background images

I'm having trouble trying to use this image as my background: . It just won't work... An error occurred while trying to set the background image. The declaration was dropped. Here is the HTML code: <div class="linkedin"></div> A ...

Achieve a sleek, modern look by using CSS to add a border with crisp square

Hello everyone, I'm currently attempting to add a border to only one side of an a element. However, when I add the border to just one side, it creates a sharp diagonal edge: https://i.stack.imgur.com/pAqMM.png My goal is to eliminate the sharp edge ...

Modify the color of the menu in OpenCart 1.5.6.4 to give it a fresh

In the default theme of OpenCart 1.5.6.4, I am looking to change the background color of the dropdown menu which is currently defined by the background image 'menu.png' to a custom hex value. The CSS code for this section is shown below: #menu & ...

interactive navigation menu with countdown feature

Looking to create an HTML/jQuery dropdown menu, but encountering a problem. The goal is for the div to slide down when the mouse hovers over the "games" navigation button and only disappear after 5 seconds of the mouse being out, not instantly. Here's ...

Tips for visually conveying the values of x and y using SVG symbols

I recently came across a blog post discussing the use of SVG symbols for icons, which inspired me to create representations of symbols using svg files. The original svgs I used had properties like x, y, height and width. However, when I tried adding these ...

Display HTML in JavaScript without altering the Document Object Model

Is it possible to style a custom HTML tag called "location" without directly modifying the DOM? For instance, having <location loc-id="14" address="blah" zipcode="14" /> Would it be feasible to render it like this: <div class="location"> ...

Is there a way to move the submit form button to the next line using CSS?

I am having trouble centering the submit button below two input fields in a simple React form. Can anyone offer assistance with this? HTML .SearchBar-fields { display: flex; justify-content: center; margin-bottom: 2.88rem; flex-direction: row; ...

"Is it possible to apply CSS to all HTML elements except for a

I am looking to apply the specified styles to all elements except for a particular class and its descendants. html * { box-shadow: none !important; border: none !important; color: white; } I attempted the following but it did not work as intended: ht ...

Tips for containing `overflow` within a flexbox container

I've organized my body space into three sections: header, content, and footer. To achieve a sticky footer effect at the bottom, I used the flex property in my layout. However, I'm struggling to add a scrollbar to my main container box. I've ...

Ensure that the horizontal navigation items are equally spaced apart

I've managed to align my longer navigation bar items horizontally instead of vertically, but I'm struggling to evenly space them alongside the shorter items within the container. Despite trying various solutions found through research, I have not ...

Combining existing CSS classes with node labels in Cytoscape JS for Angular: A Guide

My project follows a consistent CSS theme, but the node's CSS style doesn't match. I'm looking to adjust the label colors in the CSS based on whether it's day mode or night mode. How can I accomplish this? this.cy = cytoscape({ con ...

substitute a variable

I am trying to update the value of a variable using an HTML form. Within my config.php file, I have declared a variable $num = 3; I would like the value 3 to be replaced with whatever I input in the form form.html. Below is the code for my HTML form : ...

Tips for preventing the use of website URLs as variables in jQuery ajax() calls:

Having some trouble. For example: $(document).ready(function () { $("#btnSend").click(function () { var noti_p = { url: "Pusher_Controller.ashx", data: "&appname=" + $("#selt1").val() + "&title=" + $("#title"). ...

Having trouble with the function not running properly in HTML?

I'm having trouble implementing a copy button on my HTML page. Despite no errors showing in the chrome console, the text just won't copy. Below is a snippet of my HTML code: <!doctype html> <div class="ipDiv tk-saffran"> <div c ...

No specified margin at the top of the website's header section

My task was to design the header section of a webpage to resemble this desired webpage look. I started by creating a "header" tag as a container and added a navbar within it. To display the items, I used an unordered list with CSS adjustments for a horizon ...

Displaying divs inline with overlapping child divs

As a beginner in CSS, I tackle the challenges of learning it every day. Despite feeling clumsy and not naturally adept at it, my determination is strong (although sometimes my brain feels like an old computer on the verge of overheating). My current goal i ...

Unable to stop page refresh following form submission or file upload

Is it possible to upload a photo with Ajax to Express and have the response generate desired HTML? Whenever I submit the form, it redirects me and displays the picture data as an object. Here's the Express code: const storage = multer.diskStorage({ ...

How can I make my navbar stay fixed in place and also activate the transform scale functionality?

After fixing the position of my navbar with the class "top," I noticed that the transform property scale does not work on the div element I applied. The hover effect on the box only works when I remove the position from the navbar. This is the HTML code: ...