css实战案例1:顶部搜索

代码样式:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<body>

		<div class="search_box">
			<!-- 搜索框-->
			<div class="search">搜索:目的地/酒店/航班</div>

			<a class="user">我的</a>
		</div>

	</body>
</html>


<style>
	a{
		text-decoration: none;
	}
	dic {
		box-sizing: border-box;
	}
	.search_box {
		position: fixed;
		top: 0;
		/*居中*/
		left: 50%;
		transform: translateX(-50%);
		/*transform 属性允许你旋转、缩放、倾斜或平移给定元素*/
		-webkit-transform: translateX(-50%);/*向左平移当前元素长度的一半*/
		/*兼容老浏览器写法*/
		width: 100%;
		min-width: 320px;
		max-width: 540px;
		height: 44px;
		display: flex;
	}

	.search {
		flex: 1; /*左边占一份*/
		height: 26px;
		line-height: 26px;
		border: 1px solid #ccc;
		margin: 7px 10px;
		border-radius: 5px;
		position: relative;
		padding-left: 25px;
		color: #707070;
		font-size: 13px;
		/*下边框阴影:x 偏移量 | y 偏移量 | 阴影模糊半径 | 阴影颜色*/
		box-shadow: 0px 2px 4px rgba(0, 0, 0,.4);
	}
	.search::before {
		content: "";
		background: url(img/search.png) no-repeat center;
		width: 20px;
		height: 20px;
		background-size:20px;
		
		/*使用绝对定位,让他浮出来,不占一行,因为后面还有文字*/
		top: 3px;
		left: 3px;
		position: absolute; /*默认是相对整个body的位置进行绝对定位,如果父级元素加了position: relative,就是相对于父级的位置进行绝对定位*/
	}
	
	
	/* CSS 伪元素 :before 和 :after 是两个强大的工具,它们允许我们在选定元素的前后插入内容,而无需修改HTML结构。这些伪元素通常与 content 属性一起使用,可以插入文本或图像。*/
	.user::before {
		content:"";
		background: url(img/my.png) no-repeat center;
		width: 17px;
		height: 17px;
		background-size:17px;
		display:block; /*此元素将显示为块级元素,此元素前后会带有换行符。*/
		margin: 0 auto; /*水平居中*/
	}
	.user {
		width: 44px;
		height: 44px;
		text-align: center;/*里面的文字水平居中*/
		font-size: 10px;
		padding-top: 8px;
		color: #1296db;
	}

</style>

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-19 05:24:03       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-19 05:24:03       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-19 05:24:03       58 阅读
  4. Python语言-面向对象

    2024-07-19 05:24:03       69 阅读

热门阅读

  1. 交易积累-OSC

    2024-07-19 05:24:03       20 阅读
  2. 【16】时间单位换算

    2024-07-19 05:24:03       17 阅读
  3. 10 - FFmpeg - 重采样 - SoftwareResampleExample

    2024-07-19 05:24:03       17 阅读
  4. npm install时报错 reason: connect ETIMEDOUT

    2024-07-19 05:24:03       15 阅读
  5. npm相关指令

    2024-07-19 05:24:03       22 阅读
  6. 【Unity】RPG2D龙城纷争(十四)存档系统

    2024-07-19 05:24:03       18 阅读
  7. 点的距离(C++)

    2024-07-19 05:24:03       19 阅读
  8. itextpdf 使用demo

    2024-07-19 05:24:03       26 阅读
  9. chatglm2-6b-prompt尝试

    2024-07-19 05:24:03       20 阅读
  10. IKM 外企常用

    2024-07-19 05:24:03       20 阅读
  11. Linux源码阅读笔记13-进程通信组件上

    2024-07-19 05:24:03       20 阅读
  12. 分布式唯一id的7种方案

    2024-07-19 05:24:03       24 阅读