Home > Article > Web Front-end > A brief analysis of CSS properties and naming conventions in JavaScript_javascript skills
Many CSS style properties have hyphens in their names, which are interpreted as minus signs in JavaScript.
Therefore, the property names of CSS2Properties objects are a little different from the real CSS property names.
If a CSS property name contains one or more hyphens, the hyphens need to be deleted in JS, and the original letters immediately after the hyphens should be changed to uppercase.
It should be noted that float is a keyword of JS, so in JS float is written as cssFloat or floatStyle.
The following is a comparison table between CSS properties and CSS encoding in JavaScript:
Box tag and attribute comparison:
Code
CSS syntax (case-insensitive) JavaScript syntax (case-sensitive)
border border
border- bottom borderBottom
border-bottom-color borderBottomColor
border-bottom-style borderBottomStyle
border-bottom-width borderBottomWidth
border-color borderColor
border-left borderLeft
border-left - Color BorderLeftColor
Border-Left-Style Border hardStyle
Border-Left-Width BorderLeftwidth
Border-Right BorderRight
Border-COLOR BORERRIGHT Color
Border- right-width borderRightWidth
border-style borderStyle
border-top borderTop
border-top-color borderTopColor
border-top-style borderTopStyle
border-top-width borderTopWidth
border - width borderWidth
clear clear
float floatStyle(ie) cssFloat(FF)
margin margin
margin-bottom marginBottom
margin-left marginLeft
margin-right marginRight
margin- top marginTop
padding padding
padding-bottom paddingBottom
padding-left paddingLeft
padding-right paddingRight
padding-top paddingTop
Color and background tags and attribute comparison:
CodeCSS syntax (case-insensitive) JavaScript syntax (case-sensitive)
background background
background-attachment backgroundAttachment
background-color | backgroundColor
background-image | backgroundImage
background-position | backgroundPosition
background-repeat | backgroundRepeat
color | color
Style tag and attribute comparison:
CSS syntax (case-insensitive) JavaScript syntax (case-sensitive)
display display
list-style-type listStyleType
list-style-image listStyleImage
list- style-position listStylePosition
list-style listStyle
white-space whiteSpace
Text style tag and attribute comparison:
CSS syntax (case-insensitive) JavaScript syntax (case-sensitive)
font >font-variant fontVariant
font-weight fontWeight
Text tag and attribute comparison:
Code
CSS syntax (case-insensitive) JavaScript syntax (case-sensitive)letter-spacing letterSpacingline-break lineBreak
line-height lineHeighttext-align textAlign
text-decoration textDecoration
text-indent textIndent
text-justify textJustify
text-transform textTransform
vertical-align verticalAlign