如何让div中的文字垂直,水平居中;不使用line-height;随着高度的变化而变化

需要加入相对定位或是 绝对定位
  
position: fixed; 或是 position: absolute;

在父元素中加入:align-items:center; display: -webkit-flex;(垂直居中)         justify-content:center; display: -webkit-flex;(水平居中)

在一个是: transform: translate(-50%, -50%);兼容性强
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);

使用的时候同样需要绝对相对或是绝对定位



更多方法请参考:https://www.calamus.xyz/2018/07/06/css-center/

 文本超出用点表示

在一个div中,超出一行内容的部分用三个点表示

text-overflow:ellipsis;overflow:hidden;white-space:nowrap;

在一个div 中 超出两行内容用三个点表示

   white-space: normal;
    word-break: break-all;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
 
让input的光标自动聚焦,并移动到指定位置

//光标放在最后 $("#文本框ID").textFocus();光标放在第二个字符后面 $("#文本框ID").textFocus(2);
(function($){
  $.fn.textFocus=function(v){
    var range,len,v=v===undefined?0:parseInt(v);
    this.each(function(){
      if($.browser.msie){
      range=this.createTextRange();
      v===0?range.collapse(false):range.move("character",v);
      range.select();
    }else{
      len=this.value.length;
      v===0?this.setSelectionRange(len,len):this.setSelectionRange(v,v);
    }
    this.focus();
  });
  return this;
 }
})(jQuery);

另一种简单的方法,代码如下:

    var t=$(“#”+id).val();  
    $(“#”+id).val(“”).focus().val(t);  

 

获取某个div距离窗体顶端的距离:

var wst =  $('#myTable').offset().top - $(window).scrollTop();
原文地址:https://www.cnblogs.com/han-guang-xue/p/10376701.html