css pie.htc使用總結

pie.htc可讓ie支持CSS3的一些特性,但並不老是有效,使用時常常會碰到下面的一些問題css

 

 

1. z-index相關問題
IE下這些css3效果實現是藉助於VML,由VML繪製圓角或是投影效果的容器元素,而後這個容器元素做爲目標元素的後兄弟節點插入,若是目標元素position:absolute 或是 position:relative,則這個css3-Container元素將會設置與之同樣的z-index值,在DOM tree中,同級的元素老是後面的覆蓋前面的,因此這樣就實現了覆蓋,又避免了可能有其餘元素正好插入其中。python

因此,問題來了,若是目前元素的position屬性爲static,也就是默認屬性,則z-index屬性是沒有用的,無覆蓋可言,因此此時IE瀏覽器下CSS3的渲染是不會成功的。要解決也很簡單,設置目標元素position:relative或是設置祖先元素position:relative並賦予一個z-index值(不可爲-1)css3

2. 至關路徑的問題
IE瀏覽器的behavior 屬性是相對於HTML文檔而言的,與CSS其餘的屬性不同,不是相對於CSS文檔而言的。這使得使用pie.htc文件不怎麼方面。若是絕對路徑於根目錄,則CSS文件不方便移動;若是相對路徑與HTML文檔,則pie.htc文件在不一樣HTML頁面見的重用性大大下降。同時,諸如border-image後面的URL屬性路徑也很差處理。web

3. 縮寫的問題
使用PIE實現IE下的CSS3渲染(其餘方法也是同樣),只能使用縮寫的形式,例如圓角效果,咱們能夠設置border-top-left-radius表示左上圓角,可是PIE確實不支持這種寫法的,只能是老老實實的縮寫。docker

4. 提供正確的Content-Type
要想讓IE瀏覽器支持htc文件,須要一個有着」text/x-component」 字樣的content-type 頭部,不然,會忽視behavior。絕大數web服務器提供了正確的content-type,可是還有一部分則有問題。例如的個人空間域名商就沒有」text/x-component」 字樣的content-type,多是出於安全的考慮。django

若是您發如今您的機子上PIE方法無效,也就是htc文件這裏指pie.htc文件無效,檢查您的服務器配置,可能其須要更新到最新的content-type。例如對於Apache,您能夠在.htaccess文件中左以下處理:瀏覽器

在django中使用嗯PIE.htc的方式以下:
配置url.py:安全

[python]  view plain  copy
 
  1. from django.conf.urls.defaults import *  
  2. from django.views.generic.simple import redirect_to  
  3. from django.core.servers.basehttp import FileWrapper  
  4. from django.http import HttpResponse  
  5. import os  
  6. import settings  
  7.   
  8. # Uncomment the next two lines to enable the admin:  
  9. from django.contrib import admin  
  10. admin.autodiscover()  
  11.   
  12. def pie_with_headers(request):  
  13.     filename = settings.STATIC_PATH + '/scripts/css/PIE.htc'  
  14.     wrapper = FileWrapper(open(filename))  
  15.     response = HttpResponse(wrapper, content_type='text/x-component')  
  16.     response['Content-Length'] = os.path.getsize(filename)  
  17.     return response  
  18.   
  19. urlpatterns = patterns('',  
  20.   
  21.     # Uncomment the next line to enable the admin:  
  22.     (r'^admin/service/appinfo/(?P<id>\d+)/delete','service.admin_views.app_delete'),  
  23.     (r'^admin/service/appinfo/(?P<id>\d+)','service.admin_views.app_edit'),  
  24.     (r'^admin/service/appinfo/add','service.admin_views.app_edit'),  
  25.     (r'^admin/', include(admin.site.urls)),  
  26.     (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root':'/opt/dev/website/kakaservice/media', 'show_indexes': True}),  
  27.     (r'^content/(?P<path>.*)$', 'django.views.static.serve', {'document_root':'/opt/dev/website/kakaservice/templates/content', 'show_indexes': True}),  
  28.     (r'^scripts/(?P<path>.*)$', 'django.views.static.serve', {'document_root':'/opt/dev/website/kakaservice/templates/scripts', 'show_indexes': True}),  
  29.     (r'^PIE\.htc',pie_with_headers,{}),  
  30.     (r'^$', 'service.views.index'),  
  31. )  



而後在相應的css文件中使用(使用時須要注意相對路徑問題,最好經過django server的access信息來判斷請求的路徑):服務器

.page .content .right .item .icon{
    width: 140px;
    height: 141px;
    padding: 5px;
    background-color: #ffffff;
    margin: 15px auto;
    font-size: 0;
    position: relative;
    -webkit-border-radius: 25px 25px 25px 25px;
    -moz-border-radius: 25px 25px 25px 25px;
    border-radius: 25px 25px 25px 25px;
    behavior: url(../PIE.htc);
}app

相關文章
相關標籤/搜索