css3 - css背景图片高度百分百,宽度保持比例怎么做?
巴扎黑
巴扎黑 2017-04-17 11:20:12
0
3
1399

css中有宽度百分百,若想达到高度占屏幕的百分百,宽度保持纵横比应该怎么做呢, 希望详细解答,嘻嘻

巴扎黑
巴扎黑

reply all(3)
迷茫

If you are referring to the background image... background-size: auto 100%; It will have the effect you want.

It is recommended to read MDN’s explanation of background-size

刘奇

Although I would like to be able to answer in detail, I am helpless. I don’t know what you want or need.

伊谢尔伦

background: url(../images/main1_bg.jpg) no-repeat center center;
background-size:cover;
background-attachment: fixed;
I wrote it before, here background-size: 100% 100%; probably OK, but the proportion will be distorted.
The method I use now is to set img to absolute, top:0;left:50%; height:100%; and then write <img ... onload="setPos(this)"&gt on the label ;
Then this setpos function is written in the js file, function setpos(ts){ var w=ts.width/2; ts.style.margin="0 0 0 -"+w+"px"; } This function It will be executed after the image is loaded to center the image horizontally.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template