通過CSS沙箱我的意思是我的佈局中有一個完全獨立的外觀部分。我需要這個,因爲我的一些類需要在佈局中輸出一些「窗口」的內容,但我不希望應用程序的CSS混亂。他們主要是調試相關的,如打印var內容,基準圖或顯示一些錯誤/異常。有沒有一種無痛的方式來製作一個「CSS沙盒」?
到目前爲止,我正在做某種本地重置,但這真的很煩人,以避免碰撞,並可能失敗,如果我忘記了一些規則。例如:
html body div.eh-box {
margin: 0 !important;
padding: 0 !important;
border: 0 !important;
font-size: 100% !important;
vertical-align: baseline !important;
background-color: #fff !important;
font: 12px/12px 'Helvetica Neue', Helvetica, Arial, sans-serif !important;
margin-bottom: 20px !important;
}
html body div.eh-box * {
margin: 0 !important;
padding: 0 !important;
border: 0 !important;
font-size: 100% !important;
font: inherit !important;
vertical-align: baseline !important;
color: #333 !important;
}
html body div.eh-box .title {
font-size: 50px !important;
line-height: 75px !important;
/*font-weight: bold !important;*/
}
html body div.eh-box .desc {
font-size: 24px !important;
line-height: 36px !important;
}
創建它自己的'div'? – Kermit
如果應用程序對任何標籤進行了樣式設置(例如,認爲是twitter引導程序),那麼簡單的'div'也不會保護我的內容不被樣式化。 –
@hugo_leonardo:你爲什麼不製作iframe?您也可以使用本地CSS重置,但這不會阻止'!important'屬性泄漏。 – Blender