如何在这些div内居中放置这些图像?

时间:2019-02-26 22:38:56

标签: html css image centering

我似乎找不到找到将图像居中于div中的方法。有任何提示吗?我知道一些非常基本的知识,只是最近才再次涉猎。我希望有人能得到我想要在这里做什么?

我似乎找不到找到将图像居中于div中的方法。有任何提示吗?我知道一些非常基本的知识,只是最近才再次涉猎。我希望有人能得到我想要在这里做什么?

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  width: 100%;
}

body {
  padding: 0;
  margin: 0;
  border: 0;
  background-color: grey;
  background-attachment: fixed;
  background-size: 100% auto;
}

ul#horizontal-list {
  list-style: none;
}

ul#horizontal-list li {
  display: inline;
}

ul {
  margin: 0;
  padding: 0;
  overflow: hidden;
}

li {
  float: center;
}

li a {
  display: block;
  color: white;
  text-align: center;
  padding: 16px;
  text-decoration: none;
}

li a:hover {
  background-color: red;
}

.navbar {
  position: fixed;
    top: 0;
    height: 50px;
    width: 100%;
    background-color: black;
    color: white;
    text-align: center;
    left: 0;
    right: 0;
    z-index: 1;
}

.navbar ul {
  display: flex;
  align-items: center;
  justify-content: center;
  list-style-type: none;
  margin-top: 0px;
}

.header {
	width: 100%;
	height: 100%;
	background-image: url("img/bg/background1.png");
	background-color: grey;
	background-repeat: no-repeat;
	background-size: 100% 100%;
}

.body {
  /*height: 100%;*/
  width: 100%;
  background-color: white;
  color: black;
  padding-left: 5%;
  padding-right: 5%;
  overflow: hidden;

}

.content {
	margin: auto;
	width: 100%;
	background-color: white;
	color: black;
	border-right: double;
	border-left: double;
	text-align: justify;
	font-size: 20px;
	font-family: arial;
	padding-top: 10%;
	padding-bottom: 10%;
	padding-left: 5%;
	padding-right: 5%;
}

.social {
	margin: auto;
	position: absolute;
}

.social a {

}

.footer {
  height: 50px;
  width: 100%;
  background-color: black;
  color: white;
  margin: auto;
  vertical-align: middle;
}

#copyright {
	display: table;
}

#cpy{
    display: table-cell;
    vertical-align: middle;
}
<!DOCTYPE html>

<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" type="text/css" href="stylesheet.css">
  <link rel="icon" type="image/x-icon" href="img/favicon.ico"/>
  <meta name="description" content="My Personal Portfolio">
  <title>John's Work</title>
</head>

<body>


  <div class="navbar">

    <ul>
      <li><a href="index.html">HOME</a></li>
      <li><a href="about.html">ABOUT</a></li>
      <li><a href="contact.html">CONTACT</a></li>
    </ul>

  </div>


  <div class="header">

  </div>

  <div class="body">
  <div class="content">
	<div class="social">
			<a href="https://www.facebook.com/" style="color:black; text-decoration:none">
				<img src="img/fb.png" alt="Facebook">
			</a>
			
			<a href="http://www.instagram.com/" style="color:black; text-decoration:none" >
				<img src="img/ig.png" alt="Instagram">
			</a>
			
			<a href="http://www.snapchat.com/" style="color:black; text-decoration:none" >
				<img src="img/snapchat.png" alt="Snapchat">
			</a>
	</div>
  </div>
</div>

  <div class="footer" id="copyright" style="text-align:center">
    <div id="cpy">&copy;)</div>
  </div>



</body>

</html>

1 个答案:

答案 0 :(得分:2)

据我了解,主要的麻烦是.social障碍的绝对位置。如果确实需要此职位,请使用:

left: 50%;
transform: translateX(-50%);

在其他情况下,您可以删除position: absolute;并添加

display: flex;
justify-content: center;