Items that do not commence from the start of the list

I'm encountering an issue with my unordered list where the li elements are not rendering properly. The first element seems to have a margin, and I'm unsure why this is happening. How can I fix this problem?

function App() {
  return (
    <ul
      style={{
        position: 'absolute',
        width: '75%',
        height: '5%',
        left: '12.5%',
        top: '25%',
        'list-style-type': 'none',
        'background-color': '#f8d7d7'
      }}
    >
      <li
        style={{
          width: '20%',
          float: 'left',
          height: '100%'
        }}
      />
      <li
        style={{
          width: '20%',
          float: 'left',
          height: '100%'
        }}
      />
      <li
        style={{
          width: '20%',
          float: 'left',
          height: '100%'
        }}
      />
    </ul>
  )
}

ReactDOM.render(<App />, document.getElementById('root'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<div id="root"></div>

Answer №1

Here are a couple of reasons why this might be occurring:

  1. If your <ul> is set to have a position of absolute with a left 12%, it will create space on the left side.

  2. Additionally, if your <ul> has its own padding, this could also contribute to additional spacing at the beginning - you may need to adjust this based on your specific needs.

Answer №2

function App() {
  return (
    <ul
      style={{
        position: 'absolute',
        paddingLeft: '0px',
        width: '75%',
        height: '5%',
        left: '12.5%',
        top: '25%',
        'list-style-type': 'none',
        'background-color': '#f8d7d7'
      }}
    >
      <li
        style={{
          width: '20%',
          float: 'left',
          height: '100%'
        }}
      >list item 1 </li>
      <li
        style={{
          width: '20%',
          float: 'left',
          height: '100%'
        }}
      >list item 2 </li>
      <li
        style={{
          width: '20%',
          float: 'left',
          height: '100%'
        }}
      >list item 3 </li>
    </ul>
  )
}

ReactDOM.render(<App />, document.getElementById('root'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<div id="root"></div>

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

Attempting to place a different span beneath the current span

Is it possible to add another span below the first span and keep it on the same line as the circle? Check out this link for reference The following is the HTML code snippet: <div class="dialog-box"> <div class="dialog-box-circle"></d ...

unexpected automatic scrolling that occurs when hovering over an element

a sudden scrolling takes effect simultaneously with hovering on an element. What confuses me more is that it does not happen every time I hover over the element but just occasionally or maybe there is a specific scrolling position that I can't see yet ...

Utilizing shared state in React components through props

Currently, I am utilizing a shared global state in the following manner: interface DashboardProps extends React.Props<Dashboard> { globalState? : GlobalState } export class Dashboard extends React.Component<DashboardProps, any>{ } Withi ...

Hey there, I was wondering if it's possible to modify the color of the navbar when scrolling on a specific page

After the first 3 pages with a black background and a transparent navbar with white navigation items, I encounter visibility issues when scrolling to the colorful 4th page. Is there a way to change the navbar color on this specific page using ONLY HTML a ...

Discover the benefits of utilizing router.back() cascade in Next/React and how to effectively bypass anchor links

Currently, I am working on developing my own blog website using Next.js and MD transcriptions. The issue I am facing involves anchor links. All the titles <h1> are being converted into anchor links through the use of the next Link component: <Link ...

Using React MUI Select in combination with react-hook-form does not seem to be compatible with Cypress testing

Within my React application, I have implemented a form that includes a dropdown select. Depending on the option selected from the dropdown, different input fields are rendered. const [templateType, setTemplateType] = useState(""); const { regi ...

Tips on utilizing React and Node to upload text as a file to Google Drive

Are you wondering how to incorporate React.js as the frontend and Node.js as the backend for uploading/reading files from Google Drive? In my attempts, I've tried writing a string as a text file and then uploading it to Google Drive by following this ...

Vue application experiencing issues with applying Sweet Alert CSS styles

I successfully integrated vue-sweetalert2 into my Vue app (version 2.6). The setup in my main.js file looks like this: import VueSweetalert2 from 'vue-sweetalert2'; Vue.use(VueSweetalert2); In one of my components, I have a basic button with a ...

How to access the api variable in JavaScript

When attempting to retrieve variables from an API object, I encountered the obstacle of them being nested inside another object named "0" in this particular case. Here is a screenshot from the console: enter image description here Below is the JavaScrip ...

A method for positioning each pair of <li> elements side by side

My goal is to arrange every pair of li elements next to each other (e.g. 0-9, A-B, C-D, ...). Currently, they are aligned one by one. <ul> <li class="alphabetRow"><a href="#" id="alpha_1" class="alphabet active" >0-9</a></li ...

Quickly redesigning the appearance of file input using javascript and jquery. Seeking assistance to correct css issues on jsfiddle

Hey there, I've been working on styling the input[type="file"] element and could use some assistance. Like the saying goes, "One JSfiddle is worth 1000 words," so here's the link to my example: --- For more details, click here: http://jsfiddle.n ...

Expanding Issue with Bootstrap Navigation

Hello! I am experiencing an issue with my navbar. The menu collapses, but it does not expand. I have used an example from Bootstrap and made some tweaks, but for some reason, it still doesn't expand properly. Below is the code that I have been workin ...

Achieving an oval shape using HTML5 and CSS3: Step-by-step guide

<!DOCTYPE html> <head> <title> Oval shape</title> </head> <body> <div style="width:400px; height:400px; background-color:#ff0;">Oval</div> <p> Exploring the creation of an oval shape using HTML5 ...

What could be causing this discriminated union to act differently than anticipated?

Desired Outcome When the href prop is present, TypeScript should recognize that the remaining props are suitable for either a Link or Button element. However, I am encountering an error indicating type conflicts with the button element. Type '{ chil ...

designing various containers and adjusting their divisions

I have a pop-up window that contains the code snippet below, defining a template within a "container": <form method="post" class="signin" action="#"> <div id='container'> <div> <div id="divFeeTitle"&g ...

Sharing libraries among different web components can be achieved by following these steps

Embarking on a micro frontends project using custom elements has sparked the need to find a way to share dependencies across all parts of the application. I am particularly interested in integrating the Material-ui library into this structure. One idea is ...

Module 'c: est-dev3 est_namewebpack-dev-server' not found

Attempting to run an app built with React and Webpack, along with webpack-dev-server. Made changes to the run script in package.json as it was originally written for Unix and I am working on Windows. Feeling quite lost as a beginner. Using: Node v8.9.4 N ...

What is the best way to trigger a download of an external image (AWS signed URL) when a button is clicked?

Currently, I am facing a challenge attempting to download an image from an s3 Presigned URL upon clicking a button in Nextjs (client-side). To provide some context: On the backend, I'm utilizing Golang and on the front end, it's the Nextjs Reac ...

What is the best way to adjust the dimensions of a blank image without altering the size of

I am attempting to set the size of an empty image to 150px. While using float: left works on Firefox, it does not have the same effect on Google Chrome. Here is the HTML code: <div> <img src='some broken url' alt='no image'& ...

Parent container fails to center align when window is resized

When I resize my window to a smaller size, like that of a smartphone screen, the three inner divs (colored red, green, and blue - .left, .center, and .right) do not align in the center. Please refer to the screenshot attached for clarity. My goal is to ens ...