Column of Flexbox showcasing items that have been translated

I'm having an issue with positioning items in a div of 11 elements divided into 2 columns. The first row and the last item are positioned correctly, but the items in between are shifted to the left. I've been using flexbox for a while, but I can't seem to find any issues in my code.

https://i.sstatic.net/prKle.jpg

Here is my HTML code:

<div class="postview">
    <?php while ($_posts->have_posts()): $_posts->the_post();?>
        <h1><a class="post-link" href="<?php the_permalink(); ?>"></h1>
            <div class="posts-layout">
                <h1><?php the_title(); ?></h1>
                <img src="<?php the_post_thumbnail_url('post-picture'); ?>" alt="">
            </div>  
        </a>      
    </div>
.postview {
    width: 65vw;
    background-color: rgb(243, 243, 243);
    margin: auto;
    display: flex;
    flex-direction: initial;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-evenly;
    margin-top: 8vh;
    margin-bottom: 4vh;
}

.post-link {
    text-decoration: none;
    color: black;
}

.posts-layout {
    height: 100%;
    background-color: rgb(206, 45, 45);
    width: 30vw;
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
}

.posts-layout h1 {
    font-size: 2vh;
    color: black;
}

Answer №1

Let's address the issue at hand.

The root of your problem lies not with flexbox, but with HTML nesting. Avoid doing something like this:

<h1><a href="|"></h1> ... </a>

This is where things go awry.

You should aim for a structure more like this:

<div class="posts-layout">
  <a class="post-link" href="|">
    <h1>Lorem</h1>
    <img src="https://picsum.photos/200/200" alt="random image">
  </a>  
</div>

Furthermore, take a look at: Feedback requested: Runnable code snippets in questions and answers.

Implementing this will greatly enhance your experience on StackOverflow.

Additionally, if you're unsure how to incorporate random images into your code, familiarize yourself with .

Moreover, consider utilizing VScode or a similar tool. It can help identify these types of errors.

PS No offense intended, it's all part of the learning process. I hope you'll review this before your question is removed.

PPS Also, check out for additional assistance.

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 process for including a class along with a data attribute?

Working on implementing data buttons, struggling to make the function operational. Attempting to assign a class to an element through a data attribute and corresponding ID, then wanting to prevent event propagation with the button contained within the subj ...

Having trouble accessing a CSS file through HTML

Is there a reason why I am facing difficulties accessing main.css from app.html to enable Tailwind CSS? When I try putting it in the style brackets in the .svelte file itself, it throws an error. Can anyone explain why this is happening? <link rel= ...

Choose elements with unique identifiers other than those provided by the API

Seeking assistance with Material UI select element and naming dropdown. Have a few questions: 1: My API that populates the dropdown lacks good names. Is it possible to assign names like 'data 1, data 2, data 3...' to the options without manually ...

Invisibility Problem

As a newcomer to web design, this is only the second website I have ever created. However, I am facing an issue with my Nav bar that I cannot seem to resolve. I want my "Other Pages" section to be visible when the screen size is below 600px and hidden when ...

background image alteration when scrolling

I've been attempting to change the background image on scroll, but I haven't had any luck finding a guide. So, I'm hoping someone here can help me out. I found a video that showcases exactly what I'm trying to accomplish - https://www.y ...

Creating a mobile-responsive table using Bootstrap

I am struggling to make my bootstrap table more mobile-friendly. Despite trying various methods, I have not been satisfied with the results. I am interested in how others are successfully adapting their tables to look good on mobile devices while maintaini ...

Header remains fixed when scrolling

Is there a way to make the header of a Bootstrap table fixed when scrolling, while also adjusting the width of each column based on the content within it? I want the column headers to match the width of the row with the most text. Setting the position of t ...

How can I adjust height without affecting weight in CSS using curly brackets?

Can CSS be used to specifically adjust the height of a curly bracket without changing its thickness? I have been attempting to modify the height of a curly bracket dynamically by adjusting the font-size, but this also alters the weight. Is there a workar ...

What is the best technique for arranging buttons on a webpage?

As I dive into the world of creating chrome extensions, I've successfully added buttons and styled them with CSS. Now, my challenge is to arrange these buttons in three columns and two rows. How can I achieve this? Despite experimenting with various ...

Switching the body's background image dynamically using javascript

I'm attempting to switch up the background image using JavaScript. Here's how I've defined the background: body { background: black; overflow-x: hidden; overflow-y: hidden; } body:before { overflow-x: hidden; overflow ...

The 100% height setting is not functioning as expected

Why is the code below displaying strangely in Firefox and IE7, even though it works fine in Chrome? The height is set to 100%, but it seems to be not exactly that. Any ideas on how to fix this issue? Thank you! <iframe src ="demoFramesetLeftFrame.jsp ...

Center-align the table element

I've been struggling to center align this table element, specifically the one containing the square, but nothing seems to be working. Can anyone lend a hand in fixing this issue? <table> <tbody> <tr> <td>TURKEY - SU ...

Utilizing Angularjs for dynamic data binding in HTML attributes and style declarations

Can someone help me figure out how to use an AngularJS model as the value for an HTML attribute? For example: <div ng-controller="deviceWidth" width={{width}}> </div> Additionally, how can I achieve this within <style> markup? Where ...

Retrieve the child element that is being clicked

Alright, I'm facing a little issue here (it seems simple, but I just can't seem to crack it)... Let me paint the picture with a snippet of HTML code below: <!-- New Website #1 --> <!DOCTYPE html> <html style='min-height:0px; ...

Show a button using CSS when the cursor is hovering

Expressing my gratitude to everyone! I need assistance with implementing a function in reactJS where the <button /> remains hidden during page loading and reveals itself when hovered over. Despite trying various methods, I have been unable to resolve ...

Navigating pages in tinymce editor

Currently, I have implemented TinyMCE as the editor for my PHP-based website. However, I am facing a challenge in integrating pagination within the editor. My goal is to allow users to input long content that will be displayed across multiple pages inste ...

Styling the resizable textarea background color in Firefox

I am seeking to change the background color of multiple textareas on my website from the default white. textarea { background-color:Red; width:120px; height:80px; } <textarea>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam ...

SEO problem with meta refresh and form field click interruption

I have a webpage that automatically refreshes every 30 seconds with new random content. I am currently using a meta tag to achieve this, but I recently read an article stating that meta refresh is not SEO friendly. Can you suggest a more SEO-friendly metho ...

What is the best way to center a div horizontally when the width is unknown?

Check out the full screen result here: http://jsfiddle.net/anik786/UYkSf/4/embedded/result/ Here's where you can find the HTML/CSS: http://jsfiddle.net/anik786/UYkSf/4/ This is the HTML code: <div class="gallery_container"> <div class="pic ...

Is it possible to arrange the contents within a textarea by both key and value using JavaScript?

In my html page, there is a textbox labeled "Type your text" and TextArea list. The goal is to enter text into the textbox and then click the Add button so that the content of the textbox gets added to the TextArea list below. The required format for input ...