2015-09-09 138 views
0

我用ng-repeat列出了一些圖像,並且想要應用一個帶有一些內容的僞類。CSS僞元素不適用於ng-repeat?

這裏是我的小提琴:https://jsfiddle.net/Noitidart/y7dxa6n8/11/

這裏是代碼:

<style> 
    body {background-color:steelblue;} 
    img::after { content: 'rawr'; size:100px; color:red; } 
</style> 
<div ng-app="myApp"> 
    <div ng-controller="MyController as mc"> 
    <img ng-repeat="aSrc in mc.arr" ng-src="{{aSrc}}"/> 
    </div> 
</div> 

控制器:

var myApp = angular.module('myApp', ['ngCookies']); 

myApp.controller('MyController', [function($cookie) { 
      this.arr = ['https://jsfiddle.net/img/logo.png'] 
}]); 

但是僞類無法正常工作。這很奇怪。

回答

2

它不是角ng-repeat

問題只是檢查<img />沒有角,並與::before

<img src="https://jsfiddle.net/img/logo.png"> 

img::after { content: 'rawr'; size:100px; color:red; } 

它不是的,因爲大多數的瀏覽器工作檢查不支持::before::after on img elements

支票this

+0

Wowwwww我用這塊垃圾掙扎了一個半小時,然後吃了一頓晚餐。謝謝你,你救了我這麼頭疼! – Noitidart

+1

啊:)很高興聽到那cheerz :) –