Tips for configuring multiple columns using angular 4 and bootstrap 4?

Situation:

I'm in the process of tackling a simple task:

<structure>
    <div class="row">
    <div class="col-3">
    ...
    </div>
    <div class="col-4">
    ...
    </div>
    <div class="col-5">
    ...
    </div>
</div>

Each column serves a distinct purpose. To elaborate further, the first column represents a vertical menu, the middle column houses a list of items, and the last column offers detailed information about a selected item from the second column. I am utilizing Angular4 and Bootstrap4 (alongside ng-bootstrap) for this project, despite being fairly new to both frameworks.

Problem:

The initial column functions as intended, displaying the menu with the correct dimensions. However, an issue arises when setting up the second column. Here is the resultant code:

<div class="container-fluid">
  <div class="row">
    <div id="sidebar" class="col-md-3">
      ...
    </div>

    <router-outlet></router-outlet>
    <list-of-things ng-version="4.0.3">
      <div class="col-md-3">
        ...
      </div>
    </list-of-things>
    ...
  </div>
</div>
The issue here is that the component selector
<list-of-things ng-version="4.0.3">
has a predefined width which currently dictates the size. Consequently, setting the width to col-md-3 results in it being proportional to the
<list-of-things ng-version="4.0.3">
instead of the overall page width. This leads to a narrow list display. If I adjust the inner div value to col-md-12, it fills the <list-of-things> box.

Additional Details: Below is the CSS stack concerning the <list-of-things> directly sourced from the web developer tool.

element {}

*,
*::before,
*::after {
  -webkit-box-sizing: inherit;
  box-sizing: inherit;
}

*,
*::after,
*::before {
  -webkit-box-sizing: inherit;
  box-sizing: inherit;
}

body {
  font-family: "Segoe UI", "Source Sans Pro", Calibri, Candara, Arial, sans-serif;
  font-size: 0.9375rem;
  font-weight: normal;
  line-height: 1.5;
  color: #373a3c;
}

body {
  font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  color: #292b2c;
}

html {
  font-family: sans-serif;
  line-height: 1.15;
  -webkit-text-size-adjust: 100%;
}

html {
  font-family: sans-serif;
  line-height: 1.15;
  -webkit-text-size-adjust: 100%;
}

Answer №1

I stumbled upon the solution through trial and error.

The key is to assign the class "col-md-3" to the <list-of-things> tag. The tricky part is that this tag is inserted by angular using the component selector definition. Unfortunately, the documentation on this selector is currently lacking.

In essence, all examples demonstrate setting the selector in this manner:

@Component({
  selector: 'my-posts',
  templateUrl: './../templates/posts.component.html',
  providers: [PostService]
})

It seems that enclosing the selector value in square brackets [ and ] will turn the tag into a <div> tag with whatever is inside the brackets.

For instance, the following code snippet:

  @Component({
      selector: '[id=my-posts]',
      templateUrl: './../templates/posts.component.html',
      providers: [PostService]
    })

will generate the following tag:

<div id="my-posts" ng-version...>InnerHTML Here </div>

I aimed to apply a css class to this div to specify the bootstrap col-md-3. However, I couldn't set my selector directly on a css class (as it caused a recursion error). It needed to be at least applied to a css id. After some experimenting, I discovered a workaround that achieved the desired result:

@Component({
  selector: '[id=all-posts][class=col-md-6]',
  templateUrl: './../templates/posts.component.html',
  providers: [PostService]
})

Result:

<div class="col-md-6" id="all-posts" ng-version="4.0.3">
...
</div>

Further information can be found in Can an Angular 2 component be used with an attribute selector?

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 use jQuery Animate to create a step-by-step animation with image sprites?

I'm working on creating an image sprite using jQuery and I'm curious if it's feasible to animate it in steps rather than a linear motion. I initially tried using CSS3 animations, but since IE9 is a requirement, the animations didn't wor ...

How can custom form validations be implemented with Angular's `useExisting`?

When looking at Angular's documentation on incorporating custom validators into template-driven forms — There is a straightforward example provided for implementing custom validation rules for an input field: required minlength="4" value shoul ...

Unable to build an optional Node.js dependency using the Angular compiler

Within my npm library, there exists a code snippet that appears as follows: let _Buffer: typeof Buffer; let _require: NodeRequire; let _readFile: (path: string, callback: (err: (NodeJS.ErrnoException | null), data: Buffer) => void) => void; try { ...

The visual effect of SVG feColorMatrix filter appears distinct from that of CSS filter (sepia)

After researching on , I discovered that SVG filters, specifically using feColorMatrix, can be used to create a sepia effect. Despite following the instructions, I encountered difficulty in reproducing the desired image effect and am seeking clarification ...

How to target CSS selectors to exclude any child elements that have a parent with a specific class at any level

Query I am attempting to devise a CSS selector that targets all children within a specified parent, excluding them if any element along the path has a specific class. Background In my JavaScript project, I am developing a materialization class that tran ...

Adding a transition effect to a div in CSS when switching from col-12 to col-9

I am facing an issue with the CSS provided below. It seems to only work when I close my div with the class "onclick-div". However, the transition effect is not visible when I click on the button to reduce the width of the div with the class "set-transiti ...

In JavaScript, you can update the class named "active" to become the active attribute for a link

My current menu uses superfish, but it lacks an active class to highlight the current page tab. To rectify this, I implemented the following JavaScript code. <script type="text/javascript"> var path = window.location.pathname.split('/'); p ...

The options are mat-checkbox with value (A) that is checked or value (D) that is checked

To confirm if the value you receive is an A and ensure that a D is not checked, you need to check the checkbox. <mat-checkbox formControlName="active" trueValue="A" falseValue="D">Activa</mat-checkbox> The parameters trueValue and falseValue ...

Use jQuery to smoothly navigate to a designated pixel position by scrolling down the page

Is it possible to use jQuery to scroll down a page to a specific pixel? I am currently working on a website with a fixed navigation bar that scrolls to an anchor point when a button is clicked, utilizing the jQuery smooth scroll plugin. The issue I am fa ...

What are some ways to incorporate the bootstrap-sweetalert library into an Angular 2 or 4 project?

Using the bootstrap-sweetalert library in my project has presented some challenges. To start, I followed these steps for installation: `bower install bootstrap-sweetalert --save` After installation, I needed to include the path in the angular-cli.json ...

Issues with organizing a Portfolio Gallery

Currently, I am in the process of creating a portfolio page and I am utilizing placeholder images until I have actual projects to showcase. I am encountering difficulties trying to structure one large image with two to four smaller images underneath it, al ...

What could be causing issues when trying to update the profile picture effectively?

I have encountered an issue where every time I update a user's profile picture, it reverts back to the default image whenever the page is refreshed. This consistent behavior suggests that the new profile picture may not be saving correctly in the data ...

Tips for aligning headings to the left of buttons

Currently working on a webpage but struggling with web design. Here is my HTML code: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link href="https://googledrive.com/host/0B0vEuOxa0lxIajBoRU1UWmdOQjQ/style.css" r ...

Convert HTML into Word documents while incorporating large image uploads using JavaScript

I am looking to generate a Word document (.doc) by exporting HTML to Word Document using JavaScript. While I have code that works well with small images, uploading big and multiple images poses a challenge. There is a function called "exportHTML" which gen ...

Unlocking the document instance in TypeScript: A comprehensive guide

Looking at the current project, there is a decision to rewrite it in Angular 6. One of the components in the project is a side navigation panel which is currently implemented with JavaScript code (found on some website). Since I'm not very proficient ...

Tips for vertically centering text within a textarea nested in a flexbox within a grid framework

Struggling to center text inside a textarea within a flexbox nested in a grid? Despite my efforts, I can't seem to crack it. Here's the Fiddle code snippet: // Attempting to Center Text const myDocumentAreaFiltersGlobalDisplay = document.getEl ...

Resolution for Reflected Diagonal Backdrop Design

Encountering a bug in Firefox with my mirrored diagonal background pattern. A vertical line appearing between left and right positioned elements at certain screen widths. Seeking a CSS solution or hack, no linked image files allowed. .stripes-background ...

Utilizing Conditional HTML/CSS for Enhanced Outlook Emails on Office 365

One interesting feature of Microsoft Outlook is its support for conditional CSS, allowing developers to create markup and styling that is specifically designed to render on Outlook. Despite the claims, I found that the following snippet, intended to be hid ...

The Bootstrap Nested List Group feature displays both items within the Tab Content section, providing clarity and

I am currently working on implementing a page navigation feature in HTML using the Bootstrap List-group class. Here is how the feature should function: Clicking on Home should display only link 1, and clicking further on Link 1 should show only Page 1. ...

The rendering of the list is taking an unexpectedly long time due to random factors

I have encountered a strange issue with one of my components. The component fetches a list of objects from a service in the ngOInit(). The problem I am facing seems to occur randomly, where sometimes it takes a considerable amount of time to display this l ...