0

I have an horizontal list of folders.
I want to have a margin-left between folders(for spacing) but i dont want it to apply on the first item (so there will be no space from screen).
The problem is that 'first-child' applies on hidden elements as well.
how can i apply a class on the first visible item in list without using jQuery ?

<ul id="myList">
  <li ng-repeat="folder in viewmodel.folders" id="folder" class="folder"
      ng-show="folder.role == '13' || folder.role == '14'" ng-click="bringChildren(folder)" loading-directive>
    <div class="block"></div>
    <div class="folderIcon {{ folder.nameKey }}"></div>
    <div class="folderName">{{ folder.displayName }}</div>
    <div class="itemsCounter"></div>
  </li>
</ul>
4
  • 1
    Is it possible to just use margin-right? If you don't have anything else after your list, it could be a possible solution. Commented Mar 8, 2015 at 14:10
  • 1
    Have you considering using a filter on your list, instead of ng-show? Commented Mar 8, 2015 at 14:40
  • well the margin-right could be a solution however i have other inline elements so there is a problem Commented Mar 8, 2015 at 15:22
  • what do you mean filter on your list? do filter on ng-repeat? I was not familiar with that Commented Mar 8, 2015 at 15:23

3 Answers 3

2

Use ngIf rather than ngShow, since ngIf actually adds/removes the element from the DOM based on the specified condition. Then your first-child CSS selector will work fine.

Sign up to request clarification or add additional context in comments.

Comments

0

with CSS selector you especifiq what item you aplicate the style. use padding-left: 15px; in full elements of uoy list and the first child padding-left: none and this sobrewrite.

Comments

0

use ng-class like the follow and get the first element by queryselector and change the style.

<li ng-repeat="folder in viewmodel.folders" id="folder" 
  ng-show="folder.role == '13' || folder.role == '14'" ng-click="bringChildren(folder)" loading-directive  ng-class="{element:folder.role == '13' || folder.role == '14',folder:true}">

and then apply style like this.

document.querySelector(".element").style.marginLeft=0;

2 Comments

Hi bala thanks for quick reply ! however i need this to apply only for the first item and not for both
queryselector selects the first element only. So the style will only apply to first element

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.