HTML elements within the parent are seemingly enlarged compared to the parent element

I'm currently working on a project for an angular 2 recipe application, and I've encountered an issue with one of my HTML elements. The list items within the unordered list (which contain checkboxes) appear to be larger than the parent UL element. Please refer to the screenshot below.

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

Here is the relevant section of my HTML code:

<tr>
  <td>
      Ingredients
  </td>
  <td>
    <ul formControlName="ingredient_id" name="ingredient_id" class="form-control checkbox-grid" required>
      <li *ngFor="let ingredient of ingredients" value="{{ingredient.ingredient_id}}">
        <input type="checkbox" id="{{ingredient.ingredient_id}}" name="{{ingredient.ingredient_name}}" />
        <label for="{{ingredient.ingredient_name}}">{{ingredient.ingredient_name}}</label>
      </li>
    </ul>
  </td>
</tr>

And here is the corresponding CSS:

.checkbox-grid li { display: block; float: left; width: 25%;}
.checkbox-grid {
    overflow: hidden;
}

Answer №1

1) Have you attempted to assign a width to the parent ul element? 2) Since your li elements have the float property, ensure to use clear both at the conclusion.

Answer №2

Check out this CSS snippet for creating a checkbox grid:

.checkbox-grid { 
  overflow: hidden;
  margin:0px -10px;
  clear: both;
}
.checkbox-grid:before {
  content: ' ';
  display: table;
}
.checkbox-grid:after {
  clear: both;
}
.checkbox-grid li {
   display: block;
   float: left;
   width: 25%; 
   padding:0px 10px;
}
.checkbox-grid li:nth-child(5n){
  clear: left;
}

Answer №3

After some troubleshooting, I was able to figure it out. It turns out that Bootstrap css was conflicting with the height of the form-control class element. The original Bootstrap css code looked like this:

.form-control {
    height: 34px;
}

To resolve the issue, I made a change in my style.css file to override it:

.form-control.checkbox-grid {
    overflow:hidden ;
    height: auto;
}

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

How to automatically open JQuery Accordion panels when the page loads

My Accordion loads with the 1st panel open upon page load, but I am looking for a way to have the entire Accordion closed by default. Any help or suggestions on how to achieve this would be highly appreciated. Thank you for your assistance. FIDDLE http:// ...

Selenium struggles to locate elements within Iframes even when they are clearly visible

My current project involves developing code to automatically log into the Life is Feudal game website in order to gather specific information. This information is legally accessible manually, but it would be extremely time-consuming to collect everything w ...

CSS not working with fixed positioning

As part of a school project, I am required to utilize the position fixed property to correctly position the cookie statement at the bottom right of the screen. However, when I attempt to move the element, it does not seem to display properly. ...

Using jQuery to smoothly animate scrolling to the top of a

How can I create a "scroll to top" button at the bottom of my page that smoothly scrolls to the top? Despite using an "animate({scrollTop})" script, the scroll animation is not working and it jumps directly to the top. This is the script I am using: $(&a ...

Unable to view image stored as a blob

https://i.stack.imgur.com/8v90u.pngI have been studying these examples PHP display image BLOB from MySQL How to display an BLOB image stored in MySql database? They all demonstrate the same method of displaying images saved as blob. In my case, I ha ...

Absolute positioning causes an element's height to increase

As I delve into the realm of typographical animations and seek to calculate the baseline of a font at various sizes, I've stumbled upon a peculiar discovery: It appears that the height values of elements tend to increase in an erratic manner when thei ...

Tips for ensuring that the elements within the flexbox are centered and aligned to the left

New proposed layout I need assistance with centering all flexbox items in a 3-column layout. Additionally, I want the items in rows that are not full to be centered and aligned to the left. Any suggestions for achieving this? Below is my current code, bu ...

Tips for safeguarding user input data in the event of a Jeditable ajax post failure

Seeking a solution with Jeditable for retaining textarea data and keeping the form visible in case of failed ajax post due to issues like network problem or server error. Is there a way to achieve this with Jeditable? Thanks! ...

Activate the console.log functionality if it has been previously turned off

When working on a project, I noticed that console.log is disabled. Although Firefox alerts me about this, I don't have the time to locate where in the code it's disabled. Is there a method for overriding the disabling of console.log specifically ...

Tips for modifying style.display using JavaScript

On my website, the menu is structured like this: <nav id="menu"> <label for="tm" id="toggle-menu">Menu <span class="drop-icon">▾</span></label> <input type="checkbo ...

Adjusting the size of an image based on the size of the window

I'm currently working on my first website project. I have successfully implemented a large image banner, however, I am facing an issue with setting its height. Whenever I try to adjust the height using percentage values, the banner disappears. My goal ...

What is the best way to eliminate excess space on the right side of a div element

I recently utilized a column structure with bootstrap 4, resulting in a layout with 1 row containing 2 columns: <div class="left"> <hr class="container hline"> <div id="main" class="container border"> <di ...

Switching Out Bootstrap Dropdown with Dropup (Varying functionality on two almost identical implementations)

In the midst of my project on Github Pages, I encountered an interesting issue involving replacing a bootstrap .dropdown with .dropup when the div's overflow-y: scroll causes the dropdown menu to be cut off or overflow. The functionality can be viewed ...

Is it possible to integrate a Bluetooth button with a button on my website?

I've been experimenting with my web application (using HTML and JavaScript) to create a process where a click on my Bluetooth device can simulate a button click on the page. Do you think this is achievable? Appreciate any help in advance. ...

Customize the fieldset style in Bootstrap 5

In earlier versions of Bootstrap (or with plain CSS), the following HTML code used to result in a fieldset with a visible border, where the legend sat on top: <fieldset> <legend>Test</legend> Welcome! </fieldset> Here is how ...

Modify the content of the div upon clicking the link or button

Currently, I am working on a website that consists of a content div with the id "content" and a sidebar div with the id "sidebar". My goal is to dynamically update the content within the content div whenever a link or button in the sidebar is clicked, all ...

Is it possible to have 1 million links on a single webpage?

Would the performance suffer if I were to fetch 1 million link elements and add them to the DOM? I am looking to create a navigation list at the top of my website, similar to what Apple has on their site where you can scroll left or right using your keybo ...

What is the best way to style this specific HTML code using CSS?

Currently, I am facing an issue where two sets of text that are supposed to be inline with each other are not aligned properly. One of the texts is placed higher than the other even though they share the same CSS code. I want to be able to edit only one se ...

Utilizing Bootstrap 5's table design to occupy the rest of the available vertical

In my .NET Core 7 MVC project, I am facing a challenge where I want to make a details table scroll and occupy the available vertical space on the screen dynamically. I have tried using h-25, h-50 classes to achieve the scrolling effect on the table. Howev ...

The Angular Tooltip feature is unable to interpret the characters "' '" or "' '"

Let me explain the scenario: I am receiving a list of objects from my back-end service, which I then break apart using ngFor and display accordingly. Each item in the list has an associated toolTip that provides additional information. The info for each i ...