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

首頁 > 開發 > CSS > 正文

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

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

用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;居中顯示,成功解決!
 

總結

以上所述是小編給大家介紹的css實現一個元素高度固定寬度按比例顯示效果,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 北票市| 仁化县| 合阳县| 鹤峰县| 志丹县| 日照市| 武山县| 汉沽区| 志丹县| 遂昌县| 军事| 盖州市| 西畴县| 清水河县| 铜陵市| 金门县| 英山县| 荆门市| 仙居县| 正蓝旗| 绿春县| 寿光市| 化隆| 惠水县| 河南省| 柘城县| 五寨县| 观塘区| 沈丘县| 景泰县| 集安市| 同江市| 平舆县| 正阳县| 汉寿县| 连云港市| 孟村| 宝丰县| 日喀则市| 巩义市| 六枝特区|