Elements in list appear to break apart when resizing

I had previously posted about this issue, but I deleted it after making some progress. I am currently facing a problem with my todo list project when resizing the screen. My project involves using JavaScript to create a new list item for each entry. Users input a task, and then a checkbox and remove icon are added. The issue arises on smaller screens, where the checkbox and remove icon move up a layer when a longer task name is entered. I am utilizing Bootstrap 4 to maintain the layout on my HTML side. Please refer to the image for clarity. I suspect the JavaScript code might be causing the problem.

Here is how the list appears on a medium-sized screen, with the checkbox/trash icon correctly positioned to the right of the item. https://i.sstatic.net/TDLoh.png

The problem occurs when the screen size decreases. As the text breaks down, the checkbox/trash icon moves up a line. How can I ensure that they stay on the same line as the text? I attempted setting the "li" element width to "90%;" with the checkbox/remove icon occupying the remaining 10%, but it did not improve the situation. I'm uncertain about the solution. Below, I will attach the relevant code snippet. https://i.sstatic.net/RnL5l.png

function show() {
var todos = get_todos();

var html = '<ul>';
for(var i=0; i < todos.length; i++) {
    html += '<span><input class="checkBox" type="checkbox"><li style="float:left;">' + todos[i] + '</li>' + '<button class="remove" id="' + i  + '"><i class="fa fa-trash" aria-hidden="true"></i></button></span><br/>';
};
html += '</ul>';

document.getElementById('todos').innerHTML = html;

var buttons = document.getElementsByClassName('remove');
for (var i=0; i < buttons.length; i++) {
    buttons[i].addEventListener('click', remove);
};
}
  body, html { /*makes the background image stretch the whole screen*/
height:100%;
}
body {
background-image:url('campingBackground.jpg');
background-repeat:no-repeat;
background-attachment:fixed;
background-position:center;
background-size:cover;
}
.checkBox {
margin-right:10px;
height:18px;
width:18px;
}
.checkBox:hover {
background-color:#C0C0C0;
}
  .remove { /*Trash can button*/
color:white;
font-size:24px;
border:0;
padding:0;
background-color:transparent;
}
.remove:hover {
color:#C0C0C0;
}
ul {
text-align:right; /*This pushes the checkbox/trash can right while the <li> in the js file floats the todo text left*/
list-style-type:none;
padding-left:0px; /*Makes up for not having the bullet point spacing on smaller screens*/ 
font-size:24px;
color:white;
font-weight:600;
}
li {
text-align:left;
}
<div class="header">
<div class="container" style="padding-top:50px;"> 
<div class="row justify-content-center"> <!--Input Box-->
<div class="col-sm-12 col-lg-8">
<h1>To-Do List</h1>
<div class="form-group">
<input type="text" class="form-control" id="task">
</div>
</div>
</div>
<div class="row"> <!--Add Button-->
<div class="col"></div>
<div class="col-xs-2" style="margin-right:15px; margin-top:30px;">
<button id="add" style="border-radius:50%; font-size:35px; width:65px;" class="btn btn-danger">+</button>
</div>
</div>
</div>
</div>
<div class="container text"> <!--ToDos-->
<div class="row justify-content-center" style="margin-top:20px;"> 
<div class="col-sm-12 col-sm-8">
<div id="todos"></div>
</div> 
</div>
</div>

Answer â„–1

Initially, it's important to note that constructing a list using ul with child nodes like span is not considered valid as per the guidelines defined in the HTML Specification for the unordered list (ul) element:

The ul element signifies a collection of items where their order isn't significant—meaning altering the sequence would not substantially impact the document's essence.

The individual entries within this list are represented by the li elements which serve as the child nodes of the ul element.

One main issue arises due to the title allocated for the todo item, leaving insufficient room for the actual content of the task.

In light of this, here are some recommended adjustments to rectify the issue within your code:

var todos = [
  'Task 1: Implement new feature',
  'Task 2: Review pull request on GitHub',
  'Task 3: Refactor existing codebase',
  'Task 4: A massively detailed and complex task requiring ample space to display properly'
];

var html = '<ul>';
for(var i=0; i < todos.length; i++) {
    html += '<li class="todo-item">' + 
          '<span class="todo-label">' + todos[i] + '</span>' +
          '<input class="checkBox" type="checkbox">' +
          '<button class="remove" id="' + i  + '">' + 
          '<i class="fa fa-trash" aria-hidden="true"></i>' + 
          '</button>' +
      '</li>';
};

html += '</ul>';

document.write(html);
.todo-item::after {
  content: "";
  clear: both;
  display: table;  
}

.todo-item {
  text-align: right;
}

.todo-item .task-label {
  display: block;
  float: left;
  max-width: 80%; /* Adjust size accordingly */
  text-align: left;
}

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

Execute the script repeatedly

(Since Stack snippet is temporarily down, I included a jsfiddle link): Visit this link for the code I've been struggling to get this script to work. Here's the simple Javascript code I have: $(document).ready(function() { showMessage(); s ...

Utilizing OrbitControls with SVGRenderer displays a pair of SVG elements positioned at opposite ends

In my project, I have created two scenes and two renderers. One scene is for a simple 3D mesh sphere, while the other is for an SVG circle. The SVG scene is positioned on top of the Mesh scene, acting as an overlay. Both the sphere and the circle are place ...

What is the best way to ensure that the input areas stretch all the way to the edge of the screen?

This form is structured similar to Bootstrap: HTML: <div class="container"> <div class="row"> <div class="form-group row-group"> <label class="col-6">First name</label> <input class="col-6" type="text" v ...

The Next.js dynamic route in production is displaying a 403 error instead of the expected 404. What might be causing this issue?

Whenever I attempt to access https://site.con/categories/, I am greeted with a 403 Forbidden error. However, if I visit https://site.con/categories/sport, everything works perfectly fine, and all other routes function properly. What could potentially be ca ...

What is the best way to share image data between pages in Next.js?

I'm currently developing a project that mimics Instagram (simply because I want to explore Next.js further) and I'm looking for a way to handle image uploads. My goal is to allow users to upload their images and then redirect them to the "create ...

Ways to revert to the initial state in React.js

Check out my codeSandbox project here: https://codesandbox.io/s/bold-lederberg-d2h508?file=/src/Components/Products/Products.js I'm having trouble getting the items back to their original presentation when clicking on "default" - sorting by price wor ...

Differences Between Mobile and Desktop Browser Media Queries

As I work on creating a responsive website, I have come across various examples of sites that adapt well to both desktop and mobile browsers. Currently, my stylesheet setup includes different media queries for various screen sizes. However, I've notic ...

Node.js dilemma of handling numerous asynchronous calls

As someone who is still learning the ins and outs of node.js, please bear with me. My goal is to cycle through an array of servers and assign a maximum of 60 tasks to each one. The number of incoming tasks can vary between 10 and 200. My intention is to a ...

Encountering a z-index problem while viewing videos in 768 resolution on Safari and IE8

Currently, I am encountering a z-index problem with videos in IE8 and Safari browsers. Click here to visit the link Even after reducing the z-index, the video on this page appears on top at 760 resolution. It does not seem to respond to any properties. F ...

CSS - Problem with image display and hover functionality

I am facing an issue with hover effect on an image. The hover works fine but the original image remains visible above the hovered image. I have attempted to use z-index to fix this problem without success. Below is the CSS code: #login, #logout { fl ...

full-page overlay is covering the entire screen

Is there a CSS-based solution to create an overlay that remains visible even when the page is scrolled down? I want to use this overlay behind a popup. Using JavaScript to set the height of the overlay based on the page's content is one option, but I& ...

Can you tell me the locations of the src/js and build/js directories?

Just starting out and seeking guidance. I am currently working with Node v4.2.1 and Gulp 3.9.0 on a Windows 7 machine, following along with a tutorial to familiarize myself with the task runner Gulp. I'm attempting to concatenate tasks but I seem to ...

Optimize your Kendo components in Angular with this top-notch customization strategy

How can kendo components like grids and charts be styled in the best possible way while following recommended practices? My current methods of styling them are: 1 : Utilizing ng deep, host, however these approaches have been deprecated and are not consi ...

The divs are intersecting each other

For some reason, when I try to add another section under the jumbotron it overlaps with the jumbotron. I have included my code below: http://www.bootply.com/IUd0GWEuAn ...

Tips for making a 2D grid on a webpage

Is there a way to implement a 10x10 grid on a webpage where users can click anywhere on the grid and have their (x, y) position recorded with one decimal place accuracy, covering values between 0.0-10.0 or 0.1-9.9? Appreciate any guidance! ...

JSON notation that spans multiple lines

Although there are many questions on this topic already, I am struggling to find the right solution for my specific case. Therefore, I have decided to move some user terms into a separate JSON file. These strings are quite lengthy. { "term&quo ...

Encountering an issue with a Vercel deployment of a Next.js project due to an unexpected token error: 'export'

Every time I attempt to compile the latest version of my Next.js project, it throws a build error with the following log. Interestingly, when I execute npm run dev and view the project on the local port, everything functions perfectly. Have any insights? ...

The ultimate guide to removing a targeted form input using jquery

My HTML form contains two text inputs: <form id="insert_amount",onsubmit="submitAmount();return false;"> **input(type="text",placeholder="Your message",name="message")** **input(type="text",placeholder="Your amount",name="amount") ...

Attempting to update the appearance of each item within an array by utilizing the ForEach() method

I am working on a function that dynamically creates new divs based on a specific condition. Once these divs are created, I store them in an array using the .push() method like so: function SnakeBody(){ BodySnake = document.createElement("div"); tabulei ...

The ng-route feature seems to be malfunctioning and I am unable to identify the error, as no information is being displayed in the console

Here is the code in my boot.php file where I have set up the links <ul class="nav nav-pills nav-stacked"> <li role="presentation"><a href="#/valley">Valley</a></li> <li role="presentation"><a href="#/beach"> ...