首页上方搜索栏css该怎么定位

html-css010

首页上方搜索栏css该怎么定位,第1张

是不是要这种浮动效果?定位很简单的,主要是:position 这个。一种是绝对定位,相对于浏览器窗口进行定位,如下:

<div class="heaader"><img src="https://www.poscom.cn/static/image/default/logo-2.png" alt="www.poscom.cn"/></div>

<style>

.header {

    background-color: #3454d1

    height: 60px

    position: relative

    z-index: 199

    position: fixed

    width: 100%

    top: 0

}

</style>

一种是相对定位,相对于相对定位的元素

<div class="relative">

   <div class="absolute"><img src="https://www.poscom.cn/static/image/default/logo-2.png" alt="www.poscom.cn"/></div></div>

<style>

.relative{

    background-color: #3454d1

    height: 100px

    position: relative

    width: 100%

}

.absolute{

    position:absolute

    left:10pxtop:10px}

</style>

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(层叠样式表)_

这是使用搜索那个图的css代码

<!DOCTYPE HTML>

<html>

<head>

<meta charset="UTF-8">

<title>test</title>

<style type="text/css">

.ico{

display:block

width:80px

height:31px

background:url('load.jpg') no-repeat 0 -240px

}

</style>

</head>

<body>

<i class="ico"></i>

</body>

</html>