最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - How to set the css of the li:before with ng-style - Stack Overflow

matteradmin6PV0评论

I want to change the width value of the li:before with a variable scope (width).

 <ul>
    <li ng-repeat="step in stepsList" ng-style="{li:before { 'width': width;}"
        ng-class="{true: 'active'}[step.active]">
        <span>{{step.stepName | uppercase}}</span>
    </li>
</ul>

I'm doing this code but it's not working. help please.

I want to change the width value of the li:before with a variable scope (width).

 <ul>
    <li ng-repeat="step in stepsList" ng-style="{li:before { 'width': width;}"
        ng-class="{true: 'active'}[step.active]">
        <span>{{step.stepName | uppercase}}</span>
    </li>
</ul>

I'm doing this code but it's not working. help please.

Share Improve this question asked May 20, 2015 at 14:23 user2774431user2774431 531 silver badge6 bronze badges 3
  • you can't. style does not work with pseudo-elements. – Daniel A. White Commented May 20, 2015 at 14:25
  • ngstyle uses inlinestyle so it is not possible stackoverflow./questions/14141374/… – Arun P Johny Commented May 20, 2015 at 14:25
  • stackoverflow./questions/20138454/… – Daniel A. White Commented May 20, 2015 at 14:26
Add a ment  | 

1 Answer 1

Reset to default 3

Unfortunately you cannot have pseudoelements within inline styling. What you could do is have two sepparate CSS Classes like

.a:before {}
.b:before {}

This way you could use ngClass to add the appropriate class to your HTML

Post a comment

comment list (0)

  1. No comments so far