如何修复html和css中的ul代码列表



我需要将无序列表居中,并添加文本页眉和页脚,同时保持列表项左对齐。

body {
margin: 0;
padding: 0;
background: #ccc;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
@media (max-width: 600px) {
ul {
transform: scale(0.6);
}
}
@media (min-width: 601px) and (max-width: 700px) {
ul {
transform: scale(0.7);
}
}
@media (min-width: 701px) and (max-width: 800px) {
ul {
transform: scale(0.8);
}
}
ul {
margin: 0;
padding: 0;
list-style: none;
display: flex;
}
ul li {
margin: 0 40px;
}
ul li a .fa {
font-size: 40px;
color: #555;
line-height: 80px;
transition: 0.5s;
}
ul li a {
position: relative;
display: block;
width: 80px;
height: 80px;
background: #fff;
text-align: center;
transform: perspective(1000px) rotate(-30deg) skew(25deg) translate(0,0);
transition: 0.5s;
box-shadow: -20px 20px 10px rgba(0, 0, 0, 0.5);
}
ul li a::before {
content: "";
position: absolute;
top: 10px;
left: -20px;
height: 100%;
width: 20px;
background: #b2b2b2;
transition: 0.5s;
transform: rotate(0deg) skewY(-45deg);
}
ul li a::after {
content: "";
position: absolute;
bottom: -20px;
left: -10px;
height: 20px;
width: 100%;
background: #e5e5e5;
transition: 0.5s;
transform: rotate(0deg) skewX(-45deg);
}
ul li a:hover {
transform: perspective(1000px) rotate(-30deg) skew(25deg) translate(20px,-20px);
box-shadow: -50px 50px 50px rgba(0, 0, 0, 0.5);
}
ul li:hover .fa {
color: #fff;
}
ul li:hover:nth-child(1) a {
background-color: #3b5999;
}
ul li:hover:nth-child(1) a::before {
background-color: #2f477a;
}
ul li:hover:nth-child(1) a::after {
background-color: #4e69a3;
}
ul li:hover:nth-child(2) a {
background-color: #55acee;
}
ul li:hover:nth-child(2) a::before {
background-color: #4489be;
}
ul li:hover:nth-child(2) a::after {
background-color: #66b4ef;
}
ul li:hover:nth-child(3) a {
background-color: #dd4b39;
}
ul li:hover:nth-child(3) a::before {
background-color: #b03c2d;
}
ul li:hover:nth-child(3) a::after {
background-color: #e05d4c;
}
ul li:hover:nth-child(4) a {
background-color: #0077b5;
}
ul li:hover:nth-child(4) a::before {
background-color: #005f90;
}
ul li:hover:nth-child(4) a::after {
background-color: #1984bc;
}
ul li:hover:nth-child(5) a {
background-color: #e4405f;
}
ul li:hover:nth-child(5) a::before {
background-color: #b6334c;
}
ul li:hover:nth-child(5) a::after {
background-color: #e6536f;
}
<script src="https://kit.fontawesome.com/9e3f22ff10.js" crossorigin="anonymous"></script>
<ul>
<li><a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a></li>
<li><a href="#"><i class="fa fa-twitter" aria-hidden="true"></i></a></li>
<li><a href="#"><i class="fa fa-google-plus" aria-hidden="true"></i></a></li>
<li><a href="#"><i class="fa fa-linkedin" aria-hidden="true"></i></a></li>
<li><a href="#"><i class="fa fa-instagram" aria-hidden="true"></i></a></li>
</ul>

当我添加了一个标题或文本写在图标的左侧,并且不能在顶部或中心移动时,我已经在html标签中输入了它们,而body标签也不起的作用

希望这能解决你的问题,但你必须添加一些额外的css,使其完全符合你的需求

body {
margin: 0;
padding: 0;
background: #ccc;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
@media (max-width: 600px) {
ul {
transform: scale(0.6);
}
}
@media (min-width: 601px) and (max-width: 700px) {
ul {
transform: scale(0.7);
}
}
@media (min-width: 701px) and (max-width: 800px) {
ul {
transform: scale(0.8);
}
}
ul {
margin: 0;
padding: 0;
list-style: none;
display: flex;

}
ul li {
margin: 0 40px;
position: relative;
}
ul li p {
position: absolute;
top: -8px;
left: -8px;
z-index: 10;
transform: rotate(-33deg);
}
ul li a .fa {
font-size: 40px;
color: #555;
line-height: 80px;
transition: 0.5s;
}
ul li a {
position: relative;
display: block;
width: 80px;
height: 80px;
background: #fff;
text-align: center;
transform: perspective(1000px) rotate(-30deg) skew(25deg) translate(0,0);
transition: 0.5s;
box-shadow: -20px 20px 10px rgba(0, 0, 0, 0.5);
}
ul li a::before {
content: "";
position: absolute;
top: 10px;
left: -20px;
height: 100%;
width: 20px;
background: #b2b2b2;
transition: 0.5s;
transform: rotate(0deg) skewY(-45deg);
}
ul li a::after {
content: "";
position: absolute;
bottom: -20px;
left: -10px;
height: 20px;
width: 100%;
background: #e5e5e5;
transition: 0.5s;
transform: rotate(0deg) skewX(-45deg);
}
ul li a:hover {
transform: perspective(1000px) rotate(-30deg) skew(25deg) translate(20px,-20px);
box-shadow: -50px 50px 50px rgba(0, 0, 0, 0.5);
}
ul li:hover .fa {
color: #fff;
}
ul li:hover:nth-child(1) a {
background-color: #3b5999;
}
ul li:hover:nth-child(1) a::before {
background-color: #2f477a;
}
ul li:hover:nth-child(1) a::after {
background-color: #4e69a3;
}
ul li:hover:nth-child(2) a {
background-color: #55acee;
}
ul li:hover:nth-child(2) a::before {
background-color: #4489be;
}
ul li:hover:nth-child(2) a::after {
background-color: #66b4ef;
}
ul li:hover:nth-child(3) a {
background-color: #dd4b39;
}
ul li:hover:nth-child(3) a::before {
background-color: #b03c2d;
}
ul li:hover:nth-child(3) a::after {
background-color: #e05d4c;
}
ul li:hover:nth-child(4) a {
background-color: #0077b5;
}
ul li:hover:nth-child(4) a::before {
background-color: #005f90;
}
ul li:hover:nth-child(4) a::after {
background-color: #1984bc;
}
ul li:hover:nth-child(5) a {
background-color: #e4405f;
}
ul li:hover:nth-child(5) a::before {
background-color: #b6334c;
}
ul li:hover:nth-child(5) a::after {
background-color: #e6536f;
}
<script src="https://kit.fontawesome.com/9e3f22ff10.js" crossorigin="anonymous"></script>
<ul>
<li>
<p>facebook</p>
<a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a></li>
<li>
<p>twitter</p>
<a href="#"><i class="fa fa-twitter" aria-hidden="true"></i></a></li>
<li>
<p>google</p>
<a href="#"><i class="fa fa-google-plus" aria-hidden="true"></i></a></li>
<li>
<p>linkedin</p>
<a href="#"><i class="fa fa-linkedin" aria-hidden="true"></i></a></li>
<li>
<p>instagram</p>
<a href="#"><i class="fa fa-instagram" aria-hidden="true"></i></a></li>
</ul>

ul元素之前和之后添加p元素,然后使用css进行样式设置:

body {
background: #ccc;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
height: 100vh;
gap: 50px;
}
p {
text-align: center;
}

下面是一个完整的示例

body {
margin: 0;
padding: 0;
background: #ccc;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
height: 100vh;
gap: 50px;
}
p {
text-align: center;
}
@media (max-width: 600px) {
ul {
transform: scale(0.6);
}
}
@media (min-width: 601px) and (max-width: 700px) {
ul {
transform: scale(0.7);
}
}
@media (min-width: 701px) and (max-width: 800px) {
ul {
transform: scale(0.8);
}
}
ul {
margin: 0;
padding: 0;
list-style: none;
display: flex;
}
ul li {
margin: 0 40px;
}
ul li a .fa {
font-size: 40px;
color: #555;
line-height: 80px;
transition: 0.5s;
}
ul li a {
position: relative;
display: block;
width: 80px;
height: 80px;
background: #fff;
text-align: center;
transform: perspective(1000px) rotate(-30deg) skew(25deg) translate(0,0);
transition: 0.5s;
box-shadow: -20px 20px 10px rgba(0, 0, 0, 0.5);
}
ul li a::before {
content: "";
position: absolute;
top: 10px;
left: -20px;
height: 100%;
width: 20px;
background: #b2b2b2;
transition: 0.5s;
transform: rotate(0deg) skewY(-45deg);
}
ul li a::after {
content: "";
position: absolute;
bottom: -20px;
left: -10px;
height: 20px;
width: 100%;
background: #e5e5e5;
transition: 0.5s;
transform: rotate(0deg) skewX(-45deg);
}
ul li a:hover {
transform: perspective(1000px) rotate(-30deg) skew(25deg) translate(20px,-20px);
box-shadow: -50px 50px 50px rgba(0, 0, 0, 0.5);
}
ul li:hover .fa {
color: #fff;
}
ul li:hover:nth-child(1) a {
background-color: #3b5999;
}
ul li:hover:nth-child(1) a::before {
background-color: #2f477a;
}
ul li:hover:nth-child(1) a::after {
background-color: #4e69a3;
}
ul li:hover:nth-child(2) a {
background-color: #55acee;
}
ul li:hover:nth-child(2) a::before {
background-color: #4489be;
}
ul li:hover:nth-child(2) a::after {
background-color: #66b4ef;
}
ul li:hover:nth-child(3) a {
background-color: #dd4b39;
}
ul li:hover:nth-child(3) a::before {
background-color: #b03c2d;
}
ul li:hover:nth-child(3) a::after {
background-color: #e05d4c;
}
ul li:hover:nth-child(4) a {
background-color: #0077b5;
}
ul li:hover:nth-child(4) a::before {
background-color: #005f90;
}
ul li:hover:nth-child(4) a::after {
background-color: #1984bc;
}
ul li:hover:nth-child(5) a {
background-color: #e4405f;
}
ul li:hover:nth-child(5) a::before {
background-color: #b6334c;
}
ul li:hover:nth-child(5) a::after {
background-color: #e6536f;
}
<script src="https://kit.fontawesome.com/9e3f22ff10.js" crossorigin="anonymous"></script>
<ul>
<li>
<p>Facebook</p>
<a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a></li>
<li>
<p>Twitter</p>
<a href="#"><i class="fa fa-twitter" aria-hidden="true"></i></a></li>
<li>
<p>Google</p>
<a href="#"><i class="fa fa-google-plus" aria-hidden="true"></i></a></li>
<li>
<p>LinkedIn</p>
<a href="#"><i class="fa fa-linkedin" aria-hidden="true"></i></a></li>
<li>
<p>Instagram</p>
<a href="#"><i class="fa fa-instagram" aria-hidden="true"></i></a></li>
</ul>

相关内容

最新更新