Using flexbox to horizontally display a list in mySQL

I am currently displaying items from a mySQL database.

Initially, I used tables and it was working perfectly fine.

However, I have now shifted to using flexbox because apparently, tables are not the ideal approach.

Each item is stored in an unordered list.

The issue I am facing is that the list continues to be displayed vertically instead of horizontally across the page.

Does anyone have any simple flex-box list code they could share? Responsive design can wait until I figure this out!

Below is a snippet of the PHP code:

   while($row = $results->fetch_array()) {
       print '<section><ul class="flexcontainer"><li class="flexcontent">
                '.$row["ID"].'
            </li>';

Answer №1

If you're in search of a way to align items horizontally, consider using flex-direction: row; for the ul element. Check out this resource for more information: https://developer.mozilla.org/en-US/docs/Web/CSS/flex-direction

However, tables are also effective for displaying data. They can even be made responsive with some CSS adjustments. Give this code snippet a try:

table, tr, td {
    display: block;
}

Remember to share your code so others can better assist you in identifying any issues.

Answer №2

Main answer

If you want a list to display horizontally, apply the flex properties to the list element, not the individual list items.

For example, if you have a <ul> with <li> items, your HTML code could look like this:

<ul style="display: flex; flex-direction: row;">
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
</ul>

Additional notes

The solution above will align the items horizontally but may cause overlap. To prevent this, consider using justify-content: space-around; to evenly space out the items. More options can be found here.

To ensure the items wrap to the next line when reaching the edge of the container, use flex-wrap: wrap;.

These tips should help resolve any layout issues you are facing :)

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

Laravel 5 - Mysterious Database Error

My current project involves creating a login form using Laravel 5. Every time I attempt to log in, I encounter the following error: PDOException in Connector.php line 55: SQLSTATE[42000] [1049] Unknown database 'php2project' Despite the da ...

Floating Div Elements

Trying to solve this seemingly simple problem has been quite the challenge for me. I have a container with multiple divs added to it, and I want these divs to position themselves freely within any available white space. However, they must follow a pattern ...

Steps for choosing an image and embedding it within a div element

Upon loading the site, an image is displayed with the following code: <img id="some_Image" src="some_source"> However, I am looking to avoid requesting this image again from "some_source". This is because calculating the image can be resource-inten ...

Optimally align child divs within container in row and column layouts

Looking for a way to dynamically adjust div sizes based on available space within the parent container to minimize white space. Hoping for a solution that can accommodate fluctuations in the number of divs over time. The goal is to reduce white space as m ...

The Youtube Subscribe Embed feature is causing my image to lose its corners

When I use the official embed code from Google Developers to embed my YouTube channel, it cuts off the corners of my image and leaves white corners. This doesn't look good on my website with a black background. <script src="https://apis.google ...

Why isn't this button aligning in the center properly?

I'm currently using Bootstrap V5 and trying to center the login button in the div. I've attempted using mx-auto and text-center, but so far, none of them seem to be working. Can anyone point out where I might be going wrong? <div class='c ...

Guidelines for displaying JSON data in HTML <ul><li></li></ul> format using jQuery within an ASP.NET environment

I am currently developing an asp.net application that involves fetching data from a database in JSON format and displaying it within html ul-li tags using jQuery. Below is a snippet of my Html Page: <html xmlns="http://www.w3.org/1999/xhtml"> <he ...

Choose and eliminate in one simple query

I am working with 2 tables: users (user_id, user_connected) rooms (room_id, room_initiating_user_id, room_target_user_id) My goal is to remove all "rooms" where both the initiating user and the target user are set to "user_connected=0" However, I' ...

What could be the issue with this MYSQL DELETE query?

I am trying to remove entries from a table that have a message_id greater than a specific value. However, my delete statement doesn't appear to be functioning properly. http://sqlfiddle.com/#!2/4f8ee/1 Any help would be greatly appreciated. Thank yo ...

What is the optimal database design for incorporating social login functionality?

The structure of the "user" table in my application is as follows: CREATE TABLE IF NOT EXISTS `users` ( `userId` int(10) unsigned NOT NULL auto_increment, `username` varchar(128) NOT NULL default '', `password` varchar(32) NOT NULL default ...

Element with adhesive properties alters its color at a particular location

I need the sticky element to change colors at specific points and then revert back to its original color. The color should be orange initially, green on block 2, and orange again on block 3. For the complete code and to address any issues with jQuery, pl ...

:empty selector for targeting an empty tbody element

Here is the table provided for reference: <table id="incidents"> <thead> <tr> <th></th> </tr> </thead> <tbody> </tbody> </table> When using jQuery, th ...

Buttons and links with intricate geometries

I am currently developing a web application using Java/JSF and I am interested in finding out about technologies that would allow me to define intricate shapes as clickable buttons or links. Right now, my only option is to split an image into smaller trans ...

How can I align divs horizontally within a container using CSS?

Struggling with WP 3.0.4 not showing my css styling correctly for aligning four boxes (divs) horizontally inside a container div. Interestingly, the same css rules work flawlessly on my hand-coded html/php website that uses HTML 4.01 Transitional//EN. Howe ...

Exploring the World of MySQL Joins

Currently, I have a complex select statement that successfully identifies the current left and right devices of a contact. It works flawlessly and also retrieves the contact's ID. Here is the SQL query: SELECT locations.name AS location_name, CONCA ...

Is the float floating within another float?

This question may have a strange title, but I couldn't think of anything better to call it. So, here's the situation: I have a grid layout where I need my .search-wrapper to be 50% wide and floated to the right. In my demonstration on jsfiddle, ...

Craft a stunning transparent border effect using CSS

I am trying to achieve a unique border effect for an element using CSS, where the transparency is maintained against the background: This is the desired outcome: https://i.stack.imgur.com/6Z1MU.png However, the border I am currently able to create looks ...

IE and Chrome are experiencing issues where the radio buttons are disappearing

Here is the style sheet code: select,input ,td a {border:1px solid green; width:25%;height:25px;font-size:20px;margin- left:.1em;} input.myradio {border:none;width:0%;height:0%;font-size:0%;} And here is the corresponding HTML code: <td><inpu ...

Can a border-bottom be made the same size as a class it is not linked to in CSS?

Can I set a border-bottom to match the size of a separate class? For example, I want a border-bottom at the bottom of each <section> tag. However, since the sections span the full width of the screen, the border-bottom inherits that width. Each < ...

What is the best way to display a loading gif during a request being processed?

I have browsed through multiple similar queries previously, but none of them address the specific issue I am facing. My scenario involves two div blocks structured as follows: #content { width: 800px; height: 600px; margin: 0 auto; display: flex ...