What is preventing me from setting the height of the buttons to be the same as their width?

My website needs a panel on the left side of the screen that contains square buttons, each button representing a different action. However, currently these buttons are stretching horizontally when they should be stretched vertically to match my UI design:

Click here to see my UI design.

I've tried setting min-width: 100%; height: auto to make the buttons vertical, but it didn't work. I also attempted to use jQuery to equalize their dimensions, but still no luck.

Here is a snippet of my code:

#left_panel {
  float: left;
  width: 25%;
  text-align: center;
}

.btn {
  border-radius: 25px;
  padding: 1%;
  margin: 1%;
  background-color: green;
}

.item {
  border-radius: 10px;
  float: right;
  width: 71%;
  padding: 1%;
  margin: 1%;
  background-color: grey;
}

checkbox {
  display: inline-block;
  width: auto;
}

.name {
  display: inline-block;
  background-color: white;
  width: auto;
}

.del {
  border-radius: 25px;
  display: inline-block;
  float: right;
  background-color: red;
  width: auto;
}
<div id="left_panel">
  <div class="btn" id="open">Open</div>
  <div class="btn" id="add">Add</div>
  <div class="btn" id="info">Info</div>
</div>
<div id="list">
  <!--space for list-->
</div>

Answer №1

To create square elements, utilize the padding-bottom: 100% method.

#left_panel {
  float: left;
  width: 25%;
  text-align: center;
}

.btn {
  border-radius: 25px;
  padding: 1%;
  margin: 1%;
  background-color: green;
  position: relative;
}
.btn span {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.btn::after {
  content: '';
  display: block;
  padding-bottom: 100%;
}

.item {
  border-radius: 10px;
  float: right;
  width: 71%;
  padding: 1%;
  margin: 1%;
  background-color: grey;
}

checkbox {
  display: inline-block;
  width: auto;
}

.name {
  display: inline-block;
  background-color: white;
  width: auto;
}

.del {
  border-radius: 25px;
  display: inline-block;
  float: right;
  background-color: red;
  width: auto;
}
<div id="left_panel">
  <div class="btn" id="open"><span>Open</span></div>
  <div class="btn" id="add"><span>Add</span></div>
  <div class="btn" id="info"><span>Info</span></div>
</div>
<div id="list">
  <!--space for list-->
</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

Changing text color with JQuery animation

Is there a way to animate text color using jQuery/jQuery UI? I want the text color to change from #000 to #F00 when an event is triggered, then fade back to #000 over 3 seconds. I attempted using effect("highlight", {}, 3000) with the highlight effect, bu ...

Showing off the latest products at the top of the list

Typically, when utilizing ngFor, the most recent item is displayed underneath the initial element. For instance, a list containing: [Apple, Orange, Banana] If we use ngFor to display this list: Apple Orange Banana I am interested in learning a method t ...

The functionality of the Bootstrap dropdown or radio input type is not functioning correctly

I'm currently utilizing electron([email protected]) along with bootstrap([email protected]). Whenever I attempt to incorporate a dropdown or other components from Bootstrap, they simply do not function. I am unsure of what mistake I might ha ...

Guide to implementing and utilizing global CSS variables within JSS

Apologies for the lack of clarity in my initial question. I am currently working on a web project using reactjs and utilizing jss for UI style. In my design, I am limited to only 4 colors, with certain elements across multiple components sharing the same s ...

"Implement a smooth scrolling animation on the page to automatically move a div element upward and lock

I am attempting to create a unique animation for a header div that involves moving it to the top of the screen when the user scrolls down. Once the header div reaches the top, I want it to stay fixed in that position. As the header div moves upwards, it wi ...

Creating a CSS rule that specifically targets a particular div id on a webpage can be accomplished by using the selector syntax to select

Is there a way to conditionally apply a @media print css ruleset only when a specific div is present on the page? For example, I have the following css to assist in printing #mytargetdiv: @media print { .inside-article > :not(#mytargetdiv), .inside ...

Issue with duplicate selectors not being merged in SASS partials

Is there a way for SASS to combine duplicate CSS selectors from multiple files into a single output file? In my current setup, I have the same CSS selector present in separate SASS partials files that are all included in a master file. For example: File1 ...

Tips for implementing resizable Material-UI Dialogs

I'm working on a project that involves creating a dialog box that can be resized and dragged. While I found steps in the Material-UI Dialog documentation on how to make it draggable, I'm still looking for information on how to make it resizable. ...

When the value is inputted into the textbox and the enter key is pressed, a fresh chip displaying the entered value will materialize

Whenever I click on a textbox, a menu opens that requires me to enter a value in the textbox. After entering the value and hitting enter, a new chip with the entered value should appear. I tried creating an Onchange event to pass the values to the chip com ...

What's causing this issue in Internet Explorer?

I recently created a new website at Unfortunately, I'm facing an issue with Internet Explorer. Despite trying various workarounds, I can't seem to pinpoint the CSS error causing the bug. Why am I struggling to fix this? 1- I predominantly use ...

How can I transform a mat-list into a dropdown menu in Angular?

I recently used Angular to create a list using mat-list. Here is the code I implemented: <mat-list style="display: inline-grid;"> <mat-list-item *ngFor="let item of item"> <mat-checkbox [(ngModel)] ...

Adding padding to the top causes the scrollbar to hide at the bottom in Firefox

My HTML page includes the following configured DIV: <div id="contentDiv" style="padding-top: 20px; padding-left: 20px; overflow: auto; height: 100%;" > The content within this DIV is large enough to require a vertical scrollbar. When viewed in IE, ...

JavaScript code that triggers a function when the mouse is moved over a description box on a

As a beginner in the field of Computer Science, I recently embarked on a project to create a website for sharing science articles with students. The goal is to spark curiosity and interest in science through this platform. One key feature I wanted to inclu ...

Creating interactive forms (the optimal method)

My project involves creating an Android Tablet application that will connect to a web service to retrieve dynamic forms which can be filled offline and then submitted when online. These forms are not predefined, and may contain attached images. However, I ...

extract all elements from an array nested within another array

I am having difficulty extracting data from an array file in PHP. I was able to read it and convert it into a PHP array, but now I want to display the stored information in a table, however, I keep getting incorrect values. How can I retrieve the informat ...

Adjusting the size of a division element to match the dimensions

Currently, I am still in the process of finalizing the remainder of the page, but I have encountered a minor issue. The problem lies in my image div not matching the height of the container. Although the image itself is the correct size, the image div appe ...

Learn how to showcase a text file uploaded to a webpage with NODE js and HTML

<!DOCTYPE html> <html> <body> <form action = "/submit" method = "post"> Select a file: <input type="file" name="file"> <input type="submit"> </form> </bod ...

Deactivate Date Field for Editing Orders in WooCommerce

Is there a way to deactivate the Date Created textbox on the Edit Orders page of Woocommerce? I attempted to use pointer-events: none; but unfortunately, it did not have any effect. I am seeking a method to disable the Date Created field. https://i.sstat ...

Struggling to align block elements correctly after changing them to inline

I've been trying to align this paragraph while keeping the navigation menu and logo in their correct positions. I attempted to make everything inline, but that didn't work. Then I experimented with the float property, which only made things worse ...

Data entry and a dropdown menu

Looking to add a dynamic numeric input that changes based on a select box choice. The numeric input will have a specific range based on the selected option from the select box. For instance: If option2 is selected, the numeric input range will be from 2 ...