您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)css如何實(shí)現(xiàn)一個(gè)元素高度固定寬度按比例顯示效果,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
解決后效果如圖:
紅框標(biāo)注的即是我在上面高度比例固定的范圍內(nèi)寬度自適應(yīng)的效果;
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="h6" x5-video-player-fullscreen="true" x5-video-orientation="portrait" > </video> </div> </div>
由于視頻是有寬高比的,這里給視頻的高度直接是外面盒子的高度*比例,就等于視頻的寬,為了防止視頻過(guò)寬超出屏幕,這里加一個(gè)max-width:100vw;限制一下,然后通過(guò)margin:0 auto;居中顯示,成功解決!
關(guān)于“css如何實(shí)現(xiàn)一個(gè)元素高度固定寬度按比例顯示效果”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。