Angular-Components Enhanced with Flexbox Styling

Currently in my angular project, I have a basic header, main, footer structure and I want to transform the main-component into a flex-box so that all components are arranged horizontally with equal width. Moreover, I aim to switch the flex-direction to column when the screen width is less than 700px. I was able to accomplish this using pure HTML + CSS (check out the jsfiddle: http://jsfiddle.net/aJPw7/443/) which leads me to believe that it involves angular parent components.

Expected behavior: Both <app-content-section> elements should have 50% width of <app-main-component> and 100% height. Once the flex-direction changes to column, they should have 100% width and 50% height:

Current behavior: The <app-content-section> elements align as desired with "justify-content" but don't respond to any specified height or width attributes.

Style.css

html, body {
    height: 100%;
    width: 100%;
    padding: 0;
    margin: 0;
}

app-root HTML:

<app-main-component>
    <app-content-section></app-content-section>
    <app-content-section></app-content-section>
</app-main-component>

app-main-component HTML:

<div class="main-component"> 
    <ng-content></ng-content>
</div>

app-main-component CSS:

.main-component {
    display: flex;
    flex-direction: row;
    height: 100%;
}

@media screen and (max-width: 700px) {
    .main-component {
        flex-direction: column;
    }
}

app-content-section HTML:

<div class="content-section">
    <a>Test</a>
</div>

app-content-section CSS:

.content-section {
    width: 100%;
    height: 100%;
}

Edit1: I also tried :host{ } but still no luck.

Edit2: I created another jsfiddle where I achieved the correct width by styling the host-element and adding flex: 1, yet the elements still do not utilize the entire height. https://jsfiddle.net/1c15q243/19/

Answer №1

To ensure proper flex-sizing for the hosting-component <app-content-section>, it is essential to include :host{ flex: 1; } in the "app-content-section CSS".

This solution became clear during my second edit on the fiddle, with @karthikaruna pointing out that I had overlooked adding an HTML tag in the styling file.

Answer №2

Apply a 100% height to the html element. Click here to view the revised fiddle.

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

Navigating through DOM object in jQuery - A Step by Step Guide

I'm facing a challenge with my HTML code. How can I navigate to the <br> tag using jQuery? Constraints: Avoid using class attributes. Do not utilize the split method. For instance: <html> <body> <div> <div> hello ...

Display items in a not predetermined order

Despite its simplicity, I am struggling to get this working. My aim is to create a quiz program using JavaScript. Here is the basic structure: <ul> <li>option1</li> <li>option2</li> <li>option3</li> </ul> &l ...

What is the best way to halt the ticking of this clock in JavaScript?

I can't seem to figure out how to stop this clock using JavaScript Even though I press the stop button, the clock keeps running <!DOCTYPE html> <html> <head> <h1> Welcome to the clock. Press the stop button to halt the clo ...

Developing an HTML table with the power of JavaScript and JSON

I am having difficulty creating an HTML table using JavaScript with JSON input. In my code, I'm using a placeholder in the HTML that will be filled by a innerHTML call in Javascript: for (var i = 0; i < json.data.length; i++) { listItem = json. ...

Attach the div element firmly to the bottom of the webpage

I'm trying to place a second div under one with position absolute, but the two divs have different widths. The top div is centered and positioned absolutely, while the bottom div should span 100% of the width. Any suggestions on how to achieve this? ...

Sharing data between sibling components in Angular 5 for simultaneous use

I am currently working on an Angular application where I have two sibling components that need to access the same data. One component is a navigation bar listing all the sites, while the other is within the router outlet displaying the sites and graphs. To ...

Div with headers that stick to the top and stack when scrolling

I am working on creating a lengthy scrollable list of grouped items where the group titles remain visible at all times (stacked). When a user clicks on a group header, the page should scroll to the corresponding items. I have successfully used the positio ...

Transfer websites to subfolders without altering the base URL

Previously, I had two staging/test servers each hosting an angular application on nginx, referred to as app1 and app2. The setup was straightforward: http://<ip for app1 server>/ => app1 http://<ip for app2 server>/ => app2 Now, my g ...

Using jQuery in Rails 3 to display the id of a td element

I am working with a 3x3 table that contains td elements with unique id's (id='a1'...id='c3'). I want to enable the user to click on any of these 9 td elements and receive an alert displaying the id of the clicked td. Below is my C ...

The Unit Test for Angular NgRx is not passing as expected

I'm facing difficulties with my unit tests failing. How can I verify that my asynchronous condition is met after a store dispatch? There are 3 specific checks I want to perform: 1/ Ensure that my component is truthy after the dispatch (when the cond ...

The radio input is not being properly checked using ng-checked in Angular

The ng-checked attribute is causing issues in the application, specifically with radio buttons. It seems to be working fine for checkboxes but not for radio buttons. <input type="radio" class="radio" name="job_class_radio" ng-checked="key===jobClassDat ...

React ignores CSS rule

I am currently utilizing React to design some buttons and using CSS to style them accordingly. One of the classes I have created is called Button: export default class Button extends React.Component{ public className: string; constructor(props){ ...

Transitioning from a Mobile-first design to a Desktop layout: Tips and tricks

I am seeking a way to transition image 1 from mobile view to desktop view seamlessly. Currently, I have a div set up for image 1 in the mobile layout and now I need to rearrange the order of the items. Would using Bootstrap be the most efficient solution f ...

Arranging elements in HTML for Manipulating with JavaScript

I haven't started coding yet, but I'm contemplating the overall strategy. My front end is primarily composed of HTML tables, giving it an Excel-like appearance. I am considering generating default pages and then using JavaScript to dynamically m ...

Invalid input: The provided string is not recognized as a valid number

Currently, I am developing a website with Angular that is linked to an ASP.Net backend for database access. The error I am encountering pertains to a custom Async Validator integrated into a Form Control. This validator serves the purpose of verifying if a ...

Incorporating SQLSRV results into clickable <td> elements: A dynamic approach

As a newcomer to the world of JS/PHP/web development, I'm seeking help with a seemingly simple task. My goal is to make each <td> element in a table clickable, and retrieve the text contained within the clicked <td>. Currently, I have a S ...

The Node.contains() function in JavaScript does not verify the presence of inner child elements

I have developed a custom DatePicker component for my React app and I am facing an issue with hiding it on outside click, similar to how I handled other components like Select Dropdown. To address this problem, I created a custom hook: export default (ref, ...

Challenges with line height in IE when adjusting font size in textarea

I'm facing an issue with adjusting the font size in a textarea using JavaScript. While it works perfectly in Firefox, there are some problems in IE. Specifically, the line-height does not change accordingly. This results in gaps between lines when the ...

Can you explain the distinction among the various FormControl initialization techniques?

Can you discern the variance among the following methods: input: new FormControl({}, inputValidatorFn()) input: [{}, inputValidatorFn()] input: formBuilder.control({}, inputValidatorFn()) They appear to function identically. Is there truly no disparit ...

Maintain the aspect ratio of an image using CSS and flexbox styling

I have a gallery of images that looks great on a full-size PC screen. However, when I resize it for viewing on a phone, the aspect ratio is not maintained and the images only stretch in width. Currently, this is how it appears: https://gyazo.com/a1f605bb4 ...