麻烦老师帮忙看看,为什么图片这样写不能居中
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
/*此处写代码*/
* {
margin: 0;
padding: 0;
font-family: "Microsoft YaHei";
}
.container {
margin: 0 auto;
width: 100%;
min-width: 1000px;
}
.header ,
.footer {
width: 100%;
height: 100px;
line-height: 100px;
background: #000;
position: relative;
}
.header img {
float: left;
}
.header .nav {
position: absolute;
right: 0;
}
.header .nav a:hover {
color: orange;
}
.nav ul li {
list-style: none;
margin-right: 30px;
}
.nav ul li a {
color: #fff;
text-decoration: none;
}
.header .nav ul li {
float: left;
}
.footer .nav {
text-align: center;
}
.footer .nav ul li {
display: inline-block;
}
.footer .nav .last-li {
margin-right: 0;
}
.main {
height: 744px;
padding: 0 300px 0 320px;
}
.main p {
margin-top: 30px;
}
.main .career {
background: #f99;
}
.main span {
margin-right: 20px;
}
.main .left ,
.main .right ,
.main .middle {
position: relative;
float: left;
}
.main .middle {
float: left;
width: 100%;
height: 100%;
background: #ee9572;
}
.main .middle img {
display: inline-block;
text-align: center;
vertical-align: middle;
}
.main .left {
width: 320px;
height: 100%;
background: #ffefdb;
left: -320px;
margin-left: -100%;
position: relative;
}
.left .content {
position: absolute;
top:120px;
left: 5px;
}
.main .right {
width: 300px;
height: 100%;
background: #add8e6;
right: -300px;
margin-left: -300px;
position: relative;
}
.right .content {
position: absolute;
top: 120px;
left: 50%;
margin-left: -125px;
}
.main .content input {
width:245px;
height: 40px;
line-height: 40px;
background: #fff;
color: #333;
padding-left: 5px;
border: 1px solid #ddd;
}
.inpu:-ms-input-placeholder {
color: #ddd;
}
.main .content .submit {
display: block;
width: 250px;
background:#f00;
color: #fff;
font-size: 16px;
border: 1px solid #f00;
text-align: center;
}
</style>
</head>
<body>
<!-- 此处写代码 -->
<div class="container">
<div class="header">
<img src="http://img1.sycdn.imooc.com/climg//59093e9c00016ce303000100.png" alt="">
<div class="nav">
<ul>
<li><a href="#">课程</a></li>
<li><a href="#">职业路径</a></li>
<li><a href="#">实战</a></li>
<li><a href="#">猿问</a></li>
<li><a href="#">手记</a></li>
</ul>
</div>
</div>
<div class="main">
<div class="middle">
<img src="http://img1.sycdn.imooc.com/climg//590037e00001fab706000400.jpg" alt="">
</div>
<div class="left">
<div class="content">
<h3>课程推荐</h3>
<p><span class="career">职业路径</span><span>HTML5与CSS3实现动态网页</span></p>
<p><span class="career">职业路径</span><span>零基础入门Android语法与界面</span></p>
<p><span class="career">职业路径</span><span>IOS基础语法与常用控件</span></p>
<p><span class="career">职业路径</span><span>PHP入门开发</span></p>
<p><span class="career">职业路径</span><span>JAVA入门开发</span></p>
</div>
</div>
<div class="right">
<div class="content">
<h3>登录</h3>
<p><input type="text" placeholder="请输入登录邮箱/手机号" name="login"></p>
<p><input type="password" placeholder="6-16位密码,区分大小写,不能用空格" name="password"></p>
<p><input class="submit" type="submit" value="登录"></p>
</div>
</div>
</div>
<div class="footer">
<div class="nav">
<ul>
<li><a href="#">网站首页</a></li>
<li><a href="#">企业合作</a></li>
<li><a href="#">人才招聘</a></li>
<li><a href="#">联系我们</a></li>
<li><a href="#">常见问题</a></li>
<li class="last-li"><a href="#">友情链接</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>
正在回答
同学你好,针对同学的问题解答如下:
vertical-align: middle;定义行内元素的基线相对于该元素所在行的基线的垂直对齐。(vertical-align 只对行内元素有效,对块级元素无效。img定义为行内块,且父级是块级,因此无法实现垂直居中)
这里给同学讲一下:vertical-align: middle;的用法。多用于文字和图片于基线居中。如下例子:
其他的居中方法:
如果我的回答帮到了你,欢迎采纳,祝学习愉快~
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星