1. 予備知識
CSS ボックスの折りたたみと解決策
主流のソリューション:
外部ボックスの after 疑似クラスを追加し、float をクリアするように clear 属性を設定します。
父盒子::after {
content: "";
/* 清除两边的浮动 */
clear: both;
/* 也可以使用display:table; */
display: block;
/* 兼容IE浏览器 */
zoom: 1;
}
元のリンク: http://t.csdn.cn/5lxjm
余白設定
margin の省略表現プロパティは、単一の宣言内のすべての現在の要素または指定された要素の margin プロパティを設定します。この属性には 1 ~ 4 の値を指定できます。
マージンの書き方には以下の 4 通りがあります。
margin: 像素值1;
margin: 像素值1 像素值2;
margin: 像素值1 像素值2 像素值3;
margin: 像素值1 像素值2 像素值3 像素值4;
上記の 4 つの位置は、 margin-top -- margin-right -- margin-bottom -- margin -left、つまり「top - right -bottom - left」の順序です。次の略語は、上、右、下、左です。注意する必要があるのは、後者の 3 つのケースでは、デフォルトのピクセル値がある場合、ブラウザは「 bottom = top」および「left = right 」メソッドに従ってデフォルトのピクセルを自動的に割り当てるということです。
例えば:
「margin:20px;」は、4方向の余白が20pxであることを意味します。
「margin:20px 40px;」は、上が 20px、右が 40px であることを意味し、下と左はデフォルトなので、それぞれ 20px と 40px に自動的に設定されます。4番目の書き方「margin:20px 40px 20px 40px;」に変換します。
「margin:20px 40px 60px;」は、上が20px、右が40px、下が60pxという意味で、左がデフォルトなので自動的に40pxに設定されます。4番目の書き方「margin:20px 40px 60px 40px;」に変換されました。
なお、デフォルトの記述方法「margin:20px 40px 20px 60px;」では記述できない場合があります。この例では、上下は同じですが左右が異なるため、下をデフォルトにすることはできません。それ以外の場合は、「margin:20px 40px 60px 40px;」と同等になります。
浮く
float の最も典型的なアプリケーション: 複数のブロックレベルの要素を連続して表示できます。
Web ページ レイアウトの最初のルール: 垂直に配置された複数のブロック レベル要素は標準フローを探し、水平に配置された複数のブロック レベル要素はフロートを探します。
元のリンク: http://t.csdn.cn/23Tyq
border-radius の使用方法の詳細な説明
2. コード
インデックス.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="tit">
<h3>今天也有在认真生活</h3>
</div>
<div class="time-axis clearfix">
<div class="left">
<span class="dot"></span>
<span class="jiantou"></span>
<div class="con"></div>
</div>
<div class="right">
<span class="dot"></span>
<span class="jiantou"></span>
<div class="con"></div>
</div>
</div>
</body>
</html>
スタイル.css
body {
margin: 0;
background-image: linear-gradient(to right,#fdf1d8,#b1bbf9);
}
.tit {
width: 500px;
/* border: 2px solid red; */
margin: 50px auto 0px;
text-align: center;
font-size: 40px;
/* color: #b1bbf9; */
}
.clearfix::after {
content: "";
clear: both;
display: block;
}
.time-axis {
/* 右边盒子设为右浮动 最外层盒子的宽度+4 则右边盒子右移4px 使得时间轴对齐 */
width: 604px;
/* height:700px; */
/* border:2px solid red; */
/* 上右下左 左缺省 和右边保持一致 */
margin: 50px auto 10px;
}
.time-axis .left {
width: 300px;
/* height: 300px; */
/* background-color: beige; */
float: left;
border-right: 4px solid #b1bbf9;
position: relative;
}
.time-axis .right {
width: 300px;
/* height: 300px; */
/* background-color: azure; */
float: right;
border-left: 4px solid #b1bbf9;
position: relative;
}
.time-axis .dot {
width: 10px;
height: 10px;
display: block;
background-color: #fff;
border: 2px solid #b1bbf9;
border-radius: 7px;
position: absolute;
/* right:0的时候圆点到左盒子的最右边,为了使其在时间轴的正中间,需要继续右移圆点大小的一半(即7px)+时间轴的宽度一半(即2px) */
top: 50%;
margin-top: -7px;
}
.time-axis .left .dot {
right: -9px;
}
.time-axis .right .dot {
left: -9px;
}
.time-axis .jiantou {
width: 0px;
height: 0px;
/* background-color: red; */
display: block;
border: 20px solid transparent;
border-left: 20px solid white;
position: absolute;
right: -8px;
top: 50%;
margin-top: -20px;
}
.time-axis .right .jiantou {
border: 20px solid transparent;
border-right: 20px solid white;
position: absolute;
left: -8px;
}
.time-axis .con {
/* height: 200px; */
background-color: #fff;
padding: 15px;
border-radius: 20px;
text-align: center;
}
.time-axis .left .con {
margin-right: 30px;
}
.time-axis .right .con {
margin-left: 30px;
}
h3{
margin: 0;
}
.time-axis .con h3 {
/* border: 1px solid red; */
font-size: 400;
}
.time-axis .con h3 span {
font-size: 38px;
font-family:Arial, Helvetica, sans-serif;
color: #b1bbf9;
}