前端小技巧总结 v1.0.0

本文介绍了一些CSS和JS的实用技巧,包括解决CSS浮动父级塌陷问题、实现footer始终处于页面底部的方法、长文本以省略号显示并悬浮显示完整内容、iframe和textarea的高度自适应、以及获取iframe内的元素等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CSS部分

1.浮动父级塌陷

.clearFix:after{visibility: hidden;display: block;font-size: 0;content: '.';clear:both;height: 0;}


2.footer在页面底部

<!DOCTYPE html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <style>
        html,body{
            height:100%;
        }
        .container{
            height: 100%;
            position: relative;
        }
        .content{
            padding-bottom:60px;
        }
        .footer{
            width: 100%;
            height: 60px;
            background: #ccc;
            position: absolute;
            bottom: 0;
        }
    </style>
</head>

<body>
<div class="container">
    <div class="header">
        this is header
    </div>
    <div class="content">
        this is content
    </div>
    <div class="footer">
        This is footer
    </div>
</div>
<script type="text/javascript">


</script>
</body>
</html>


3.长文本以省略号显示

以table td为例

       table{
            table-layout: fixed;
        }
        table>tbody>tr>td{
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap; /*强制一行显示所有内容*/
        }

悬浮显示

 table>tbody>tr>td:hover{
            overflow: visible;
            white-space: normal; 
        }


JS部分

1.iframe 高度自适应

parent.document.all('staffList').style.height = document.body.scrollHeight  + 'px'; 

2.textarea高度自适应

document.addEventListener("DOMContentLoaded",function(){  
         var elem=document.getElementById("#id");  
         elem.style.height = elem.style.scrollHeight + "px";  
     },false)  

3.获取iframe里面的元素

  $('iframe').contentWindow.document;

4.YYYY-MM-DD HH:MM:SS格式的日期


    Number.prototype.padLeft = function(base,chr){
        var  len = (String(base || 10).length - String(this).length)+1;
        return len > 0? new Array(len).join(chr || '0')+this : this;
    }

        var d = new Date,
                dformat = [ (d.getMonth()+1).padLeft(),
                            d.getDate().padLeft(),
                            d.getFullYear()].join('-')+
                        ' ' +
                        [ d.getHours().padLeft(),
                            d.getMinutes().padLeft(),
                            d.getSeconds().padLeft()].join(':');
    



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值