Splitting the div into two columns

I've encountered various solutions to this issue, but when I integrate an Angular2 component inside the divs, it fails to function properly.

Here is my progress so far: https://i.stack.imgur.com/qJ8a9.jpg

Code:

<div id="container">
  <div id="categoriesContainer">
    <categories (onCategoryChanged)="categoryChanged($event)"></categories>
  </div>
  <div id="products-container">
    <product-details *ngFor="let product of products$ | async" id="prodcut"
                     [product]="product"
                     [canAddProductToCart]="canAddToCart(product.$key) | async"
                     (onAddToCart)="addToCart($event)"></product-details>
    <button md-button
            *ngIf="!showCreateProductComponent"
            id="create-product-button"
            [disabled]="disableCreateProductButton$ |async"
            (click)="showCreateProductComponent=true">
      <i class="material-icons">add</i>
    </button>
    <create-product id="create-product"
                    (onCencel)="showCreateProductComponent=false"
                    (onCreateProduct)="onCreateProduct($event)"
                    *ngIf="showCreateProductComponent"></create-product>
  </div>
  <div style="clear: both"></div>
</div>

css:

//splitting the div into 2 columns
#container
{
  border-style: solid;
  border-width: 1px;
  border-color: green;
  padding: 10px;
  margin: 10px
}
#categoriesContainer
{
  width: 15%;
  border-style: solid;
  border-width: 1px;
  border-color: blue;
  float: left;
}
#products-container
{
  border-style: solid;
  border-width: 1px;
  width: 85%;
  border-color: red;
}

//styling for angular2 components
#prodcut
{
  float: left;
  margin-right: 10px;
  margin-bottom: 10px;
}
#create-product
{
  float: left;
  margin-right: 10px;
  margin-bottom: 10px;
}
#create-product-button
{
  float: left;
  margin-right: 10px;
  margin-bottom: 10px;
}

My Desired Layout: (the cards will only be in the red square.)

https://i.stack.imgur.com/mI7Mn.jpg

Questions:

  1. How can I resolve this issue and why does it work fine when I replace the Angular2 components with simple HTML text?
  2. Can I simplify this code without impacting anything:

    <div id="categoriesContainer"
       style="width: 15%;border-style: solid;border-width: 1px;border-color: blue;float: left">
    <categories (onCategoryChanged)="categoryChanged($event)"></categories>
    

To:

<categories id="categoriesContainer"
               style="width: 15%;border-style: solid;border-width: 1px;border-color: blue;float: left"
 (onCategoryChanged)="categoryChanged($event)"></categories>

Thank you!

Answer №1

Easy Way to Style with flexbox

*{box-sizing:border-box;}

#wrapper {
  display: flex;
}

#left, #right {
  padding: 16px;
}

#left {
  width: 15%;
  background: red;
}

#right {
  width: 85%;
  background: blue;
}
<div id="wrapper">
  <div id="left">left</div>
  <div id="right">right</div>
</div>

Simplified Layout using floats and box-sizing

You may also consider adding a .clearfix class to the parent element for this approach

*{box-sizing:border-box;}

#left, #right {
  float: left;
  padding: 16px;
}

#left {
  width: 15%;
  background: red;
}

#right {
  width: 85%;
  background: blue;
}
<div id="wrapper">
  <div id="left">left</div>
  <div id="right">right</div>
</div>

Clean Layout using display:table (cross-browser compatible)

#wrapper {
  display: table;
  width: 100%;
  border-collapse: collapse;
} 

#left, #right {
  display: table-cell;
  padding: 16px;
}

#left {
  width: 15%;
  background: red;
}

#right {
  background: blue;
}
<div id="wrapper">
  <div id="left">left</div>
  <div id="right">right</div>
</div>

Answer №2

Have you experimented with using float:left for child nodes and clear:both, content: '' for the parent node?

What I'm suggesting is that you may be missing a float:left declaration for the #products-container

<div class="container clearfix"> 
  <div id="categoriesContainer" style="float:left" ></div>
  <div id="products-container" style="float:left" ></div>
</div>

If you need more information on the clearfix class, you can find it in Bootstrap here.

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

Expanding image size with CSS

Looking for assistance to fix the squished image in HTML & CSS. I used the CSS code provided by Figma to style the image in html, but it resulted in a different aspect ratio from the original picture, causing the image to appear squished. Any help is appr ...

Using AngularJs, you can access the document.body.onfocus event within the controller of

I am attempting to detect when the user closes or cancels the File Upload Window <input type="file"> Since there isn't a built-in listener for the close event of the file upload, I am trying to capture it using the document.body.focus event, s ...

What is the best way to bind a click handler or any event handler to my object or module?

Can someone help me with attaching event handlers to my module in a way that I am not sure how to achieve? Here is the snippet of my module: var globalModule = { name:'Banana on princess bed', init:function(){ alert('Init ...

Is there a jQuery function that can produce repeated output and append content with each successive click?

Attempting to implement a dynamic searchbar with various parameters has led me to explore using jQuery to load and clone the searchbar file in order to append it to the body dynamically. I have made several attempts to modify selectors without achieving t ...

When multiple checkboxes are selected, corresponding form fields should dynamically appear based on the checkboxes selected. I attempted to achieve this functionality using the select option method

Require checkboxes instead of a selection option and have multiple checkbox options. Depending on the checked checkboxes, different form fields should appear. A submit button is needed. I have included some CSS code, but a more detailed CSS code is requir ...

Add two columns for mobile devices in the Woocommerce platform

How can I display 2 columns of products in my Woocommerce shop using a child theme based on 'Shopisle'? Is a CSS-only solution the best approach for this task, and will it work smoothly without any bugs? I suspect that the theme is built on Boot ...

Tips for positioning slideshow below header in web design

I am currently working on enhancing the slideshow feature on my website. If you take a look at the image link provided below, you'll notice that the alignment of the slideshow is slightly off on both sides. Despite my attempts to adjust the CSS width ...

Tips for turning on a gaming controller before using it

Current Situation In my ionic side menu app, I have a main controller called 'main view'. Each tab in the app has its own controller, which is a child of the main controller. The issue I'm facing is that when I start the app, the first cont ...

Typography Addition on Flexslider

I am currently working with flexslider and trying to incorporate a unique text overlay on each individual slide, but so far I have been unsuccessful. <div class="flexslider"> <ul class="slides"> <li> <img src ...

Creating dynamic templates for table rows in AngularJS directives

Is it possible to dynamically load an AngularJS Directive templateUrl while working within a table? In my scenario, I have the following HTML structure where I am repeating a tr element with a fw-rule directive: <tbody> <tr ng-repeat="rule in ...

I'm curious to know why my jQuery function fadeOut is functioning properly while slice isn't working as expected

I'm trying to create a button that displays three consecutive posts After clicking on "view all", the three "div" elements should become visible I'm attempting to use jQuery to make the three 'div' elements appear when the view all bu ...

Adding data from one object to another in Javascript results in duplicated entries

Despite my efforts to find a solution for my issue, I couldn't locate a relevant topic. Being new to Javascript, I suspect my lack of understanding is hindering me from resolving the problem. After days of trying, I'm still unable to grasp it. An ...

Loading an Ionic module lazily within a children array is a smart way to

Within my Ionic application, I have structured a List Page Module and a Subdir Page Module nested under the main Page module. The folder structure looks like this ---> list/subdir. https://i.sstatic.net/XGrnU.png Dilemma: Whenever I navigate to localh ...

Making an Axios request with parameters

I am facing an issue where my parameter articleid is not being passed to the route /createAnswer. When I log articleData._id, it shows the correct ID (e.g., 60b4f5d8c8be1d4cb0cdd6ca) that I want to pass to the route /createAnswer. const createAnswer = () = ...

Using GSAP to create a staggered animation with a negative delay

Seeking a Solution: I am curious if there is a method to incorporate a negative delay into the staggerFrom / staggerTo functions within greensock? Issue at Hand: The current animation I have in place is extending longer than desired. It would be benefic ...

Importing an object into Three.js from Blender using JSON_KEYBOARD_SHORTCUT

I'm currently utilizing the Blender plugin to export JSON files, but I've encountered an issue where the texture of my object is not being exported. The materials section within the JSON file appears as follows: "materials" : [ { "DbgCo ...

What is Flask's approach to managing JSON data?

I am currently developing an editable table using FLASK, JSON, and jQuery. After serializing the form, I send it via $.getJSON, as shown at the bottom of my JS code: This is the JS code: $(function(){ $('tbody').on('click', &apos ...

difficulty associated with using a package I uploaded to npm

I am encountering issues with importing a package that I have published on npm. after executing npm install binaryconversor I have experimented with various ways of incorporating it. let conversor = require('binaryconversor'); let conversor = ...

Guide on implementing asyncWithLDProvider from Launch Darkly in your Next.js application

Launch Darkly provides an example (https://github.com/launchdarkly/react-client-sdk/blob/main/examples/async-provider/src/client/index.js) showcasing how to use asyncWithLDProvider in a React project (as shown below). However, I'm struggling to integr ...

Retrieve an element from an array using the POST method

I am currently working on implementing a POST method using mongo/mongoose: Department .create({ name: req.body.name, link: req.body.link, state: req.body.state, requirements: req.body.requirements, salary: req.b ...