CSS-文字环绕浮动、行内块分页、三角强化妙用、伪元素选择器

文字环绕浮动

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文字环绕浮动效果</title>
	<style>
		.container {
		  width: 300px; /* 根据需要设置容器的宽度 */
		}
		
		img {
		  float: left; /* 图片向左浮动 */
		  margin-right: 10px; /* 可根据需要设置图片与文本之间的间距 */
		  width: 100px;
		  height: 100px;
		}
		
		p {
		  overflow: hidden; /* 清除浮动 */
		}
		
	</style>
</head>

<body>

	<div class="container">
	  <img src="img/7bf51d9fa40156eccb6c7cec218996368dc72872.jpg" alt="Image">
	  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc ut dapibus luctus, velit mauris aliquam tellus, sit amet luctus nunc nisl id justo.</p>
	<p>如果他正在受苦,他会被考虑帮助他。但现在,就像他在口袋里哭一样,他想把胡子剪掉,所以他现在必须哭。</p>
	</div>
	
</body>

</html>

行内块分页

html 复制代码
<!DOCTYPE html>
<html lang="cn-ZH">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>行内块分页</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        li {
            list-style: none;
            display: inline-block;
            width: 45px;
            line-height: 45px;
            height: 45px;
            background-color: silver;
            border-radius: 15px;
            border: 1px solid wheat;
        }
        
        li:hover {
            box-shadow: 0 0 7px 3px rgba(0, 0, 0, 0.6);
        }
        
        ul .s {
            list-style: none;
            display: inline-block;
            width: 100px;
            line-height: 45px;
            height: 45px;
            background-color: silver;
            border-radius: 10px;
            border: 1px solid wheat;
        }
        
        .box {
            font-size: 16px;
            font-weight: 600;
            margin: 100px auto;
            text-align: center;
        }
        
        .box .two,
        .box .three {
            background-color: white;
        }
    </style>
</head>

<body>
    <div class="box">
        <ul>
            <li class="s">&lt;&lt;上一页</li>
            <li>1</li>
            <li class="two">2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
            <li class="three">...</li>
            <li class="s">下一页&gt;&gt;</li>
            <span style="width: 200x;height: 40px;display: inline-block;
                font-weight: 400;
            ">到第<input style="width: 40px;height: 30px;border: 1px solid;margin: 0 5px;" type="text">页
            <input type="button" style="width: 40px;height: 30px;"  value="确定"></span>

        </ul>

    </div>


</body>

</html>

三角强化的妙用

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>三角形</title>

    <style>
        .box {
            width: 0px;
            height: 0px;
            border-top: 50px solid transparent;
            border-bottom: 0px solid yellow;
            border-left: 0px solid violet;
            border-right: 25px solid white;
            position: relative;
            right: 50px;
            float: left;
        }
        
        .box2 {
            width: 100px;
            height: 50px;
            float: left;
            position: relative;
            right: 50px;
            background-color: white;
            line-height: 50px;
            text-align: center;
            color: darkgray;
            font-weight: 800;
        }
        
        .box3 {
            width: 150px;
            height: 50px;
            line-height: 50px;
            text-align: left;
            padding-left: 50px;
            float: left;
            color: white;
            font-weight: 800;
            background-color: tomato;
        }
        
        .nav {
            position: absolute;
            border: 1px solid tomato;
        }
    </style>


</head>

<body>

    <div class="nav">
        <div class="box3">
            <span> $1405</span>
        </div>
        <div class="box"></div>
        <div class="box2">
            <span><del>$1243.62</del></span>
        </div>
    </div>


</body>

</html>

伪类选择器

伪类选择器是CSS中一种特殊的选择器,用于选择元素的特定状态或位置。通过使用伪类选择器,可以为元素的不同状态或位置应用不同的样式。以下是一些常见的伪类选择器及其功能:

  • :hover:选择鼠标悬停在元素上时的状态。
css 复制代码
a:hover {
  color: red;
}

当鼠标悬停在链接上时,链接的颜色将变为红色。

  • :active:选择元素被激活(被点击)时的状态。
css 复制代码
button:active {
 background-color: yellow;
}

当按钮被点击时,按钮的背景颜色将变为黄色。

  • :focus:选择元素获得焦点时的状态。
css 复制代码
input:focus {
  border-color: blue;
}

当输入框获得焦点时,输入框的边框颜色将变为蓝色。

  • :first-child:选择作为其父元素的第一个子元素的元素。
css 复制代码
ul li:first-child {
  font-weight: bold;
}

选择ul元素下的第一个li元素,并将其字体加粗。

  • :nth-child(n):选择作为其父元素的第n个子元素的元素。
css 复制代码
ul li:nth-child(odd) {
  background-color: lightgray;
}

选择ul元素下的奇数位置的li元素,并将其背景颜色设置为浅灰色。

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>伪元素选择器</title>
    <style>
        div {
            width: 400px;
            height: 400px;
            background-color: antiquewhite;
        }
        
        div::after {
            content: '我在后面';
        }
        
        div::before {
            content: '我在前面';
        }
		
		 a:hover {
		      color: red;
		    }
		
		    button:active {
		      background-color: yellow;
		    }
		
		    input:focus {
		      border-color: blue;
		    }
		
		    ul li:first-child {
		      font-weight: bold;
		    }
		
		    ul li:nth-child(odd) {
		      background-color: lightgray;
		    }
    </style>
</head>

<body>

    <div>
        哇哇哇哇
		<br />
		
		<a href="#">Hover me</a>
		  <br><br>
		  <button>Click me</button>
		  <br><br>
		  <input type="text">
		  <br><br>
		  <ul>
		    <li>Item 1</li>
		    <li>Item 2</li>
		    <li>Item 3</li>
		    <li>Item 4</li>
		    <li>Item 5</li>
		  </ul>
		
    </div>
</body>

</html>

当鼠标悬停在链接上时,链接的颜色将变为红色。当按钮被点击时,按钮的背景颜色将变为黄色。当输入框获得焦点时,输入框的边框颜色将变为蓝色。列表中的第一个li元素的字体将加粗,奇数位置的li元素的背景颜色将设置为浅灰色。

相关推荐
90后的晨仔1 分钟前
在macOS上无缝整合:为Claude Code配置魔搭社区免费API完全指南
前端
沿着路走到底32 分钟前
JS事件循环
java·前端·javascript
子春一21 小时前
Flutter 2025 可访问性(Accessibility)工程体系:从合规达标到包容设计,打造人人可用的数字产品
前端·javascript·flutter
白兰地空瓶1 小时前
别再只会调 API 了!LangChain.js 才是前端 AI 工程化的真正起点
前端·langchain
jlspcsdn2 小时前
20251222项目练习
前端·javascript·html
行走的陀螺仪2 小时前
Sass 详细指南
前端·css·rust·sass
爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ2 小时前
React 怎么区分导入的是组件还是函数,或者是对象
前端·react.js·前端框架
LYFlied3 小时前
【每日算法】LeetCode 136. 只出现一次的数字
前端·算法·leetcode·面试·职场和发展
子春一23 小时前
Flutter 2025 国际化与本地化工程体系:从多语言支持到文化适配,打造真正全球化的应用
前端·flutter
QT 小鲜肉3 小时前
【Linux命令大全】001.文件管理之file命令(实操篇)
linux·运维·前端·网络·chrome·笔记