CSS Box Model Attribute Ordering Convention

前端 未结 2 1017
借酒劲吻你
借酒劲吻你 2021-01-01 05:44

If you ever wonder in what order to enter your CSS attributes like border, padding, font-family, etc. Two common approaches seem to be

相关标签:
2条回答
  • 2021-01-01 06:27

    It makes sense to:

    • Group the properties with similar functions (like height and width or clear and float) because if we change the value of one property, we often change the value of other properties in the group too.
    • Order the property groups such that they are in decision sequence. For example position before float, because if I choose position: absolute, float will be irrelevant.
    0 讨论(0)
  • 2021-01-01 06:48

    Box Model Convention copied from http://fordinteractive.com/tools/propertyorder/propertyorder.css.

    Additions should be edited in when they are found to be missing from the list. Please comment on where you think that additions and wait for some agreement before adding them to the final list.

    display: ;
    visibility: ;
    float: ;
    clear: ;
    
    position: ;
    top: ;
    right: ;
    bottom: ;
    left: ;
    z-index: ;
    
    width: ;
    min-width: ;
    max-width: ;
    height: ;
    min-height: ;
    max-height: ;
    overflow: ;
    
    margin: ;
    margin-top: ;
    margin-right: ;
    margin-bottom: ;
    margin-left: ;
    
    padding: ;
    padding-top: ;
    padding-right: ;
    padding-bottom: ;
    padding-left: ;
    
    border: ;
    border-top: ;
    border-right: ;
    border-bottom: ;
    border-left: ;
    
    border-width: ;
    border-top-width: ;
    border-right-width: ;
    border-bottom-width: ;
    border-left-width: ;
    
    border-style: ;
    border-top-style: ;
    border-right-style: ;
    border-bottom-style: ;
    border-left-style: ;
    
    border-color: ;
    border-top-color: ;
    border-right-color: ;
    border-bottom-color: ;
    border-left-color: ;
    
    outline: ;
    
    list-style: ;
    
    table-layout: ;
    caption-side: ;
    border-collapse: ;
    border-spacing: ;
    empty-cells: ;
    
    font: ;
    font-family: ;
    font-size: ;
    line-height: ;
    font-weight: ;
    text-align: ;
    text-indent: ;
    text-transform: ;
    text-decoration: ;
    letter-spacing: ;
    word-spacing: ;
    white-space: ;
    vertical-align: ;
    color: ;
    
    background: ;
    background-color: ;
    background-image: ;
    background-repeat: ;
    background-position: ;
    
    opacity: ;
    
    cursor: ;
    
    content: ;
    quotes: ;
    
    • Where should clip go?
    • Where should user-select go? (not supported except by Mozilla with -moz-user-select and Chrome with -webkit-user-select. IE uses JavaScript onselectstart)
    • Where should border-radius go? (not supported except by Mozilla with -moz-border-radius and Chrome with -webkit-border-radius)

    Please comment if you have a suggestion as to where something should go.

    0 讨论(0)
提交回复
热议问题