Heim  >  Artikel  >  Web-Frontend  >  几个简单的css设置问题:div居中,ul li不换行 ,内容超出自动变省略号等_html/css_WEB-ITnose

几个简单的css设置问题:div居中,ul li不换行 ,内容超出自动变省略号等_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:40:381514Durchsuche

1  div在页面居中的问题

    1)position值为relative时(相对定位),css设置属性margin:0 auto;(0 auto,表示上下边界为0,左右则根据宽度自适应相同值,即居中)即可。

    2)position值为relative时(绝对定位),css设置属性    text-align:center; left:50%;  margin-left:-500px;(左边距margin-left设置为当前div宽度的一半的负值即可).

   代码示例:

.page {    position:absolute;    width:1000px;    background-image:none;    text-align:center;    left:50%;    margin-left:-500px;}

    css负值结合z-index能实现一些很不错的东西,但是负值使用始终存在很大的隐患尤其在页面内容赋值时。

2   ul li 所有元素排列在一行的方式及其它

  ul作为我们最常用的列表元素,有时候我们想要让它下面的li都放置在同一行,

   1) 设置ul的list-style-type:none;(一般默认每列前面有黑圆点的,设置列表的格式为none,即可去掉每列前的圆点或方块。)

   2) 设置ul 和 li 的float:left;(左浮动,即每个元素从左至右单行排列)

  代码示例:

.tableclass ul{    float: left;    height: 50px;    left:30px;    line-height: 50px;    position: absolute;    list-style-type:none;}.tableclass ul li{    float:left;    width:100px; }

3  div内容太多,我们有时会需要将超出部分省略,也很简单

  1) 设置div的white-space: nowrap;(设置div内容不换行,保证一直在一行)  

  2) 设置div的overflow: hidden;(超出div的内容不显示)

  3) 设置div的text-overflow: ellipsis;(当文本溢出时的属性,ellipsis表示省略符号来代表被修剪的文本。)

代码示例:

 .videoname{  position:absolute;  left:25px;  height:48px;  width:160px;  top:5px;  font-size:15px;  font-family: Arial;  line-height:45px;  text-align:left;  white-space: nowrap;  overflow: hidden;  text-overflow: ellipsis;}

 

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn