Awkwardtaco Awkwardtaco - 4 months ago 6
HTML Question

Image doesn't center on large screens

I am trying to center the image in my website below the navigation. It centers correctly on smaller screens in all browsers however, On larger screens it doesn't center in any browsers. I have tried encasing the image with a 'p' tag and using text-align to center it, but it didn't work. I have consulted others who are more knowledgeable in html and css and they have found nothing. I have searched the internet for an issue similar to my own have found nothing. Any insights into this problem would be appreciated.

Here is my HTML and CSS.



html{
font-family: 'Ubuntu', sans-serif;
overflow: hidden;
}
html>a{
text-decoration:none;
list-style-type: none;
}
body{
overflow:hidden;
margin:0;
padding:0;
}
.header{
position:relative;
width:100%;
background-color:black;/*#00FF00*/
margin:0px;
padding:0px;
z-index: -100;
font-size:2em;
}
.header>h1{
position:relative;
float:right;
}
.titlehead{
color: white;
}
.logo{
z-index: 1;
float:left;
}
.navBar{
position:relative;
top:15%;
float:left;
width:50%;
overflow:hidden;
}
.nav{
color:black;
}
.nav>ul{
list-style-type:none;
height:100%;
}
.nav>ul>li{
text-decoration:none;
float:left;
}
.nav>ul>li:hover{
-webkit-transition: all 100ms cubic-bezier(0.380, 0.410, 0.605, 0.625);
-moz-transition: all 100ms cubic-bezier(0.380, 0.410, 0.605, 0.625);
-o-transition: all 100ms cubic-bezier(0.380, 0.410, 0.605, 0.625);
transition: all 100ms cubic-bezier(0.380, 0.410, 0.605, 0.625); /* custom */
border-bottom-style:solid;
border-bottom-width:4px;
border-bottom-color:black;;
}
.nav>ul>li>a{
list-style-type:none;
text-decoration:none;
padding:15px;
font-size:1.7em;
color: black;
}
.images{
width:100%;
position:relative;
top:100px;
text-align:center;
}
.images>img{
display:block;
width:500px;
margin-left:auto;
margin-right:auto;
}
.images>p{
display:block;
margin-right:auto;
margin-left:auto;
text-align:center;
}
#melita{
position: relative;
top: -15%;
transform: translateY(15%);
width:100%;
}
.wrapper{
/*-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
transform-style: preserve-3d;*/
}
.content{
/*position:relative;
top:50%;*/
}

<!DOCTYPE HTML>
<html>
<head>
<title> PopcornDotOrg</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css"/>
<link href='https://fonts.googleapis.com/css?family=Ubuntu' rel='stylesheet' type='text/css'>
<meta name=viewport content='width=815'>
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
</head>
<body>
<div class="wrapper">
<div class="header">
<div class="titlehead">
<a href="index.php"><img class="logo" src="logoScaled.png" alt="logo"/></a>
<h1>PopcornDotOrg</h1>
</div>
</div>
<div class="navBar">
<nav class="nav">
<ul>
<li><a href="#">Recent</a></li>
<li><a href="#">Popular</a></li>
<li><a href="archive.php">Archive</a></li>
</ul>
</nav>
</div>
<div class="images">
<!--<h2>These muffins are terrible</h2>-->
<p><img alt="logo" src="logo.png"/></p>
</div>
</div>
</body>
</html>




Answer

The float: left and width: 50% in your .navBar are the reasons that caused the issue. Try remove float:left would work.

Also, try removing > from the follow css class, because your img tag is not directly nested in the div with css class .images

.images img {
  display: block;
  width: 500px;
  margin-left: auto;
  margin-right: auto;
}

Here is the working version.

html {
  font-family: 'Ubuntu', sans-serif;
  overflow: hidden;
}
html>a {
  text-decoration: none;
  list-style-type: none;
}
body {
  overflow: hidden;
  margin: 0;
  padding: 0;
}
.header {
  position: relative;
  width: 100%;
  background-color: black;
  /*#00FF00*/
  margin: 0px;
  padding: 0px;
  z-index: -100;
  font-size: 2em;
}
.header>h1 {
  position: relative;
  float: right;
}
.titlehead {
  color: white;
}
.logo {
  z-index: 1;
  float: left;
}
.navBar {
  position: relative;
  top: 15%;
  width: 50%;
  overflow: hidden;
}
.nav {
  color: black;
}
.nav>ul {
  list-style-type: none;
  height: 100%;
}
.nav>ul>li {
  text-decoration: none;
  float: left;
}
.nav>ul>li:hover {
  -webkit-transition: all 100ms cubic-bezier(0.380, 0.410, 0.605, 0.625);
  -moz-transition: all 100ms cubic-bezier(0.380, 0.410, 0.605, 0.625);
  -o-transition: all 100ms cubic-bezier(0.380, 0.410, 0.605, 0.625);
  transition: all 100ms cubic-bezier(0.380, 0.410, 0.605, 0.625);
  /* custom */
  border-bottom-style: solid;
  border-bottom-width: 4px;
  border-bottom-color: black;
  ;
}
.nav>ul>li>a {
  list-style-type: none;
  text-decoration: none;
  padding: 15px;
  font-size: 1.7em;
  color: black;
}
.images {
  width: 100%;
  position: relative;
  top: 100px;
  text-align: center;
}
.images img {
  display: block;
  width: 500px;
  margin-left: auto;
  margin-right: auto;
}
.images >p {
  display: block;
  margin: auto;
  text-align: center;
}
#melita {
  position: relative;
  top: -15%;
  transform: translateY(15%);
  width: 100%;
}
.wrapper {
  /*-webkit-transform-style: preserve-3d;
	-moz-transform-style: preserve-3d;
	transform-style: preserve-3d;*/
}
.content {
  /*position:relative;
	top:50%;*/
}
<div class="wrapper">
  <div class="header">
    <div class="titlehead">
      <a href="index.php">
        <img class="logo" src="logoScaled.png" alt="logo" />
      </a>
      <h1>PopcornDotOrg</h1>
    </div>
  </div>
  <div class="navBar">
    <nav class="nav">
      <ul>
        <li><a href="#">Recent</a>
        </li>
        <li><a href="#">Popular</a>
        </li>
        <li><a href="archive.php">Archive</a>
        </li>
      </ul>
    </nav>
  </div>
  <div class="images">
    <!--<h2>These muffins are terrible</h2>-->
    <p>
      <img alt="logo" src="http://www.online-image-editor.com/help/images/photo_border.png" />
    </p>
  </div>
</div>

Comments