老师,请帮忙看看有没有可以优化的地方,另外还有个地方想咨询一下

来源:4-8 自由编程

贪食王

2021-01-10 19:15:24

相关代码:

相关代码:

​<!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="css/css.css">
</head>

<body>
<div class="about">
<h2>ABOUT</h2>
<div class="line"></div>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum has been the
industry's standard dummy text ever since the 1500s.</p>
</div>

<div class="content">
<div class="content-left">
<h3>A WORD ABOUT US</h3>
<div class="background">
<p>Praesent dignissim viverra est,sed bibendum ligula congue non.Sedac nisl et felis gravida commodo?Suspendisse eget ullamcorper ipsum.Suspendisse diam amet.</p>
<a href="">EXPLORE</a>
</div>
</div>

<div class="content-centre">
<img src="/image/bb3.jpg" alt="">
</div>

<div class="content-right">
<div class="right-container-1">
<p>70000</p>
<div class="line"></div>
<p>Students</p>
</div>

<div class="right-container-2">
<p>600</p>
<div class="line"></div>
<p>Faculty</p>
</div>
</div>

</div>
</body>

</html>


*{
    margin:0;
    padding:0;
}

.about h2 {
   margin-top: 30px;
   text-align: center;
   font-size: 32px;
}
.about .line {
    width: 60px;
    height: 3px;
    background-color: #07cbc9;
    margin: 10px auto;
}
.about p {
    font-size: 14px;
    color: gray;
    text-align: center;
    width: 450px;
    margin: 0 auto;
}

.content {
    width: 1201px;
    height: 464px;
    margin: 0 auto;
}

.content .content-left {
    float: left;
}
.content .content-centre {
    float: left;
    width: 650px;
    height: 435px;
    margin-top: 30px;
    margin-left: 80px;
}
.content .content-right {
    float: right;
}
.content .content-left h3 {
    width: 180px;
    font-size: 30px;
    position: relative;
    margin-top: 40px;
}

.content .content-left .background {
    width: 300px;
    background:rgba(255,255,255,0.5);
    margin-top: 20px;
    padding: 20px;
    border: 1px solid gray;
    position: absolute;
}

.content .content-left .background p {
   font-size: 18px;
}

.content .content-right .right-container-1 {
    width: 260px;
    border: 1px solid #07cbc9;
    padding-top: 40px;
    margin-top: 30px;
    padding-bottom: 40px;
}

.content .content-right .right-container-1 p:first-child {
        font-size: 28px;
        font-weight: bold;
        text-align: center;
}
.content .content-right .right-container-1 div {
    width: 60px;
    height: 3px;
    background-color: #07cbc9;
    margin: 10px auto;
}

.content .content-right .right-container-1 p:last-child {
    font-size: 20px;
    text-align: center;
}

.content .content-right .right-container-2 {
    width: 260px;
    border: 1px solid #07cbc9;
    padding-top: 40px;
    padding-bottom: 40px;
    margin-top: 30px;
}
.content .content-right .right-container-2 p:first-child {
    font-size: 28px;
    font-weight: bold;
    text-align: center;
}
.content .content-right .right-container-2 div {
    width: 60px;
    height: 3px;
    background-color: #07cbc9;
    margin: 10px auto;
}
.content .content-right .right-container-2 p:last-child {
    font-size: 20px;
    text-align: center;
}

另外我想问的是,我的图片想要居中,可是设置了浮动后,我怎么弄都居中不了,只能通过

margin-left来控制左边距,我想问下,在我的这个代码里,想要把图片居中,可以怎么弄呢?


写回答

1回答

好帮手慕久久

2021-01-11

同学你好,代码中有如下问题可优化:

1、explore按钮的样式没有设置:

http://img.mukewang.com/climg/5ffbb59c094fdf9604770122.jpg

建议增加如下样式:

http://img.mukewang.com/climg/5ffbb65b09ab163006070498.jpg

2、content区域与about区域之间的间距,可以直接设置在content上,没必要设置在content中的每个子元素上,如下

http://img.mukewang.com/climg/5ffbb7120958d03407110206.jpg

http://img.mukewang.com/climg/5ffbb72d09a9200505090177.jpg

http://img.mukewang.com/climg/5ffbb74009cd485604510215.jpg

http://img.mukewang.com/climg/5ffbb75709c1ecd400000000.jpg

问题解答如下:

图片设置了浮动后,就没法使用text-align:center;属性来实现居中了。当前例子中,图片是处于content中的,而content是有固定宽度的,所以只要保证图片在content中大概居中即可。而采用margin-left调整图片的位置,就是一个很好的实现方案。

如果想实现绝对的居中,可以采用定位:

http://img.mukewang.com/climg/5ffbb8b709b27d7606970240.jpg

http://img.mukewang.com/climg/5ffbb8d309d3112f05810325.jpg

但是老师觉得没必要,使用margin-left调成一下图片位置就行了。

祝学习愉快!

0

0 学习 · 15276 问题

查看课程