国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > CSS > 正文

css實現一個元素高度固定寬度按比例顯示效果

2024-07-11 08:31:32
字體:
來源:轉載
供稿:網友

用padding-top百分比可以實現寬度固定高度按比例展示,現在的需求是對一個video視頻的盒子div高度是固定的,寬度如何按比例展示?

解決后效果如圖:

紅框標注的即是我在上面高度比例固定的范圍內寬度自適應的效果;

css代碼:

.content { margin: 0 auto; height: 79vh; .video_box { position: relative; height: 100%; overflow: hidden; margin: 0 auto; width: 79vh*1.778; max-width: 100vw; .ad_pic { display: none; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: url(6.jpg) no-repeat center; background-size: 100% 100%; img { width: 100%; height: 100%; } .btn_play { display: inline-block; .width(50); .height(50); position: absolute;; left: 50%; top: 50%; .margin-left(-25); .margin-top(-25); background: url(../../public/img/icon_play.png) no-repeat center; background-size: 100% 100%; } } iframe, object, embed, video { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } .video_card { position: absolute; top: 0; left: 0; width: 2px; height: 1px; } } }

html:

<div class="content"> <div class="video_box"> <div class="ad_pic"> <span class="btn_play"></span> </div> <video id="ad_video" autobuffer src="a.mp4" autoplay preload controls="" loop poster="6.jpg" webkit-playsinline="true" playsinline="true" x-webkit-airplay="allow" x5-playsinline x5-video-player-type="h5" x5-video-player-fullscreen="true" x5-video-orientation="portrait" > </video> </div> </div>

由于視頻是有寬高比的,這里給視頻的高度直接是外面盒子的高度*比例,就等于視頻的寬,為了防止視頻過寬超出屏幕,這里加一個max-width:100vw;限制一下,然后通過margin:0 auto;居中顯示,成功解決!
 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 依兰县| 扎兰屯市| 南宁市| 开封县| 郓城县| 乐昌市| 福州市| 永寿县| 当雄县| 保德县| 诸暨市| 东明县| 绥棱县| 高邮市| 左权县| 麦盖提县| 房产| 石屏县| 大英县| 遂昌县| 丰台区| 安福县| 防城港市| 太仓市| 林州市| 开封县| 西充县| 思南县| 历史| 乌鲁木齐市| 华亭县| 巴南区| 自治县| 敦煌市| 泸溪县| 商河县| 武陟县| 淮滨县| 册亨县| 连州市| 登封市|