CSS学习
date
Apr 10, 2023
slug
css-0
author
status
Public
tags
CSS
summary
type
Post
thumbnail
category
updatedAt
Apr 10, 2023 08:21 AM
结合代码
<!DOCTYPE html>
<html>
<head>
<style>
* {
box-sizing: border-box;
}
/* box-sizing 属性允许我们在框的总宽度(和高度)中包括内边距和边框,确保内边距留在框内而不会破裂。*/
body {
margin: 0;
}
/*外边距*/
.header {
background-color: #2196F3;
/*背景颜色*/
color: white;
/*字体颜色*/
text-align: center;
/*文字居中*/
padding: 15px;
/*内边距*/
}
.footer {
background-color: #444;
color: white;
padding: 15px;
}
.topmenu {
list-style-type: none;
margin: 0;
padding: 0;
/*用于删除标记/项目符号。请注意,列表还拥有默认的外边距和内边距。要删除此内容,请在 <ul> 或 <ol> 中添加 margin:0 和 padding:0*/
overflow: hidden;
/*如果使用 hidden 值,溢出会被裁剪,其余内容被隐藏:*/
background-color: #777;
}
.topmenu li {
float: left;
/*规定哪些元素可以在清除的元素旁边以及在哪一侧浮动。*/
}
.topmenu li a {
display: inline-block;
color: white;
text-align: center;
padding: 16px;
text-decoration: none;
/* 不带下划线 */
}
.topmenu li a:hover {
/*鼠标悬浮效果*/
background-color: #222;
}
.topmenu li a.active {
/*点击效果*/
color: white;
background-color: #4CAF50;
}
.column {
float: left;
padding: 15px;
}
.clearfix::after {
/*伪元素*/
content: "";
clear: both;
display: table;
}
.sidemenu {
width: 25%;
}
.content {
width: 75%;
}
.sidemenu ul {
list-style-type: none;
margin: 0;
padding: 0;
}
.sidemenu li a {
margin-bottom: 4px;
display: block;
padding: 8px;
background-color: #eee;
text-decoration: none;
color: #666;
}
.sidemenu li a:hover {
background-color: #555;
color: white;
}
.sidemenu li a.active {
background-color: #008CBA;
color: white;
}
</style>
</head>
<body>
<ul class="topmenu">
<li><a href="#home" class="active">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
<div class="clearfix">
<div class="column sidemenu">
<ul>
<li><a href="#flight">The Flight</a></li>
<li><a href="#city" class="active">The City</a></li>
<li><a href="#island">The Island</a></li>
<li><a href="#food">The Food</a></li>
<li><a href="#people">The People</a></li>
<li><a href="#history">The History</a></li>
<li><a href="#oceans">The Oceans</a></li>
</ul>
</div>
<div class="column content">
<div class="header">
<h1>The City</h1>
</div>
<h1>Chania</h1>
<p>Chania is the capital of the Chania region on the island of Crete. The city can be divided in two parts, the old town and the modern city.</p>
<p>You will learn more about responsive web pages in a later chapter.</p>
</div>
</div>
<div class="footer">
<p>Footer Text</p>
</div>
</body>
</html>
效果如下