CSS文本和图标中心对齐问题

时间:2017-07-12 19:30:15

标签: html css

我无法让文字和图标在我的页脚中心框中水平和垂直居中对齐。 HTML和CSS表格如下。请查看我的代码,让我知道我需要做出的任何更改以及解决我的问题。

<style>.footer-distributed{
	background-color: #292c2f;
	box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.12);
	box-sizing: border-box;
	width: 100%;
	text-align: left;
	font: bold 16px sans-serif;

	padding: 55px 50px;
	margin-top: 80px;
}

.footer-distributed .footer-left,
.footer-distributed .footer-center,
.footer-distributed .footer-right{
	display: inline-block;
	vertical-align: top;
}

/* Footer left */

.footer-distributed .footer-left{
	width: 40%;
}

/* The company logo */

.footer-distributed h3{
	color:  #ffffff;
	font: normal 34px '', normal;
	margin: 20px ;
}

.footer-distributed h3 span{
	color:  #894FAB;
}

/* Footer links */

.footer-distributed .footer-links{
	color:  #ffffff;
    font: normal 16px 'arial', normal;
    text-transform: none;
	margin: 20px 0 12px;
	padding: 0;
}

.footer-distributed .footer-links a{
	display:inline-block;
	font-size: 14;
	font-weight: normal;
	line-height: 1.8;
	text-decoration: none;
	color:  inherit;
}

.footer-distributed .footer-company-name{
	color:  #8f9296;
	font-size: 14px;
	font-weight: normal;
	margin: 0;
}

.footer-distributed .footer-privacy-policy{
	color:  #8f9296;
	font-size: 14px;
	font-weight: normal;
	margin: 0;
}

/* Footer Center */

.footer-distributed .footer-center{
	width: 35%;
}

.footer-distributed .footer-center i{
	background-color:  #33383b;
	color: #ffffff;
	font-size: 25px;
	width: 38px;
	height: 38px;
	border-radius: 50%;
	text-align: center;
	line-height: 42px;
	margin: 10px 15px;
	vertical-align: middle;
}

.footer-distributed .footer-center i.fa-envelope{
	font-size: 17px;
	line-height: 38px;
}

.footer-distributed .footer-center p{
	display: inline-block;
	color: #ffffff;
	vertical-align: middle;
    text-align: center;
	margin:0;
}

.footer-distributed .footer-center p span{
	display:block;
	font-weight: normal;
	font-size:14px;
	line-height:2;
}

.footer-distributed .footer-center p a{
	color:  #894FAB;
	text-decoration: none;;
}


/* Footer Right */

.footer-distributed .footer-right{
	width: 20%;
}

.footer-distributed .footer-company-about{
	line-height: 20px;
	color:  #92999f;
	font-size: 13px;
	font-weight: normal;
	margin: 0;
}

.footer-distributed .footer-company-about span{
	display: block;
	color:  #ffffff;
	font-size: 14px;
	font-weight: bold;
	margin-bottom: 20px;
}

.footer-distributed .footer-icons{
	margin-top: 25px;
}

.footer-distributed .footer-icons a{
	display: inline-block;
	width: 35px;
	height: 35px;
	cursor: pointer;
	background-color:  #33383b;
	border-radius: 2px;

	font-size: 20px;
	color: #ffffff;
	text-align: center;
	line-height: 35px;

	margin-right: 3px;
	margin-bottom: 5px;
}

/* If you don't want the footer to be responsive, remove these media queries */

@media (max-width: 880px) {

	.footer-distributed{
		font: bold 14px ;
	}

	.footer-distributed .footer-left,
	.footer-distributed .footer-center,
	.footer-distributed .footer-right{
		display: block;
		width: 100%;
		margin-bottom: 40px;
		text-align: center;
	}

	.footer-distributed .footer-center i{
		margin-left: 0;
	}
.footer-privacy-policy {
}

}
</style>
<!DOCTYPE html>
<html>

  <script src="https://use.fontawesome.com/7b48e06cba.js"></script>
  
	<body>

		
		<!-- The content of your page would go here. -->

		<footer class="footer-distributed">

			<div class="footer-left">

				<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBQ9lFHOxqSd-Tx5713FBhTp4L5QsC1oxg"></script><div style='overflow:hidden;height:250px;width:auto; margin: 0 auto;'><div id='gmap_canvas' style='height:250px;width:auto; margin: 0 auto;'></div>
              <style>#gmap_canvas img{max-width:none!important;background:none!important}</style></div><script type='text/javascript'>function init_map(){var myOptions = {zoom:12,center:new google.maps.LatLng(40.459225378643445,-86.84742606020508),mapTypeId: google.maps.MapTypeId.ROADMAP};map = new google.maps.Map(document.getElementById('gmap_canvas'), myOptions);marker = new google.maps.Marker({map: map,position: new google.maps.LatLng(40.459225378643445,-86.84742606020508)});infowindow = new
google.maps.InfoWindow({content:'<strong>Bethany Childcare & Preschool</strong><br>3305 Longlois Dr., Lafayette, IN 47904<br>'});google.maps.event.addListener(marker, 'click', function()              {infowindow.open(map,marker);});infowindow.open(map,marker);}google.maps.event.addDomListener(window, 'load', init_map);</script>

				<p class="footer-links">
					<a href="https://www.bccandp.org/">Home</a>
					·
					<a href="https://www.bccandp.org/contact">Contact</a>
					·
					<a href="https://www.bccandp.org/brightwheel">Brightwheel</a>
					·
					<a href="https://www.bccandp.org/programs">Programs</a>
					·
					<a href="https://www.bccandp.org/calendar">Calendar</a>
				    ·
					<a href="https://www.bccandp.org/enrollment">Enrollment</a>
					·
					<a href="https://www.bccandp.org/staff">Staff</a>
				</p>

				<p class="footer-company-name">BCC&P DOT &copy; 2017 |
					<a href="https://www.bccandp.org/privacy" class="footer-privacy-policy">Privacy Policy</a></p>
			</div>

			<div class="footer-center">

				<div>
					<i class="fa fa-map-marker"></i>
					<p><span>3305 Longlois Dr.</span> Lafayette, Indiana</p>
				</div>

				<div>
					<i class="fa fa-phone"></i>
					<p>+1.765.447.7044 X.2</p>
				</div>

				<div>
					<i class="fa fa-envelope"></i>
					<p><a href="mailto:contactus@bccandp.org">contactus@bccandp.org</a></p>
				</div>

			</div>

			<div class="footer-right">

				<p class="footer-company-about">
					<span>About Us</span>
					We are an Indiana State registered childcare and preschool ministry of Bethany Presbyterian Church. Our primary focus is on the community of Lafayette, Indiana and its surrounding communities. We are a Child Care Development Fund (CCDF) provider. Founded in 1988.
				</p>

				<div class="footer-icons">

					<a href="https://www.facebook.com/bccandp"><i class="fa fa-facebook"></i></a>
					<a href="#"><i class="fa fa-twitter"></i></a>
					<a href="#"><i class="fa fa-linkedin"></i></a>
					<a href="#"><i class="fa fa-github"></i></a>

				</div>

			</div>

		</footer>

	</body>
  
</html>

2 个答案:

答案 0 :(得分:0)

创建一个div来包装内容。这将是负责将其集中到页面的div。

<div class="footer-center">

    <div class="wrapper">
        <div>
            <i class="fa fa-map-marker"></i>
            <p><span>3305 Longlois Dr.</span> Lafayette, Indiana</p>
        </div>

        <div>
            <i class="fa fa-phone"></i>
            <p>+1.765.447.7044 X.2</p>
        </div>

        <div>
            <i class="fa fa-envelope"></i>
            <p><a href="mailto:contactus@bccandp.org">contactus@bccandp.org</a></p>
        </div>

    </div>
</div>

现在,只是让包装器成为一个内联块,考虑到它的父亲有一个文本中心,包装器将居中。 将文本和包装器内的所有其他内容对齐到左侧。

答案 1 :(得分:0)

由于此错误,我无法运行您的示例:

"Google Maps API error: RefererNotAllowedMapError https://developers.google.com/maps/documentation/javascript/error-messages#referer-not-allowed-map-error
Your site URL to be authorized: https://stacksnippets.net/js"

所以我对你面对的事情有点暗淡。但是,当我需要垂直对齐时,我去的是flexbox。 即在包含元素上:

  display: flex;
  justify-content: center;
  flex-direction: column;
  text-align: center;

(有时还需要保证金:0自动; )。

如果您遇到图标和标签垂直对齐的问题,我总是使用的技巧是使用垂直对齐和负像素值。即:

vertical-align: -2px;