如何使用CSS创建响应式浮动元素?
要使用CSS创建响应式浮动元素,代码如下-
示例
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
.floatRight, .floatLeft {
color: white;
font-size: 20px;
padding: 10px;
font-weight: 500;
}
.floatRight {
background-color: rgb(0, 2, 95);
float: right;
}
.floatLeft {
background-color: rgb(85, 0, 74);
float: left;
}
@media (max-width: 768px) {
.floatRight {
float: left;
}
.floatLeft {
float: right;
}
}
</style>
</head>
<body>
<h1>Responsive Float Example</h1>
<h2>The floats will swap their position on smaller screens</h2>
<div class="clearfix">
<div class="floatRight">Float Right ></div>
<div class="floatLeft">Float Left <</div>
<br />
</div>
</body>
</html>输出结果
上面的代码将产生以下输出-
在调整屏幕大小时,浮子将按以下方式交换位置-
热门推荐
1 潜能开发训练狗狗
2 狗狗多会训练好
3 扣篮训练狗狗
5 狗狗不训练
6 少儿柔术训练狗狗
8 训练好狗狗
9 训练狗狗怎么训
10 狗狗训练猫咪
11 狗狗训练地点
12 两个多月的狗狗怎么训练
13 怎么训练狗狗去厕所拉屎
14 狗狗怎样训练大小便
15 训练狗狗母
16 怎么训练狗狗坐下和握手
17 近视训练狗狗
18 狗狗倒的训练