When the screen size decreases, the button overflows from its containing div

I'm currently working on creating a to-do list with an edit button that matches the height of the div on normal or larger screens. However, when the screen size is reduced to less than 500px, the button collapses and extends beyond its div. Here's how my list appears on medium and larger screens: https://i.sstatic.net/T6wRq.png

But, when I resize the window to below 400 or 500px, it ends up looking like this:

https://i.sstatic.net/v5Jmt.png

Here's the JSX code for my React component:

export default function TodoList(props) {
     const list = props.todos.map(todo =>
          <div className="TodoList">
               <h3 >{todo.todo}</h3>
               <div className="btn">
               <button>edit</button>
               </div>
               
          </div>
          
     )
     return (
          <div>
               {list}
          </div>
     )
}

And here's what my CSS looks like:

.TodoList{
     background: #283048;  
     background: -webkit-linear-gradient(to right, #859398, #283048); 
     background: linear-gradient(to right, #859398, #283048); 
     padding: 2px;
     margin: 10px;     
     display: block;
     width: 50%;
     margin-left: auto;
     margin-right: auto;
     color: snow;
     transform: skew(20deg);
     height: 3rem;
     
}

.TodoList h3{
     transform: skew(-20deg);
     letter-spacing: 2px;
     display: inline-block;
}

.btn{
     float: right;
     height: 100%;
}

.btn button{
     height: 100%
}

Answer №1

Unfortunately, I was using my mobile while leaving comments, so creating a code snippet would have been awkward.

Instead, here is an example showcasing the usage of FlexBox which not only simplifies the markup but also handles layouts effectively. This eliminates the need for setting height to 100% or adding extra wrapper divs.

.TodoList{
     background: #283048;  
     background: -webkit-linear-gradient(to right, #859398, #283048);  
     background: linear-gradient(to right, #859398, #283048); 
     padding: 2px;
     margin: 10px;     
     display: flex;
     margin-left: auto;
     margin-right: auto;
     color: snow;
     transform: skew(20deg);
     text-align: center;
}

.TodoList h3{
     transform: skew(-20deg);
     letter-spacing: 2px;
     display: inline-block;
}

.TodoList {
     width: 50%;
}
<div class="TodoList">
     <h3 >Make Coffee</h3>
     <button>edit</button>
</div>
<div class="TodoList">
     <h3 >Make Tea</h3>
     <button>edit</button>
</div>
<div class="TodoList">
     <h3 >Make Orange Juice</h3>
     <button>edit</button>
</div>

Answer №2

It seems like the issue lies within your CSS code. When the screen size decreases, there is not enough space for the todo list and button with a skew of 20 degrees. By removing the width: 50%; property and instead using text-align: center;, you can achieve the desired outcome.

.TodoList{
     background: #283048;  /* fallback for old browsers */
     background: -webkit-linear-gradient(to right, #859398, #283048);  /* Chrome 10-25, Safari 5.1-6 */
     background: linear-gradient(to right, #859398, #283048); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
     padding: 2px;
     margin: 10px;     
     display: block;
     margin-left: auto;
     margin-right: auto;
     color: snow;
     transform: skew(20deg);
     height: 3rem;
     text-align: center;
}

.TodoList h3{
     transform: skew(-20deg);
     letter-spacing: 2px;
     display: inline-block;
}

.btn{
     float: right;
     height: 100%;
}

.btn button{
     height: 100%
}
@media only screen and (min-width: 600px) {
  .TodoList {
    width: 50%;
  }
}
<div class="TodoList">
     <h3 >Make Coffee</h3>
     <div class="btn">
     <button>edit</button>
     </div>
</div>
<div class="TodoList">
     <h3 >Make Tea</h3>
     <div class="btn">
     <button>edit</button>
     </div>
</div>
<div class="TodoList">
     <h3 >Make Orange Juice</h3>
     <div class="btn">
     <button>edit</button>
     </div>
</div>

Answer №3

After some tweaking, I have come up with a more efficient solution. My button now adjusts its height based on the size of its containing div, and the div's height dynamically changes to fit its content. I updated the .btn class by adding a position property that synchronizes the button's height with the div's.

.btn{
     float: right;
     position:absolute;
     top: 0;
     bottom: 0;
     right: 0;
}

I also included a margin to prevent text from being hidden below the button.

.TodoList h3{
     transform: skew(-20deg);
     letter-spacing: 2px;
     display: inline-block;
     /* Added margin to ensure text does not get obscured by the edit button */
     margin: 5px 25px;
}

Furthermore, I implemented a media query:

@media only screen and (min-width: 500px) {
     .TodoList {
       width: 50%;
     }
}

You can see the updated look here: https://i.sstatic.net/dSio9.png

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

Can you show me how to extract the html code from a website using python's requests module?

Attempting to retrieve an HTML file from the specified website: Inspecting the source in Google Chrome allows me to obtain the HTML without any difficulty. However, I aim to download multiple pages using Python requests. Unfortunately, when attempting to ...

Steps for creating a sleek vertical slider with transitional effects using JavaScript and HTML

Take a look at my code snippet: <table> <tr> <td onclick="shownav()">Equations of Circle <div id="myDownnav" class="sidenav"> <a>General Info</a> <a>In Pola ...

Single-page application powered by WordPress and universal JavaScript

Can a WordPress single-page application be created using isomorphic/universal JavaScript approaches (utilizing frameworks like React and Angular2)? ...

Show ng-message when email is invalid in Angular Material without using ng-pattern

I need to show an error message that says Please enter valid email. when an invalid email is entered, but I cannot use the ng-pattern attribute with this specific regex pattern. <md-input-container class="md-block" flex-gt-xs> <label>Ema ...

Is it feasible to send a GET form to two separate views using two buttons?

On one view, I have a form that functions perfectly. http://myurl.com/myapp/filter_objects/?risk__worktask=1&craft=3 In another view, I need to export the filtered list to a PDF. Currently, I store the results in session and access the list from ther ...

The useEffect hook is not executing every time I navigate back and forth to the screen. What could be causing this issue and

import { useRoute, useIsFocused, useFocusEffect } from '@react-navigation/native' import React, { useEffect, useState } from 'react'; import { ScrollView , Text, View, SafeAreaView, StyleSheet, StatusBar, TouchableOpacity, BackHandler} ...

Await is not supported by Stripe and Next.js

Looking to implement a checkout form with Stripe using their API and Next.js? Check out the documentation here const stripe = require('stripe')(''); const session = await stripe.checkout.sessions.create({ success_url: 'https ...

Transmit information using jQuery to an MVC controller

I am developing an ASP.NET MVC3 application and need to send three pieces of data to a specific action when the user clicks on an anchor tag: <a onclick='sendData(<#= Data1,Data2,Data3 #>)'></a> Here is the javascript function ...

What is the method to effectively conduct a testing procedure for JavaScript files that have been exported using

I have a JavaScript file called "sum.js" which contains a simple function: // sum.js function sum(a, b) { return a + b; } export default { sum }; Now I want to write a test for this file using Jest. Here is my "sum.test.js" file in the same folder: // ...

What is the best way to access an excel file using JavaScript and Protractor?

Is it possible to read an Excel file dynamically in JavaScript and iterate through cell values using row and column counts, without converting it into a JSON object? I have searched through several posts on Stack Overflow but have not found a solution yet. ...

Retrieving input data from FormSubmit command

I have implemented Formsubmit to manage forms on my websites, but I do not want users to be redirected to another page when submitting the form. My website is hosted on Netlify and when I tested the forms, I did not receive the information in my email. I a ...

Polymer form failing to submit via AJAX in Firefox

My Form: <form is="iron-form" action="{{url('/user/store')}}" id="registerForm" method="POST"> <input type="hidden" name="_token" value="{{csrf_token()}}"> <paper-input name="email" label="E-mail" type="email"></pape ...

Use the given URL to set the background image

Having trouble setting a background image for an <a> tag. The image link is set in the background-image:url property, but the image isn't showing up as the background. Here's my code, what could be the issue? <a href="#" data-to ...

Executing Jest on every file within the imported Tree

Recently, I encountered a curious side effect and would appreciate the input of experienced members here. When executing the command npm run test -- --testPathPattern="filePath" --coverage, I receive coverage information like this - Statemen ...

What is the process for activating the Placeholder feature in a Floating Input Field in a React application

Having trouble changing the placeholder value in a Bootstrap-based floating input. I want to display default text as a placeholder and allow users to edit it. Any suggestions? Check out this example on CodeSandbox <div class="form-floating mb-3&qu ...

Utilizing conditional statements within the array.forEach method to select specific sub-objects within an array of objects

Need help troubleshooting an if statement inside a function that is called by a forEach array loop. My array contains objects, with each object structured like this: arrofobj = [ {"thing_id":"1a", "val": 1, "Type": "Switch","ValType":{"0":"Open","1":" ...

CSS an act of misbehavior

I have noticed some unusual behavior on my website page. My website design can be viewed at Also, here is the same design in CMS format Please pay attention to the section under <div class="godelpage"> <a href="http://ryugaku.babonmultimedia ...

Disappear text gradually while scrolling horizontally

There is a need to create a special block that displays fading text on horizontal scroll. However, the problem is that the block is situated on a non-uniform background, making the usual solution of adding a linear gradient on the sides unsuitable. Click ...

Using jQuery to obtain the object context while inside a callback function

Suppose I have the following object defined: var myObj = function(){ this.hello = "Hello,"; } myObj.prototype.sayHello = function(){ var persons = {"Jim", "Joe", "Doe","John"}; $.each(persons, function(i, person){ console.log(this.h ...

Ensure the configuration is stored in a safe location where files cannot be accessed through external links

Currently, I am attempting to utilize a configuration file for both a database and rating script. However, the dilemma lies in the fact that the config file is located in this directory: website.com/include/config.php also known as websitename/include/co ...