前端-常用样式组合 (自用)

1.css控制文字超出隐藏

//HTML
名字刚好
//CSS样式
 span{width:50px; display:inline-block;overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}

样式解析
overflow: hidden
overflow 属性规定当内容溢出元素框时发生的事情。这个属性定义溢出元素内容区的内容会如何处理。hidden 表示内容会被修剪,并且剪掉的内容是不可见的。

white-space: nowrap
规定文本不进行换行。white-space 属性设置如何处理元素内的空白。nowrap 表示文本不会换行,文本会在在同一行上继续,直到遇到
标签为止。

text-overflow: ellipsis
text-overflow 属性规定当文本溢出包含元素时发生的事情。ellipsis 表示显示省略符号来代表被修剪的文本。

width:50px
width 属性设置div的长度。

word-break: break-all
表示文本长度超过就自动换行

2.js 阻止事件冒泡

e.stopPropagation();

3.js代码操作浏览器cookie

//写cookies 

function setCookie(name,value) 
{ 
    var Days = 30; 
    var exp = new Date(); 
    exp.setTime(exp.getTime() + Days*24*60*60*1000); 
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); 
} 

//读取cookies 
function getCookie(name) 
{ 
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
 
    if(arr=document.cookie.match(reg))
 
        return unescape(arr[2]); 
    else 
        return null; 
} 

//删除cookies 
function delCookie(name) 
{ 
    var exp = new Date(); 
    exp.setTime(exp.getTime() - 1); 
    var cval=getCookie(name); 
    if(cval!=null) 
        document.cookie= name + "="+cval+";expires="+exp.toGMTString(); 
} 
//使用示例 
setCookie("name","hayden"); 
alert(getCookie("name")); 

4. 我只想让缩略图在div中完全居中展示

前端-常用样式组合 (自用)_第1张图片

.img-show{width:100px;height:100px;border:1px solid #ccc;overflow:hidden;float: right;margin-right: 0px;margin-top:-58px;text-align:center;line-height:94px;}
.img-show img{max-width:100px;max-height:100px;}

 

你可能感兴趣的:(CSS)