在CSS中固定定位的问题

html-css015

在CSS中固定定位的问题,第1张

1、绝对定位 和 固定定位 的元素若没有设置 top/right/left/bottom 的值。其位置为原来在文档流中的位置。其他文档流元素会占据其原来位置。

要使绝对定位或固定定位的元素水平居中,需要设置其 width 为固定值,并且 left: 0right: 0。

2、绝对定位 和 固定定位 的元素,若其宽度 width 或高度 height 的单位为 百分比 ,宽度和高度值是相对于其基于定位的元素计算的。(在使用一些stick插件时尤其要注意这点)。

扩展资料:

CSS技巧 

1、div的垂直居中问题 vertical-align:middle将行距增加到和整个DIV一样高 line-height:200px然后插入文字,就垂直居中了。缺点是要控制内容不要换行 

2、 margin加倍的问题 设置为float的div在ie下设置的margin会加倍。这是一个ie6都存在的bug。解决方案是在这个div里面加上 display:inline例如: <#div id=”imfloat”>相应的css为 #IamFloat{ float:leftmargin:5px/*IE下理解为10px*/ display:inline/*IE下再理解为5px*/} 

3、浮动ie产生的双倍距离 #box{ float:leftwidth:100pxmargin:0 0 0 100px//这种情况之下IE会产生200px的距离 display:inline//使浮动忽略} 这里细说一下block与inline两个元素:block元素的特点是,总是在新行上开始,高度,宽度,行高,边距都可以控制(块元素)。

参考资料:百度百科 CSS(层叠样式表)_

nth-child可以选择单个元素,也可以实现一个范围,如: 123456上面是一个列表1.选择单个标签元素(指定序列的单个元素).li:nth-child(1){ color: red}执行上面的CSS,1在界面上面表现为红色2.选择一个范围的标签元素(偶数序列的元素)

重点是go-top的CSS定义:

div.go-top {display: none

opacity: 0.6

z-index: 999999

position: fixed

bottom: 113px

left: 90%

margin-left: 40px

border: 1px solid #a38a54

width: 38px

height: 38px

background-color: #eddec2

border-radius: 3px

cursor: pointer}div.go-top:hover {opacity: 1

filter: alpha(opacity=100)}div.go-top div.arrow {position: absolute

left: 10px

top: -1px

width: 0

height: 0

border: 9px solid transparent

border-bottom-color: #cc3333}div.go-top div.stick {position: absolute

left: 15px

top: 15px

width: 8px

height: 14px

display: block

background-color: #cc3333

-webkit-border-radius: 1px

-moz-border-radius: 1px

border-radius: 1px}

使用fixed定位,让按钮始终出现在右下角,通过设定left:90%可以使按钮在右方出现,但又不会太紧贴滚动条。

按钮默认不可见,当滚动页面到一定高度后,按钮出现,这里用jQuery实现

$(function() {$(window).scroll(function() {if ($(window).scrollTop() >1000)$('div.go-top').show() else

$('div.go-top').hide()

}) $('div.go-top').click(function() {$('html, body').animate({scrollTop: 0}, 1000)

})

})

当按下按钮时,有动画效果返回顶部