Tips for preventing horizontal list items from stacking on top of each other in React

After successfully creating a horizontal list using HTML and CSS, I encountered an issue when trying to replicate the same code in my React application. In React, the list elements were stacking on top of each other due to a styling conflict with the stylesheet. Below is the original HTML code along with its corresponding stylesheet:

.os{
                width:800px;
                height: 20px;
                list-style: none;
                text-align: justify;
                margin: 80px auto;
                background-color: black;
            }
            .os:after {
                display: inline-block;
                content: "";
                width: 100%;
            }
            /* Remaining CSS styles */
            
<!DOCTYPE html>
            <html>
                <head>
                    <title>react</title>
                    <meta charset="utf-8">
                    <link rel="stylesheet" href="style.css">
                </head>
                <body>
                    <ul class="os">
                        <li data-year="2016" data-text="lorem"></li>
                        <li data-year="2017" data-text="ipsum"></li>
                        <li data-year="2018" data-text="dolor"></li>     
                    </ul>      
               </body>
            </html>

The React code implementation appeared as follows:

render(){
        
                 return(
                    <ul className="os">
                         {/*{json.map((row,index)=>{
                             var tytul = row.tytul
                             var data = row.data
                             return  <li key={row.id} data-year={data} data-text={tytul}></li>
                            
                         })}*/}     
                        <li data-year="2016" data-text="lorem"></li>
                        <li data-year="2017" data-text="ipsum"></li>
                        <li data-year="2018" data-text="dolor"></li>     
                    </ul>
                        )
                     }
    

However, the rendered output did not align properly as shown in this image. Both the HTML version and React app referenced the same stylesheet for styling.

Answer №1

Perhaps using text-align: justify; in the .os class is not the best idea. Here's an alternative solution.

.os {
  width:800px;
  height: 20px;
  list-style: none;
  /* text-align: justify; */ /* Remove this line */
  margin: 80px auto;
  background-color: black;
  display: grid; /* New line */
  grid-template-columns: repeat(auto-fit, 200px); /* New line */
}

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

Running Perl CGI script within an HTML document

I'm currently facing an issue while attempting to execute a perl script within an html context. Upon execution, I am encountering an error labeled as "Internal Server Error," which does not provide much insight. Additionally, I am seeking guidance on ...

How to automatically refresh the idToken in a Firebase http request when the currentUser object is null?

Currently implementing a Custom Auth System with React JS and Firebase for sign-in operations. The Back End generates a custom token, allowing the Front End to execute signInWithCustomToken. After successful sign in, an issue arises when refreshing the pa ...

Prevent the Bootstrap Navbar from collapsing

Trying to customize a Bootstrap navbar for specific needs, I've encountered an issue. I want the first two links on the left (home and menu glyphs) to remain visible even when the window is resized down, while the rest should collapse. Check out the ...

Adjusting the media query breakpoints based on the visibility of the side panel

I have been tasked with enhancing an already extensive React project by adding a 400px wide side panel that is only visible under certain conditions. Depending on the screen size, the side panel should either appear in the empty space to the right of the ...

Removing data with the click of a button

I have successfully implemented a feature where clicking the "add to my stay" button displays the name and price data. Subsequently, it automatically changes to a remove button when clicked again for another addon. If I press the remove button of the first ...

Eliminating data from selection options on a HTML menu list

Currently, I am facing an issue while attempting to incorporate a menu bar into my HTML page. After adding the icons, they are displaying with both underlines and dots at the back. I have tried using text-decoration=none; to remove the underline, but unf ...

HTML and Python synchronize perfectly when handling date formatting

Here is a code snippet I am working with: {% for x in fixtures %} <TR style="display:block" onclick="team_visibility('match{{ forloop.counter }}');"> <TD> {{ x.fixturedate }}</TD> ...

Utilizing HTML5/JavaScript to send a text message from a mobile device

I am developing a mobile web application to be downloaded from various markets with a mini web server, capable of running on any operating system such as iOS, Android, Windows8, and more. My goal is to make the application as OS-independent as possible by ...

How to Achieve a Fixed Bottom Footer in Ember Framework

Hello, I am working on an Ember application and trying to implement a Sticky Footer feature. I followed a tutorial on Sticky Footer On CSS-Tricks which worked for me previously, but it seems to not work with Ember. Here is my CSS code: .mainFooter { ...

Tips for creating a responsive H1 tag within the Avada WordPress theme by implementing CSS

One of my acquaintances recently upgraded his Avada WordPress theme to the latest version of WordPress without physically uploading any files. However, after this upgrade, he noticed that the page titles (H1) no longer appear responsive as they did before. ...

What is the best way to calculate the sum of for-loop values in a Django template

Inside my Django template, I have a code snippet that looks like this: {% load mathfilters %} {% with total=0 %} {% for item in numbers %} {{ total | addition:item }} {% endfor %} {% endwith %} At the conclusion of this code, the total value remain ...

Connecting the list elements to the current state

My React component is defined as: export default class App extends React.Component<AppProps, Items> The Items class is declared as: export default class Items extends Array<Item> where Item is a class with various properties. When I direct ...

What is the best way to import two components with the same name from different libraries?

How can I import the Tooltip component from two different libraries without encountering naming conflicts? For example: import { Tooltip as LeafletTooltip } from "react-leaflet"; import { Tooltip as RechartsTooltip } from "recharts"; By renaming the impo ...

Ways to design siblings that are not currently being hovered over

Is there a way to achieve an effect where hovering over one list item causes all other list items to fade out? I'm searching for a method to style an element that is not being hovered, when one of its siblings is in the hovered state. I've trie ...

Displaying buttons on each row in an ngx-datatable based on a condition using *ng

In my table, there is a column with a hidden element that appears when a show button is clicked. Currently, clicking the button reveals all hidden fields at once. I want to modify this so that only the input field for the specific row appears when the butt ...

Guide on positioning an svg icon and text content in the same row to be right-aligned using Bootstrap

I have attempted to align the icon and text towards the right side, but unfortunately, it is not working as expected. I am attaching the design for reference. I have tried using the following code - please advise if there are any other options available. ...

Hover over a ListItem

Looking for advice on how to incorporate a Mouseover feature into a Material UI ListItem from the following link: http://www.material-ui.com/#/components/list. As the "SecondaryText" is limited to 2 lines, I am exploring options to display additional data ...

Tips for successfully sending a nested function to an HTML button and dropdown menu

I'm working on two main functions - getChart() and fetchData(). The goal is to retrieve chart data and x/y axes information from a database. Within the getChart function, I'd like to incorporate a dropdown menu for displaying different types of c ...

Dynamic element substitution

Can you provide guidance on how to create a smooth transition in the height of a container based on the child element's height? Currently, my code does not include any animation effects. setTimeout(() => { document.getElementById("page1").st ...

Connecting users from a mobile website to a particular item within the Amazon application

Recently, I've been working on linking from my mobile site to a particular item within the Amazon app. My JavaScript code includes a try/catch block that redirects users to the webpage if they don't have the app installed. However, I've foun ...