2012-01-08 2 views
5

'제거'란 해당 요소에서 내려 와서 브라우저 기본값에 넣을 수있는 모든 스타일을 재설정하는 것을 의미합니다.요소에서 모든 스타일을 제거하는 방법은 무엇입니까?

나는 디버그를 위해 이것을 필요로한다. 어떤 규칙이 해를 끼치는 지 알지 못한다. 좋은 접근법은 모든 스타일을 제거한 다음 제한 사항을 하나 하나 풀어서 일이 잘못 될 때를 확인하는 것이다. 그래서

{ right: auto !important; left: auto !important; visibility: visible !important;... 

등을 가능한 모든 스타일을 통해 :

당신은 다음과 같이 구성 할 웹에있는 모든 조각을 보았다.

+0

관련 : http://stackoverflow.com/questions/15901030/reset-remove-css-styles-for- element-only/15903168 –

답변

3

의 수정 된 버전을 사용합니다. CSS3 초안에서 제안 된 값 initial이 있지만 정의 된 경우에도 브라우저 기본값으로 정의 된 것이 아닌 CSS 사양에 정의 된 초기 값으로 속성이 설정됩니다. 예를 들어, display 속성의 초기 값은 inline이지만 브라우저는 기본적으로 모든 항목을 인라인 요소로 렌더링하지 않습니다.

Firebug 또는 Firefox 용 Web Developer Extension과 같은 디버깅 및 검사 도구를 사용하는 것이 더 나은 방법입니다. 그들은 어떤 스타일이 어떤 요소에 적용되는지, 어디서 오는 지 알 수있게 해줍니다.

+0

이것은 rsk82를 조사해야하는 것입니다. –

0

다른 모든 스타일 시트보다 먼저로드되는 재설정 스타일 시트를 사용하십시오.

나는 당신은 할 수 없습니다 http://meyerweb.com/eric/tools/css/reset/

+0

또한 F12를 사용하여 Safari 및 Chrome에서 개발자 ui가 표시되면 Firefox 용 firebug add를 설치하고 스타일이 어디에서 왔는지 확인할 수도 있습니다. –

+0

나는 야후를 믿는다! 하나도 가지고 있음 – Steve

+1

이것은 "가능한 모든 스타일"을 변경하지 않는다는 것에 유의하십시오. 그러나 스타일 수는 불행히도 브라우저마다 다릅니다.CSS 파일에서 참조하는 모든 스타일을 추가해야합니다. –

1

Chrome/Safari를 사용하는 경우 initial은 원하는 작업에 적합합니다. 설정이 끝나면 활성 스타일이 initial으로 표시되고 계산 된 스타일이 브라우저 기본값으로 표시됩니다.

활성 스타일을 기본값으로 설정하려면 임시 요소를 만들고 요소 속성을 임시 값으로 설정하십시오.

데모 : http://jsfiddle.net/ThinkingStiff/Yb9J9/

스크립트 :

Element.prototype.setDefaultStyles = function() { 
    var element = document.createElement(this.tagName), 
     styles = window.getComputedStyle(element), 
     display = styles.getPropertyValue('display'); 
    element.style.display = 'none'; 
    document.body.appendChild(element); 

    for(style in styles) { 
     this.style[styles[style]] = styles.getPropertyValue(styles[style]); 
    }; 

    this.style.display = display; 
    document.body.removeChild(element); 
}; 

document.getElementById('unstyled').setDefaultStyles(); 

HTML :

<div id="styled">styled</div> 
<div id="unstyled">unstyled</div> 

CSS :

#styled, #unstyled { 
    border: 1px solid red; 
    color: green; 
    width: 100px; 
    height: 50px; 
} 

출력 :

enter image description here

0

시도해보십시오. 이 같은 클래스 이름이 뭔가를하고 다음 원래

.reset-this { 
    animation : none; 
    animation-delay : 0; 
    animation-direction : normal; 
    animation-duration : 0; 
    animation-fill-mode : none; 
    animation-iteration-count : 1; 
    animation-name : none; 
    animation-play-state : running; 
    animation-timing-function : ease; 
    backface-visibility : visible; 
    background : 0; 
    background-attachment : scroll; 
    background-clip : border-box; 
    background-color : transparent; 
    background-image : none; 
    background-origin : padding-box; 
    background-position : 0 0; 
    background-position-x : 0; 
    background-position-y : 0; 
    background-repeat : repeat; 
    background-size : auto auto; 
    border : 0; 
    border-style : none; 
    border-width : medium; 
    border-color : inherit; 
    border-bottom : 0; 
    border-bottom-color : inherit; 
    border-bottom-left-radius : 0; 
    border-bottom-right-radius : 0; 
    border-bottom-style : none; 
    border-bottom-width : medium; 
    border-collapse : separate; 
    border-image : none; 
    border-left : 0; 
    border-left-color : inherit; 
    border-left-style : none; 
    border-left-width : medium; 
    border-radius : 0; 
    border-right : 0; 
    border-right-color : inherit; 
    border-right-style : none; 
    border-right-width : medium; 
    border-spacing : 0; 
    border-top : 0; 
    border-top-color : inherit; 
    border-top-left-radius : 0; 
    border-top-right-radius : 0; 
    border-top-style : none; 
    border-top-width : medium; 
    bottom : auto; 
    box-shadow : none; 
    box-sizing : content-box; 
    caption-side : top; 
    clear : none; 
    clip : auto; 
    color : inherit; 
    columns : auto; 
    column-count : auto; 
    column-fill : balance; 
    column-gap : normal; 
    column-rule : medium none currentColor; 
    column-rule-color : currentColor; 
    column-rule-style : none; 
    column-rule-width : none; 
    column-span : 1; 
    column-width : auto; 
    content : normal; 
    counter-increment : none; 
    counter-reset : none; 
    cursor : auto; 
    direction : ltr; 
    display : inline; 
    empty-cells : show; 
    float : none; 
    font : normal; 
    font-family : inherit; 
    font-size : medium; 
    font-style : normal; 
    font-variant : normal; 
    font-weight : normal; 
    height : auto; 
    hyphens : none; 
    left : auto; 
    letter-spacing : normal; 
    line-height : normal; 
    list-style : none; 
    list-style-image : none; 
    list-style-position : outside; 
    list-style-type : disc; 
    margin : 0; 
    margin-bottom : 0; 
    margin-left : 0; 
    margin-right : 0; 
    margin-top : 0; 
    max-height : none; 
    max-width : none; 
    min-height : 0; 
    min-width : 0; 
    opacity : 1; 
    orphans : 0; 
    outline : 0; 
    outline-color : invert; 
    outline-style : none; 
    outline-width : medium; 
    overflow : visible; 
    overflow-x : visible; 
    overflow-y : visible; 
    padding : 0; 
    padding-bottom : 0; 
    padding-left : 0; 
    padding-right : 0; 
    padding-top : 0; 
    page-break-after : auto; 
    page-break-before : auto; 
    page-break-inside : auto; 
    perspective : none; 
    perspective-origin : 50% 50%; 
    position : static; 
    /* May need to alter quotes for different locales (e.g fr) */ 
    quotes : '\201C' '\201D' '\2018' '\2019'; 
    right : auto; 
    tab-size : 8; 
    table-layout : auto; 
    text-align : inherit; 
    text-align-last : auto; 
    text-decoration : none; 
    text-decoration-color : inherit; 
    text-decoration-line : none; 
    text-decoration-style : solid; 
    text-indent : 0; 
    text-shadow : none; 
    text-transform : none; 
    top : auto; 
    transform : none; 
    transform-style : flat; 
    transition : none; 
    transition-delay : 0s; 
    transition-duration : 0s; 
    transition-property : none; 
    transition-timing-function : ease; 
    unicode-bidi : normal; 
    vertical-align : baseline; 
    visibility : visible; 
    white-space : normal; 
    widows : 0; 
    width : auto; 
    word-spacing : normal; 
    z-index : auto; 
    /* basic modern patch */ 
    all: initial; 
    all: unset; 
} 

여기에서 사용 Reset/remove CSS styles for element only

관련 문제