日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

css background 一半_CSS小技巧

發布時間:2025/3/11 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 css background 一半_CSS小技巧 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
點擊上方藍字 ?關注我們

左右布局

將內部的子元素加浮動,父元素清除浮動即可。

代碼:

DOCTYPE html><html><head><title>testtitle><style type="text/css">
.big{
width: 300px;
height: 300px;
background-color: #999;}
.smallOne{
width: 100px;
height: 100px;
background-color: red;
float: left;}
.smallTwo{
width: 100px;
height: 100px;
background-color: red;
float: right;}
.clearfix{
content: "";
display: block;
clear: both;}style>head><body><div class="big clearfix"><div class="smallOne">div><div class="smallTwo">div>div>body>html>
  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 31

  • 32

  • 33

  • 34

  • 35

效果:

左中右布局

?浮動 清除浮動

代碼:

DOCTYPE html><html><head><title>testtitle><style type="text/css">
.big{
width: 300px;
height: 300px;
background-color: #999;}
.smallOne{
width: 100px;
height: 100px;
background-color: red;
float: left;}
.smallTwo{
width: 100px;
height: 100px;
background-color: green;
float: left;}
.smallThree{
width: 100px;
height: 100px;
background-color: red;
float: left;}
.clearfix{
content: "";
display: block;
clear: both;}style>head><body><div class="big clearfix"><div class="smallOne">div><div class="smallTwo">div><div class="smallThree">div>div>body>html>
  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

  • 30

  • 31

  • 32

  • 33

  • 34

  • 35

  • 36

  • 37

  • 38

  • 39

  • 40

  • 41

  • 42

效果:

?水平居中

?內聯元素居中:

text-align: center;

代碼:

DOCTYPE html><html><head><title>testtitle><style type="text/css">
.big{
width: 200px;
height: 100px;
background-color: #999;
text-align: center;}style>head><body><div class="big"><span>我在這里span>div>body>html>
  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

效果圖:

?塊級元素居中:

margin:0 auto

代碼:

DOCTYPE html><html><head><title>testtitle><style type="text/css">
.big{
width: 200px;
height: 100px;
background-color: #999;
text-align: center;}
.small{
width: 100px;
height: 20px;
background-color: red;
margin: 0 auto;}style>head><body><div class="big"><div class="small">我在這里div>div>body>html>
  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

效果圖:

垂直居中

父元素高度確定的單行文本

設置 height = line-height

?代碼:

DOCTYPE html><html><head><title>testtitle><style type="text/css">
.big{
width: 200px;
height: 100px;
background-color: #aaa;
line-height: 100px;}style>head><body><div class="big">
這里是文本!div>body>html>
  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

效果圖:

塊級元素垂直居中

利用父元素相對定位,子元素絕對定位,并且處置、水平方向個偏移50%,子元素利用負值偏移自身寬度、長度的一半,這種方式同樣適用于水平居中。

代碼:

DOCTYPE html><html><head><title>testtitle><style type="text/css">
.big{
height: 200px;
width: 200px;
background-color: red;
position: relative;}
.small{
height: 50px;
width: 50px;
background-color: black;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);}style>head><body><div class="big"><div class="small">div>div>body>html>
  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

  • 11

  • 12

  • 13

  • 14

  • 15

  • 16

  • 17

  • 18

  • 19

  • 20

  • 21

  • 22

  • 23

  • 24

  • 25

  • 26

  • 27

  • 28

  • 29

效果圖:

更多精彩請繼續關注小編了解哦!

計算機畢業設計(源程序+論文+開題報告+文獻綜述+翻譯+答辯稿)

聯系QQ:2932963541進行咨詢

網站地址:http://www.webtmall.com/掃碼關注最新動態點擊此處“閱讀全文”查看更多內容

總結

以上是生活随笔為你收集整理的css background 一半_CSS小技巧的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。