Tips for building a dynamic view using Angular

I am working on a project where I need to dynamically generate multiple horizontal lines using data from a JSON file, similar to the example in the image below. https://i.sstatic.net/MthcU.png Here is my attempt: https://i.sstatic.net/EEy4k.png

Component.html

<div style="text-align: center">
  <div class="flex-items">
    <div *ngFor="let item of timelineObject">
      <h3 class="row text-center">{{ item.data }}</h3>
      <hr id="timeline" />
      <img style="" [src]="item.icon" />
    </div>
  </div>
</div>

Component.css

.flex-items {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}
#timeline {
  display: inline-block;
  margin: auto;
  width: 10vh;
  border: 10px solid blue;
}

Answer №1

The provided HTML structure may differ from the one you provided, but I used some demo data to simulate the desired behavior. The key element here is the flex-box property order. By utilizing the :nth-child property, I am able to change the order of h3 and img elements within every alternate timeline-wrapper div. It's important to ensure that both the h3 and img have the same height in order for the hr to be consistently displayed in the center.

<div class="flex-items">
  <div class="timeline-wrapper">
    <h3 class="row text-center">2017</h3>
    <hr>
    <img src="https://picsum.photos/200" />
  </div>
  <div class="timeline-wrapper">
    <h3 class="row text-center">2018</h3>
    <hr>
    <img src="https://picsum.photos/200" />
  </div>
  <div class="timeline-wrapper">
    <h3 class="row text-center">2019</h3>
    <hr>
    <img src="https://picsum.photos/200" />
  </div>
  <div class="timeline-wrapper">
    <h3 class="row text-center">2020</h3>
    <hr>
    <img src="https://picsum.photos/200" />
  </div>
</div>

CSS

.flex-items {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}

.timeline-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

hr {
  background-color: blue;
  height: 5px;
  width: 100%;
}

h3,
img {
  height: 200px;
  margin: 0;
}

.timeline-wrapper:nth-child(2n) h3 {
  order: 2;
}

.timeline-wrapper:nth-child(2n) img {
  order: 0;
}

.timeline-wrapper:nth-child(2n) hr {
  order: 1;
}

Access the live example here: https://jsfiddle.net/w6nvfb4d/32/

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 your JavaScript skills: Tackling nested object key and value replacements

I am looking to manipulate the values of a nested object using JavaScript. The structure of the object is outlined below. let jsonObj = { "service":[ { "name":"restservice", "device&quo ...

JavaScript does not allow executing methods on imported arrays and maps

In my coding project, I created a map named queue in FILE 1. This map was fully built up with values and keys within FILE 1, and then exported to FILE 2 using module.exports.queue = (queue). Here is the code from FILE 1: let queue = new.Map() let key = &q ...

What is the best way to implement a never-ending scrolling grid loader within a scrollable area using Codeigniter?

In my Codeigniter framework and bootstrap installation, I have multiple sub-pages. On one of these pages, I am attempting to implement an infinite scroll loader using a jQuery script from a tutorial found at gridScrollFx.js. Here is the JS file I am using: ...

A guide on implementing multiline properties in a property file for Selenium WebDriver

At the moment, I am focusing on utilizing Selenium WebDriver with code that is developed in Java. In the snippet below, I have successfully verified if the dropdown values match the UI for one dropdown. Now, I aim to extend this capability to check multip ...

Text Alignment Issue in Icon Bar of Zurb Foundation 5

There's an unusual problem I'm encountering with the alignment of text under the icon bar not being properly centered below the icons. Here is a snippet of the code: <div class="row"> <div class="small-12 columns"> < ...

Is it possible to handle both ajax form submissions and browser post submissions in express.js?

On my website, I have implemented a contact form using express.js (4.0). I am contemplating how to manage the scenario where a user disables JavaScript. If the last part of my routing function looks like this: res.render('contact.jade', { tit ...

Is there a way for me to gain access to the ng-repeat scope?

I have a scenario where my ng-repeat generates different elements and I need to perform certain operations, such as creating variables, within the scope of the ng-repeat. Is there a way to access the specific ng-repeat scope? How can I achieve something ...

I'm having trouble getting my home.js to render in the outlet component

After using Material-UI to create navbar.js, I encountered an issue where the other component was not rendering in the <Outlet/> Component RootLayout.js import { Outlet } from "react-router-dom"; import NavBar from "../component/NavBa ...

Express is encountering an issue where it is unable to interpret the property 'name' of an undefined element coming from

I am attempting to create a fullstack application using Node.js and Angular with Material UI. I have encountered an issue while working on my web resource management application. Currently, I am facing an error during the registration and data submission ...

Ways to automatically run Java script again when new elements are included in the document model

Recently, I added paging and filtering to a page displaying a list of products. @model ProductFiltersViewModel ... <div class="row"> <aside class="col-3"> <nav class="sidebar card py-2 mb-4"> ...

I'm having difficulty with the installation of the @angular/CLI package

npm ERROR 404: Package @angular/CLI@latest Not Found ** log: ** 0 info it worked if it ends with ok 1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe', 1 verbose cli 'C:\\Program Files\&b ...

Adding external JavaScript files that rely on jQuery to a ReactJS project

As a beginner in web development, I have a question regarding importing external JavaScript files in ReactJS. I currently have the following imports: import $ from 'jquery'; window.jQuery = $; window.$ = $; global.jQuery = $; import './asse ...

Locate a specific text within a complex array of objects and retrieve the objects that contain the match as

I have an array of objects named input as shown below. Each object in the array contains a property vertical of type string, an array called platformList, and a nested object named radar_metadata. I am looking to implement a search functionality where I c ...

Using Angular 4 in combination with Bootstrap 4 to create powerful data tables

Looking to incorporate a table using Angular 4 and Bootstrap 4, but the standard Bootstrap 4 table doesn't meet expectations. In my search for alternatives, I came across this GitHub project: https://www.npmjs.com/package/angular-4-data-table-fix Ho ...

Error encountered: Unexpected character 'C' found at the beginning of the JSON data

Hey there, I'm new to all of this so just trying to figure it out! :) I stumbled upon a GitHub project that I really want to work on and understand in order to create my own solution. The project can be found at the following link: https://github.com ...

Creating dynamic CSS classes with SCSS/SASS

Recently, I encountered a scenario where I needed to automate the creation of a series of CSS classes by utilizing a mixin. This led me to ponder if there is a dynamic approach to achieve this. Essentially, the classes I have are structured as follows: . ...

Tips for clearing input fields in React.js without using an empty string

Is there a way to reset the input field in this specific scenario? const [username, setUsername] = useState({ username: "", usernameError: "" }); const handleUsername = (inputUsername) => { if (inputUsername.length > ...

What is the best way to detect when an option is selected in a Material UI autocomplete component?

Utilizing the autocomplete feature with filterOptions to propose adding a new value: <Autocomplete multiple name="participant-tags" options={people} getOptionLabel={(option) => option.name} renderInput={(param ...

Iterate over the array and show the elements only when a click event occurs

I am trying to create a loop through an array (array) and display the elements one by one only after clicking a button (bt). However, when I run this code, it only shows the last element of the array (i.e. honda). Can someone please help me fix this issu ...

using the useEffect hook to create a loop that runs infinitely

For my project, I am working on updating data in firebase. The issue that I'm facing is that the data seems to be constantly looping, causing potential crashes. Is there a way to stop this loop and prevent any crashing? import "./App.css"; ...