The background-size CSS property sets the size of the element's background image. The image can be left to its natural size, stretched, or constrained to fit the available space.
document.getElementById("myDIV").style.background="url('smiley.gif') blue repeat-x center"; Try it Yourself » Example Set a background color for a document: document.body.style.backgroundColor="red"; Try it Yourself » Example ...
FitText FlatBorders Font FontCharSet FontFamily FontFamilyValues FontPitchValues FontRelationshipType Fonts FontSignature FontSize FontSizeComplexScript FontTypeHintValues Footer FooterReference Footnote FootnoteDocumentWideProperties FootnoteEndnoteReferenceType FootnoteEndnoteSeparatorReferenceType FootnoteEndnoteT...
FitText FlatBorders 字体 FontCharSet FontFamily FontFamilyValues FontPitchValues FontRelationshipType 字体 FontSignature FontSize FontSizeComplexScript FontTypeHintValues 页脚 FooterReference Footnote FootnoteDocumentWideProperties FootnoteEndnoteReferenceType FootnoteEndnoteSeparatorReferenceType FootnoteEndnot...
The background-size CSS property sets the size of the element's background image. The image can be left to its natural size, stretched, or constrained to fit the available space.
cssCopy to Clipboardplay /* Shared for all DIVS in example */ ol, li { margin: 0; padding: 0; } li { margin-bottom: 12px; } div { background-image: url(star-solid.gif); width: 160px; height: 70px; } /* Background repeats */ .one { background-repeat: no-repeat; } .two...
It will fit perfectly within the div section without any space around the div.HTML with CSS<html> <head> <title>Fit image on screen</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <style> body{ background-image:url('images/...
使用object-fit:cover 不丢失比率。div { border: black solid; width: 400px; height: 400px; } img { width: 100%; height: 100%; object-fit: cover } <div> <img src="//lorempixel.com/100/100" /> </div> 注意: 这在IE 中不受支持PS - 对于那些喜欢投反对票(并且正在投反对票)的人,原...
A Few Ways to Scale the Background Image The CSS property to scale a background image so that it fills all the space available is background-size. Given that, you still need to figure out what to do if the picture, when expanded, does not fit perfectly into the surrounding space. Af...
Return the background image of a specific <div> element: letimg = document.getElementById("myDiv").style.backgroundImage; Try it Yourself » Example Return the background image of a document: letimg = document.body.style.backgroundImage; ...