gpt4 book ai didi

CSS响应将div从右移到左下方和中心

转载 作者:行者123 更新时间:2023-11-28 06:21:30 28 4
gpt4 key购买 nike

当我使用响应式媒体查询时,我希望我的页脚内部 div 包装器从右移动到左下方并居中。但是,将最后一个元素“Contact us”从右向左移动时,它在下方但不居中,并且之前的div“follow us”与“copyright”不在同一行。

The Idea Here Codepen here

HTML
<!doctype html>
<html>

<head>
<title>Agency</title>
<meta charset="utf-8">
<link href="footer.css" rel="stylesheet" merdia="handheld">
<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
</head>

<body>
<div class="wrapper">

<div class="header">
<h1>Header</h1>
</div>

<div class="footer">
<h1>Footer</h1>
<div class="copyright">
<h3>Copyright</h3>
</div>

<div class="social">
<h3>Follow us:</h3>
<p> Twitter, Facebook, Youtube</p>
</div>

<div id="contactfooter">
<h2> Contact </h2>
<p>Contact Form would go here</p>
</div>
</div>
</body>

CSS
/*footer.css*/
*{
margin:0;
padding:0;
font-family: 'Open Sans', sans-serif;
}

body
{
background-color:#DCDCDC;
}

.wrapper{
max-width:1200px;
width:100%;
margin:auto;
}

.header{
width:100%;
background-color:green;
height:20vh;
}

.footer{
width:100%;
background-color:orange;
font-size:1em;
overflow:hidden;
padding-bottom:3%;
clear:both;
padding-top:5%;
border-top:3px solid #0099FF;
color:black;
}

.copyright{
width:25%;
background-color:red;
float:left;
margin-left:10%;
}

.copyright p{

font-size:0.938em;
line-height: 2em;
}

.social{
width:20%;
background-color:yellow;
float:left;
margin-left:8%;
}

#contactfooter{
width:20%;
background-color:blue;
float:right;
margin-right:10%;
display:block;
}

#contactfooter h2, #contactfooter{
font-size:1.250em;
text-align: center;
}

/*---------MEDIA QUERIES----------*/

@media (max-width:1020px){
.copyright{
margin-left:25%;
float:left;
}
.social{
float:right;
margin-right:25%;
}

#contactfooter{
float:left;
width:30%;
margin:auto; /*does not margin to the center of the footer wrapper.. why?*/
/*margin-right:0%;
margin-left:45%;*/


}
}

最佳答案

对于较小的屏幕,您不需要更改它们的边距,只需固定它们的宽度即可。

关于CSS响应将div从右移到左下方和中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35563175/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com