Tips for applying CSS based on the ngIf condition in Angular 2

Need help with a CSS issue. I have 2 fields for uploading media - one for images and one for videos. I want to apply specific styling to just the video upload section. Can anyone assist me with this?

HTML:

<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" *ngFor="let media of medias; let i = index">
  <div class = "type-img" [hidden]= "selectedImage !='img'">
    <img class="cat-img" src="{{media.image_path}}" style="width: 100px;margin: 10px 0px;" type='img' *ngIf="selectedImage=='img'" />
  </div>
  <div class = "type-video" [hidden]= "selectedImage !='video'" >
  <video width="320" height="240" controls> <source src="{{media.image_path}}" type="video/mp4" *ngIf="selectedImage=='video'" ></video>
  </div>
  <p class="inputimg video">
    <input type="file" name="{{media._id}}[i]" id="{{media._id}}[i]" class="inputfile" (change)="editPinImage($event,media)" style='display: none;' />
    <label *ngIf="media._id" for="{{media._id}}[i]" class="img_change">Change</label>
    <label *ngIf="!media._id" for="{{media._id}}[i]" class="img_change">Add</label>
  </p>
  <div class = "type-video"  [hidden]= "selectedImage !='video'" >
  <span style="margin-left: 12%;">or </span>
  <input type="text" class="form-control form-textbox input-text" (change)="editPinImage($event,media)" style="width: 28%;margin-right: 24%;">
  </div>
</div>

In the code snippet <p class="inputimg video">, the following CSS applies specifically to videos:

.video {
  float: right;
  margin-right: 56%;
  margin-top: -2%;
}

Answer №1

To achieve this, utilize NgClass. Keep in mind to apply the 'video' class when the selected image is a video.

<p class="inputimg" [ngClass]="{'video': selectedImage =='video'}">

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

What is the best way to showcase an ajax response on an HTML webpage?

Apologies for the length of the code, but I'm looking to condense it while maintaining the same functionality. Is there an alternative approach or method that could achieve the same results? I receive data from PHP, which is then passed to JavaScript ...

Is there a way to display a bold gridline every third row in an ASP.NET GridView?

I am looking to create a grid layout with 3 rows, followed by a bold line to separate the 3rd row from the 4th row. Then I want another 3 rows, with another bold line separating the 6th row from the 7th row, and so on. Any suggestions on how to achieve th ...

Get the title text from a selected div and create an array using JQuery

I'm attempting to gather the text from all divs' Title Attributes and store them in an array, but I'm having trouble finding the correct selection. The title is important because it holds the specific string that I require. Below are three ...

What is the best way to rotate rectangles without moving them on an HTML canvas?

I am encountering difficulties when attempting to rotate rectangles on an HTML canvas in place. In the provided JS Fiddle, you can see the original image displayed here: https://jsfiddle.net/vyx2hbky/. What I aim to achieve is to rotate the lines slightly, ...

An issue in IE 11 causes the favicon to disappear when switching pages within an Angular application

The favicon issue is particularly noticeable in Internet Explorer, as it works perfectly fine in Chrome. I am currently working with an angular application that is integrated with a legacy application. When I switch from the legacy application to the angu ...

An unusual CSS phenomenon with z-index

I've encountered a peculiar issue with my z-indexing. I have an image positioned relatively with a z-index of 1, and it should be above my navigation that is positioned absolutely with a z-index of -1. The problem is that upon page load, the image ap ...

Auto language-switch on page load

Wondering if using jQuery is the best approach to create a single French page on my predominantly English website. I want it to work across multiple browsers on pageload, currently using HTML replace. jQuery(function($) { $("body").children().each(funct ...

Angular 5: dynamic component swapping

I am facing a challenge with dynamically placing components inside the view and need to switch their positions. For instance, I have dynamically created components with ids 1 and 2, as shown in the figure linked below. https://i.sstatic.net/hgxd2.jpg No ...

div maintain aspect ratio while scaling

My current layout is structured like this: HTML <div id="container"> <div id="zoomBox"> <div class="box"></div> <div class="box"></div> <div class= ...

Loading JSON and HTML div in the correct order: Reloading vs Refreshing

Currently, I am working on developing a code snippet to retrieve and showcase stock data for my Smart Mirror Project. Although the script successfully displays all of the necessary information, I am encountering difficulties when attempting to update the s ...

Apply CSS styling to the v-html output

I am trying to enhance the style of HTML code using a v-html but have been struggling with finding a working solution so far. Can anyone help me out? :( Below is my code snippet: Template : <div class="para" v-html="value" /> Script : exp ...

Problem with Bootstrap slider animation

Currently, I am tackling a bootstrap slider project, where the images are all in place, and they transition every few seconds. Everything appears to be functioning correctly, except for the animation display. The image changes suddenly without any smooth t ...

Preventing value alteration when input is blank

I recently wrote this code snippet for a form I was designing: <div class="col-md-6"> <label class="labels">Birthday:</label> <input method="POST" name="birthdate" class="form-contro ...

"Divs are now linked and drag as one cohesive unit instead of

As I was experimenting with making images draggable and resizable, I encountered a small issue. When I attempted to drag two or more images, they would merge into one large draggable object instead of remaining separate. My goal was to make each image drag ...

Troubleshooting Problems with Adjusting Left Margin Using JQuery

function adjust_width() { $('#cont').toggle(function(){ $('#cont').animate({marginLeft:'0%'}); },function(){ $('#cont').animate({marginLeft:'18.4%'}); }); } The code above is in ...

Can the tooltip placement be adjusted in ng-bootstrap when it reaches a specific y-axis point?

Currently, I am facing an issue with my tooltip appearing under the header nav-bar instead of flipping to another placement like 'left-bottom' when it reaches the header. Is there a way to manually set boundaries for tooltips in ng-bootstrap? Unl ...

What is the best way to present progress bar numbers in Bootstrap beneath the bar?

I have successfully implemented a progress bar using Bootstrap. Now, I am looking to display numerical values below the progress bar, similar to this: https://i.sstatic.net/3QG8d.png Is there a way to achieve this without utilizing JavaScript graphing l ...

Show a dynamic value in a div element on an HTML page using the text property

There is a value that I would like to display: var head=comments; The "comments" variable contains a string. Is there a way for me to achieve the following: var hoverText='text=comments'; <div "+hoverText+"></div> In order to ...

Changing the direction of input text from right to left: A step-by-step guide

Is there a way to reverse text in HTML? For example, if I input "apple" can it be automatically changed to "elppa"? I have attempted some solutions but they only affect the text direction! https://i.sstatic.net/ce2Fv.jpg ...

Sketch lines within the accordion

In my design, I have nested accordions and I am trying to create a graphical representation with vertical and horizontal lines connecting the elements. Here is the basic structure: <div id="accordion3" class="collapseblock"> <div class="cardsm ...