Why doesn't my `inline-block` work? - html

I've been trying to figure out why my #logo doesn't behave as it should, having display: inline-block;, #logo and #main_nav should be on the same line, however it doesn't. Why is this and how can I fix it?
#logo {
margin: 5px;
background-repeat: no-repeat;
background-size: 350px;
width: 350px;
height: 100px;
background-image: url("http://www.jeffarries.com/media/pictures/logos/jeff_cursive.png");
display: inline-block;
}
ul, li {
display: block !important;
}
li, ul {
display: inline-block;
}
#main_nav {
float: right;
display: inline-block;
margin: 10px;
}
.nav_button:link {
text-transform: uppercase;
display: inline-block;
text-decoration: none;
font-family: arial;
font-size: 16px;
margin: 10px;
padding-bottom: 2px;
position: relative;
color: black;
}
.nav_button:visited {
color: black;
}
<div id="logo"></div>
<div id="myNav" class="overlay">
<div id="main_nav" class="overlay-content">
<a class="nav_button" href="/">Home</a>
<!-- <a class="nav_button" href="">Blog</a>
<a class="nav_button" href="">Trips</a> -->
<a class="nav_button" href="/politics">Politics</a>
<!-- <a class="nav_button" href="">Pictures</a> -->
<a class="nav_button" href="/videos">Videos</a></li>
<!-- <a class="nav_button" href="">Computer</a></li> -->
</div> <!-- close main_nav -->
</div> <!-- close myNav-->

Your parent #myNav doesn't have apply any style, so the browser default would set the display to block. Hence make it wrap to another line. Make it inline-block to fix the problem.
#logo {
margin: 5px;
background-repeat: no-repeat;
background-size: 350px;
width: 350px;
height: 100px;
background-image: url("http://www.jeffarries.com/media/pictures/logos/jeff_cursive.png");
display: inline-block;
}
ul {
display: block;
}
li, #myNav {
display: inline-block;
}
#main_nav {
float: right;
margin: 10px;
display: inline-block;
}
.nav_button:link {
text-transform: uppercase;
display: inline-block;
text-decoration: none;
font-family: arial;
font-size: 16px;
margin: 10px;
padding-bottom: 2px;
position: relative;
color: black;
}
.nav_button:visited {
color: black;
}
<div id="logo"></div>
<div id="myNav" class="overlay">
<div id="main_nav" class="overlay-content">
<ul>
<li><a class="nav_button" href="/">Home</a></li>
<li><a class="nav_button" href="/politics">Politics</a></li></ul>
</div> <!-- close main_nav -->
</div> <!-- close myNav-->

Add width to your nav container and align the text to center. The inline-block depends on the space, it will move to second line if there is not enough space.
#logo {
margin: 5px;
background-repeat: no-repeat;
background-size: 350px;
width: 350px;
height: 100px;
background-image: url("http://www.jeffarries.com/media/pictures/logos/jeff_cursive.png");
display: inline-block;
}
ul,
li {
display: block !important;
}
li,
ul {
display: inline-block;
}
#myNav {
float: right;
display: inline-block;
text-align: right;
vertical-align: top;
margin-top: 25px;
}
#main_nav {
width: 250px;
margin: 10px;
}
.nav_button:link {
text-transform: uppercase;
display: inline-block;
text-decoration: none;
font-family: arial;
font-size: 16px;
margin: 10px;
padding-bottom: 2px;
position: relative;
color: black;
}
.nav_button:visited {
color: black;
}
<a href="/">
<div id="logo"></div>
</a>
<div id="myNav" class="overlay">
<div id="main_nav" class="overlay-content">
<a class="nav_button" href="/">Home</a>
<!-- <a class="nav_button" href="">Blog</a>
<a class="nav_button" href="">Trips</a> -->
<a class="nav_button" href="/politics">Politics</a>
<!-- <a class="nav_button" href="">Pictures</a> -->
<a class="nav_button" href="/videos">Videos</a>
<!-- <a class="nav_button" href="">Computer</a></li> -->
</div>
<!-- close main_nav -->
<!-- close myNav-->

Related

How to shift one element of an <li> list to the right

I have an unordered linked list. I'm trying to shift one of the items in the navigation all the way to the right (Order) as if it had text-align: right;. I tried using float: right; and text-align: right;, but none of them seemed to work. If I set the margin-left to a really high number (such as 100px) it does shift to the right, but if I resize my window then I can't see it anymore or it's not on the right side of the page. Here is the HTML:
nav {
position: fixed;
}
.navigation-links-no-style a {
text-decoration: none;
position: relative;
margin: 15px;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
li {
float: left;
}
.navigation-links li {
padding-top: 1.3em;
}
.navbar {
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
border-bottom: solid 1px black;
background: white;
padding-left: 5em;
}
.navbar a {
float: left;
display: block;
text-align: center;
padding: 14px 16px;
text-decoration: none;
margin-left: 20px;
color: black;
font-size: 14pt;
}
.order {
color: #FFFFFF !important;
background: #1419e2;
text-decoration: none;
padding: 8px;
border-radius: 5px;
margin-top: 15px;
}
<div class="navbar">
<a class="glacier-hills" href="glacier_hills.html">
<img src="Images/Glacier-Hills-Logo.svg" alt="" width="182" height="90">
</a>
<ul class="navigation-links">
<div class="navigation-links-no-style">
<li>
<a class="menu" href="menu.html">Menu</a>
</li>
<li>
<a class="location" href="location.html">Hours and Location</a>
</li>
</div>
<li>
<a class="order" href="order.html">Order</a>
</li>
</ul>
</div>
Any help would be greatly appreciated. Thanks!
Assuming you're looking to move your .order element, you'll want to apply the float: right rule to the parent (<li>) element. I've added a class to this, .order-container, to make this easier to achieve in the following example.
Note also that once you float to the right, it will be off the screen by default. You'll want to set a negative margin-right to circumvent this. I've gone with margin-right: -10em in the following, to match the offset from the image on the left.
Ultimately, you may wish to consider using a framework to achieve responsive design, ensuring that the offset is correct regardless of screen size.
nav {
position: fixed;
}
.navigation-links-no-style a {
text-decoration: none;
position: relative;
margin: 15px;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
li {
float: left;
}
.navigation-links li {
padding-top: 1.3em;
}
.navbar {
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
border-bottom: solid 1px black;
background: white;
padding-left: 5em;
}
.navbar a {
float: left;
display: block;
text-align: center;
padding: 14px 16px;
text-decoration: none;
margin-left: 20px;
color: black;
font-size: 14pt;
}
.order {
color: #FFFFFF !important;
background: #1419e2;
text-decoration: none;
padding: 8px;
border-radius: 5px;
margin-top: 15px;
float: right;
}
.order-container {
float: right;
margin-right: 10em;
}
<div class="navbar">
<a class="glacier-hills" href="glacier_hills.html">
<img src="Images/Glacier-Hills-Logo.svg" alt="" width="182" height="90">
</a>
<ul class="navigation-links">
<div class="navigation-links-no-style">
<li>
<a class="menu" href="menu.html">Menu</a>
</li>
<li>
<a class="location" href="location.html">Hours and Location</a>
</li>
</div>
<li class="order-container">
<a class="order" href="order.html">Order</a>
</li>
</ul>
</div>
MDN still advises that <div> is not a valid child of <ul>. Furthermore float adds a whole heap of side effects by removing the items from the natural flow of the document. To modernize this we can make use of display:flex
/*Normalise body*/
body {
margin:0;
}
/*Set flex on the nabar top position logo and links*/
.navbar {
display: flex;
}
/*Ad a maring to the logo link*/
.navbar > a:first-of-type {
margin-left: 5em;
}
nav {
position: fixed;
}
.navigation-links-no-style a {
text-decoration: none;
}
.navbar ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
width: 100%;
/*Ad flex to the nav link element*/
display: flex;
/*Vertically center the links*/
align-items:center;
}
/*Push the last element right but give it a little margin to the right*/
.navbar ul>li:last-of-type {
margin-left: auto;
margin-right:1em;
}
.navigation-links li {
padding-top: 1.3em;
}
.navbar {
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
border-bottom: solid 1px black;
background: white;
}
.navbar a {
display: block;
text-align: center;
padding: 14px 16px;
text-decoration: none;
margin-left: 20px;
color: black;
font-size: 14pt;
}
.order {
color: #FFFFFF !important;
background: #1419e2;
text-decoration: none;
padding: 8px;
border-radius: 5px;
margin-top: 15px;
}
<div class="navbar">
<a class="glacier-hills" href="glacier_hills.html">
<img src="Images/Glacier-Hills-Logo.svg" alt="" width="182" height="90">
</a>
<ul class="navigation-links">
<li>
<a class="menu" href="menu.html">Menu</a>
</li>
<li>
<a class="location" href="location.html">Hours and Location</a>
</li>
<li>
<a class="order" href="order.html">Order</a>
</li>
</ul>
</div>
You should use media queries for making navbar responsive.
a {
text-decoration: none;
color: black;
}
.navbar {
width: 100%;
overflow: hidden;
position: fixed;
top: 0;
display: flex;
justify-content: space-between;
border-bottom: solid 1px black;
}
.div-links {
display: flex;
align-items: center;
width: 70%;
}
.nav-links {
width: 100%;
display: flex;
justify-content: end;
align-items: center;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
.nav-links li {
padding: 2rem;
}
.nav-items {
width: 30%;
display: flex;
justify-content: space-around;
}
.order {
overflow: hidden;
color: #ffffff !important;
background: #1419e2;
text-decoration: none;
padding: 0.8rem;
border-radius: 5px;
}
<div class="navbar">
<a href="glacier_hills.html">
<img
src="Images/Glacier-Hills-Logo.svg"
alt=""
width="182"
height="90"
/>
</a>
<div class="div-links">
<ul class="nav-links">
<div class="nav-items">
<li>
<a class="menu" href="menu.html">Menu</a>
</li>
<li>
<a class="location" href="location.html">Hours and Location</a>
</li>
</div>
<li class="btn">
<a class="order" href="order.html">Order</a>
</li>
</ul>
</div>
</div>

why css code not working problem in float?

I have written some code in CSS and HTML but float is not working. I want the site name and logo at left side and menu or nav at the right side of the navbar.
https://codepen.io/asfafasa/pen/NWWWzgd
Html:
<body>
<div class="page-wrapper">
<header>
<div class="banner-home">
<h1>
<div class="homepage"> <a href="index.html" title="CrazyPirates" target="new">
<span class="crazy"><img src="images/Logomakr_5MZbkZ.png" alt="" width="30px" class="logo">Sitename & logo </span>
</a>
</div>
</h1>
<div id="open">
<a href="#" onClick="openMenu()">
<i class="fas fa-ice-cream"></i>
</a>
</div>
<nav>
<div class="menu">
<div class="button">
<ul>
<!--<a href="#" onClick="closeMenu()">
<i class="fas fa-times">
</i>
</a>-->
<li>
<div class="homePage_re rd_button">
<a href="index.html" class="navigation_home">
Home
</a></div>
</li>
<li>
<div class="crazyGallary rd_button">
<a href="gallary.html">
Gallay
</a></div>
</li>
<li>
<div class="aboutUs rd_button">
<a href="aboutUs.html">
About Us
</a></div>
</li>
</ul>
</nav>
</div>
</div>
</div>
</div>
</header>
<div class="space"></div>
CSS:
*{
margin: 0;
padding: 0;
outline: 0;
box-sizing: border-box;
}
div{
display: block;
}
body{
margin: 0;
font-size: 14px;
}
.space{
height: 50px;
}
.page-wrapper{
padding: 0 50px;
}
header{
background: darkgrey;
height: 120px;
color: azure;
z-index: 1;
margin: 0 auto;
padding: 5px 0;
text-align: center;
display: block;
}
header *{
display: inline-block;
}
.banner-home{
align-items: center;
overflow: auto;
}
.homepage{
padding-left: 20px;
float: left;
}
.menu{
display: inline-block;
float: right;
}
.rd_button a{
text-decoration: none;
display: block;
}
.rd_button{
list-style-type: none;
display: block;
}
.button a{
color: #fff;
font-weight: 300;
letter-spacing: 2px;
text-transform: uppercase;
padding: 0 0 0 50px;
font-size: 14px;
z-index: 1;
}
.button{
float: right;
}
.button a:hover{
background-color: tomato;
color: #fff;
}
.button a:hover:after{
transform: translateY(-50%) rotate(-35deg);
}
nav{
margin: 0 auto;
text-align: right;
float: right;
}
.logo{
display: inline;
height: 100%;
}
.banner-home h1 a{
text-decoration: none;
}
nav ul{
list-style: none;
padding: 0;
margin: 0;
}
main{
text-align: center;
}
The menu items should be on the right side of the bar while the logo and site name should be on the left side.
2 things:
.banner-home should have the float:left property
.banner-home div was not closed properly
Updated pen: https://codepen.io/david-somekh/pen/yLLLEEK
<body>
<style>
*{
margin: 0;
padding: 0;
outline: 0;
box-sizing: border-box;
}
div{
display: block;
}
body{
margin: 0;
font-size: 14px;
}
.space{
height: 50px;
}
.page-wrapper{
padding: 0 50px;
}
header{
background: darkgrey;
height: 120px;
color: azure;
z-index: 1;
margin: 0 auto;
padding: 5px 0;
text-align: center;
display: block;
}
header *{
display: inline-block;
}
.banner-home{
float:left;
align-items: center;
overflow: auto;
}
.homepage{
padding-left: 20px;
float: left;
}
.menu{
display: inline-block;
float: right;
}
.rd_button a{
text-decoration: none;
display: block;
}
.rd_button{
list-style-type: none;
display: block;
}
.button a{
color: #fff;
font-weight: 300;
letter-spacing: 2px;
text-transform: uppercase;
padding: 0 0 0 50px;
font-size: 14px;
z-index: 1;
}
.button{
float: right;
}
.button a:hover{
background-color: tomato;
color: #fff;
}
.button a:hover:after{
transform: translateY(-50%) rotate(-35deg);
}
nav{
margin: 0 auto;
text-align: right;
float: right;
}
.logo{
display: inline;
height: 100%;
}
.banner-home h1 a{
text-decoration: none;
}
nav ul{
list-style: none;
padding: 0;
margin: 0;
}
main{
text-align: center;
}
</style>
<div class="page-wrapper">
<header>
<div class="banner-home">
<h1>
<div class="homepage"> <a href="index.html" title="CrazyPirates" target="new">
<span class="crazy"><img src="images/Logomakr_5MZbkZ.png" alt="" width="30px" class="logo">Sitename & logo </span>
</a>
</div></div>
</h1>
<div id="open">
<a href="#" onClick="openMenu()">
<i class="fas fa-ice-cream"></i>
</a>
</div>
<nav>
<div class="menu">
<div class="button">
<ul>
<!--<a href="#" onClick="closeMenu()">
<i class="fas fa-times">
</i>
</a>-->
<li>
<div class="homePage_re rd_button">
<a href="index.html" class="navigation_home">
Home
</a></div>
</li>
<li>
<div class="crazyGallary rd_button">
<a href="gallary.html">
Gallay
</a></div>
</li>
<li>
<div class="aboutUs rd_button">
<a href="aboutUs.html">
About Us
</a></div>
</li>
</ul>
</nav>
</div>
</div>
</div>
</div>
</header>
<div class="space"></div>

My nav bar won't center and keeps moving either right or left

I've been going around the web trying to find an answer to how to center my navbar but none of the solution worked.
The code below will show what I have so far with both HTML and CSS.
header {
background: #ffffff;
color: #000000;
padding-top: 30px;
min-height: 70px;
border-bottom: #000000 3px solid;
}
header a {
color: #000000;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
header li {
float: center;
display: inline;
padding: 0 20px 0 20px;
}
header nav {
margin-left: auto;
margin-right: auto;
margin-top: 10px;
}
header #smcontent {
float: left;
}
header #smcontent a {
margin: 0;
}
header #smcontent img {
width: 20px;
}
header .logoimg .center {
display: block;
margin-left: auto;
margin-right: auto;
width: 20%;
}
header a:hover {
color: #cccccc;
font-weight: bold;
}
<header>
<div class="container">
<div id="smcontent">
<a href="https://twitter.com/">
<img src="./images/twitter.png">
</a>
<a href="https://facebook.com/">
<img src="./images/facebook.png">
</a>
</div>
<div class="logoimg">
<a href="index.html">
<img class="center" src="./images/portfolio.png">
</a>
</div>
<nav>
<ul>
<li class="current">Home</li>
<li>Story</li>
<li>Product</li>
<li>Clinique</li>
<li>Promotions</li>
</ul>
</nav>
</header>
This is how it looks like right now:
I have also noticed that in CSS, when I did "float: center;" it had no difference with when I did "float: left;". But when I did "float: right;" it would shift to the right.
ul {
margin: 0 auto;
text-align: center;
}
header {
background: #ffffff;
color: #000000;
padding-top: 30px;
min-height: 70px;
border-bottom: #000000 3px solid;
}
header a {
color: #000000;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
header li {
float: center;
display: inline;
padding: 0 20px 0 20px;
}
header nav {
margin-left: auto;
margin-right: auto;
margin-top: 10px;
margin: 0 auto;
}
header #smcontent a {
margin: 0;
}
header #smcontent img {
width: 20px;
}
header .logoimg .center {
display: block;
margin-left: auto;
margin-right: auto;
width: 20%;
}
header a:hover {
color: #cccccc;
font-weight: bold;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<header>
<div class="container">
<div id="smcontent">
<a href="https://twitter.com/">
<img src="./images/twitter.png">
</a>
<a href="https://facebook.com/">
<img src="./images/facebook.png">
</a>
</div>
<div class="logoimg">
<a href="index.html">
<img class="center" src="./images/portfolio.png">
</a>
</div>
<nav>
<ul>
<li class="current">Home</li>
<li>Story</li>
<li>Product</li>
<li>Clinique</li>
<li>Promotions</li>
</ul>
</nav>
</div>
</header>
</body>
</html>
I have removed the below css from your code
header #smcontent {
float: left;
}
and added margin: 0 auto; text-align: center; to the ul
Try absolute position with float none, left 50% and a left translate of 50% to center your nav bar perfectly.
CSS: add
header .newCenter {
float: none;
position: absolute;
left: 50%;
transform: translate(-50%, 0);
}
HTML: add
<nav class="newCenter">
<ul>
<li class="current">Home</li>
<li>Story</li>
<li>Product</li>
<li>Clinique</li>
<li>Promotions</li>
</ul>
</nav>
Float only applies to left and right. I added display: grid and justify-content: center to your header. I removed float: left; in header #smcontent.
header {
background: #ffffff;
color: #000000;
padding-top: 30px;
min-height: 70px;
border-bottom: #000000 3px solid;
display: grid; //or flex
justify-content: center;
}
header a {
color: #000000;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
header li {
display: inline;
padding: 0 20px;
}
header nav {
margin: 10px auto 0;
}
header #smcontent a {
margin: 0;
}
header #smcontent img {
width: 20px;
}
header .logoimg .center {
display: block;
margin: 0 auto;
width: 20%;
}
header a:hover {
color: #cccccc;
font-weight: bold;
}
<header>
<div class="container">
<div id="smcontent">
<a href="https://twitter.com/">
<img src="./images/twitter.png">
</a>
<a href="https://facebook.com/">
<img src="./images/facebook.png">
</a>
</div>
<div class="logoimg">
<a href="index.html">
<img class="center" src="./images/portfolio.png">
</a>
</div>
<nav>
<ul>
<li class="current">Home</li>
<li>Story</li>
<li>Product</li>
<li>Clinique</li>
<li>Promotions</li>
</ul>
</nav>
</header>
To align text horizontally center use text-align:center. In your to align nav bar content center just add text-align:center to header nav
header nav {
margin-left: auto;
text-align:center;
margin-right: auto;
margin-top: 10px;
}
In below code snippet I have added some images for demonstration purpose.
header {
background: #ffffff;
color: #000000;
padding-top: 30px;
min-height: 70px;
border-bottom: #000000 3px solid;
}
header a {
color: #000000;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
header li {
float: center;
display: inline;
padding: 0 20px 0 20px;
}
header nav {
margin-left: auto;
text-align:center;
margin-right: auto;
margin-top: 10px;
}
header #smcontent {
float: left;
}
header #smcontent a {
margin: 0;
}
header #smcontent img {
width: 20px;
}
header .logoimg .center {
display: block;
margin-left: auto;
margin-right: auto;
width: 20%;
}
header a:hover {
color: #cccccc;
font-weight: bold;
}
<header>
<div class="container">
<div id="smcontent">
<a href="https://twitter.com/">
<img src="https://image.shutterstock.com/image-photo/kiev-ukraine-may-26-2015twitter-260nw-281505518.jpg">
</a>
<a href="https://facebook.com/">
<img src="https://image.shutterstock.com/image-photo/kiev-ukraine-april-27-2015-260nw-278925056.jpg">
</a>
</div>
<div class="logoimg">
<a href="index.html">
<img class="center" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png">
</a>
</div>
<nav>
<ul>
<li class="current">Home</li>
<li>Story</li>
<li>Product</li>
<li>Clinique</li>
<li>Promotions</li>
</ul>
</nav>
</div>
</header>

Cannot Get Text to go to the Top of Page

I cannot get the text for navigation to display inline and in the grey bar at the top of the page. I am guessing there is some type of problem with my CSS. Before I had the text included with the class="box" and the formatting was working, but the buttons wouldn't work, so I created a new div class="new" so the buttons would work.
HTML:
<div class="box-contents">
<img src="../images/LOGO.png" alt="Stephen Crawford Photography Logo">
</div>
<div class="box">
</div>
<div class="new">
<nav>
<ul>
<li class="button"><a class="button-text" href="portfolio.html">portfolio</a></li>
<li class="button"><a class="button-text" href="../html/about.html">about</a></li>
<li class="button"><a class="button-text" href="../html/contact.html">contact</a></li>
</ul>
</nav>
</div>
CSS:
#charset "utf-8";
/* CSS Document */
body{
margin: 0;
padding: 0;
font-size: 100%;
}
.box {
width: auto;
height: 120px;
background: grey;
overflow: hidden;
opacity: 0.85;
position: relative;
z-index: 3;
}
.box-contents {
margin: auto;
width: 100%;
overflow: hidden;
position: absolute;
opacity: 1 !important;
z-index: 4;
}
.new ul{
font-family: 'Roboto Condensed', sans-serif;
font-weight: lighter;
letter-spacing: 2px;
font-size: 2em;
margin-top: 0;
padding-top: 25px;
float: right;
margin-right: 100px;
position: relative;
list-style-type: none;
margin: 0;
padding: 0;
display: inline;
z-index: 99;
}
a{
text-decoration: none;
color: inherit;
}
img{
display: block;
float: left;
width: 150px;
margin: 10px 2%;
}
.images{
display: block;
width: 800px;
float: inherit;
margin: auto;
padding-bottom: 20px;
padding-top: 20px;
}
The picture below shows the formatting issues
The most appropriate approach is to contain your logo and navigation links within your <nav> element. Right now they're broken out into separate elements which will cause them to stack. Recently, flexbox has become the best solution for situations like this. You'll be flexing your nav container and the unordered list inside. The margin property on the ul has left set to auto, which will push the navigation items to the right.
I've removed all of the unnecessary elements since we really just need <nav>. Hopefully this helps. I've included only the relevant CSS to give you a better understanding of what is happening.
nav {
display: flex;
align-items: center;
background-color: grey;
}
nav ul {
display: flex;
margin: 0 0 0 auto;
list-style-type: none;
}
nav ul li {
padding-right: 10px;
}
<nav>
<img src="//placehold.it/150x50" alt="Stephen Crawford Photography Logo">
<ul>
<li class="button"><a class="button-text" href="portfolio.html">portfolio</a></li>
<li class="button"><a class="button-text" href="../html/about.html">about</a></li>
<li class="button"><a class="button-text" href="../html/contact.html">contact</a></li>
</ul>
</nav>
Add this css to your code and <div class="new"> //content </div> inside <div class="box"> </div> like so
.new ul li{
display: inline-block;
}
body{
margin: 0;
padding: 0;
font-size: 100%;
}
.box {
width: auto;
height: 120px;
background: grey;
overflow: hidden;
opacity: 0.85;
position: relative;
z-index: 3;
}
.box-contents {
margin: auto;
width: 100%;
overflow: hidden;
position: absolute;
opacity: 1 !important;
z-index: 4;
}
.new ul{
font-family: 'Roboto Condensed', sans-serif;
font-weight: lighter;
letter-spacing: 2px;
font-size: 2em;
margin-top: 0;
padding-top: 25px;
float: right;
margin-right: 100px;
position: relative;
list-style-type: none;
margin: 0;
padding: 0;
display: inline;
z-index: 99;
}
.new ul li{
display: inline-block;
}
a{
text-decoration: none;
color: inherit;
}
img{
display: block;
float: left;
width: 150px;
margin: 10px 2%;
}
.images{
display: block;
width: 800px;
float: inherit;
margin: auto;
padding-bottom: 20px;
padding-top: 20px;
}
<body>
<div class="box-contents">
<img src="../images/LOGO.png" alt="Stephen Crawford Photography Logo">
</div>
<div class="box">
<div class="new">
<nav>
<ul>
<li class="button"><a class="button-text" href="portfolio.html">portfolio</a></li>
<li class="button"><a class="button-text" href="../html/about.html">about</a></li>
<li class="button"><a class="button-text" href="../html/contact.html">contact</a></li>
</ul>
</nav>
</div>
</div>
<div>
<img class="images" src="../images/DSC_7997-Edit.jpg" alt="Trevi Fountain, Rome">
<img class="images" src="../images/DSC_1195.jpg" alt="Lake Hartwell">
<img class="images" src="../images/DSC_7564-Edit.jpg" alt="Cinque Terre">
<img class="images" src="../images/_DSC4277.jpg" alt="Park City">
<img class="images" src="../images/LAC_6060.jpg" alt="Toccoa Falls">
<img class="images" src="../images/DSC_7547-Edit.jpg" alt="Cinque Terre">
<img class="images" src="../images/_DSC8776.jpg" alt="Campfire">
<img class="images" src="../images/_DSC2203-Edit.jpg" alt="Milkyway">
<img class="images" src="../images/_DSC8094-Edit.jpg" alt="Lake Hartwell">
</div>
</body>
Put your div with class new in div with class box
<div class="box">
<div class="new">...</div>
</div>
and then change your css by replacing .new ul with .new li
.new li{
...
}

Why is one of my gallery images out of place?

Here's a link to my site (Currently a work in progress so very basic right now):
website
I just can't figure out why one image is messed up. It's not even the last image in the gallery and it's the same size as all the other images. Maybe i'm missing the obvious, I'm pretty tired.
Here's the code: https://jsfiddle.net/b0r684hh/2/
HTML
<div class="row">
<div class="col-lg-10">
<h1 class="page-header">Ryk Design</h1>
</div>
<!--<div class="col-lg-2 page-header">
<ul class="nav navbar-nav">
<li>
<a class="invert" href="#">About</a>
</li>
<li>
<a class="invert" href="#">Contact</a>
</li>
</ul>
</div>-->
</div>
<div class="row">
<div id="photos">
<ul id="photo-gallery">
<li>
<a href="img/DoomQuoteMed.png">
<img src="img/thumbs/DoomQuoteThumb.png">
</a>
</li>
<li>
<a href="img/crop/SlaveBlur.png">
<img src="img/thumbs/SlaveBlur.png">
</a>
</li>
<li>
<a href="img/love wins2.png">
<img src="img/love wins2.png">
</a>
</li>
<li>
<a href="img/rd.png">
<img src="img/thumbs/rdcrop.png">
</a>
</li>
<li>
<a href="img/crop/taplrCrop.png">
<img src="img/thumbs/taplrCrop.png">
</a>
</li>
<li>
<a href="img/cider.jpg">
<img src="img/cider.jpg">
</a>
</li>
<!--<li>
<a href="http://40.media.tumblr.com/7302cf024c924726c6ad99bb80b0be41/tumblr_nauccbKUCw1tubinno1_1280.jpg">
<img src="http://40.media.tumblr.com/7302cf024c924726c6ad99bb80b0be41/tumblr_nauccbKUCw1tubinno1_1280.jpg">
</a>
</li>
<li>
<a href="http://41.media.tumblr.com/fddb3f2b0bdf390efd7ea87372e75fa5/tumblr_ndyg3pYbKW1tubinno1_1280.jpg">
<img src="http://41.media.tumblr.com/fddb3f2b0bdf390efd7ea87372e75fa5/tumblr_ndyg3pYbKW1tubinno1_1280.jpg">
</a>
</li>
<li>
<a href="http://41.media.tumblr.com/758a5cb9046fde53138ad0f55527ca25/tumblr_ndyfdoR6Wp1tubinno1_1280.jpg">
<img src="http://41.media.tumblr.com/758a5cb9046fde53138ad0f55527ca25/tumblr_ndyfdoR6Wp1tubinno1_1280.jpg">
</a>
</li>-->
</ul>
</div>
</div>
CSS
a,
h2,
h3 {
font-family: 'Montserrat', sans-serif;
margin: 0;
}
h1 {
font-family: "Avant Garde", Avantgarde, "Century Gothic", CenturyGothic, "AppleGothic", sans-serif;
font-size: 92px;
text-transform: uppercase;
text-rendering: optimizeLegibility;
}
a {
color: #000;
}
.invert {
color: #fff;
background-color: #000;
}
.col-md-4 p {
padding-top: 5px;
}
a:hover {
color: #000;
background-color: #fff;
text-decoration: none;
}
.nav,
.navbar-nav {
margin: 0;
padding: 0;
}
body {
margin: 0;
}
.page-header {
border: none;
padding-bottom: 40px;
}
footer {
margin: 50px 0;
}
.row {
padding-left: 0;
}
#photos {
opacity: .88;
}
#photos img {
width: 30%;
float: left;
display: block;
margin: 1px;
}
ul {
list-style: none;
margin: 0px auto;
padding: 10px;
display: block;
max-width: 100%;
text-align: center;
}
#overlay {
background: rgba(0, 0, 0, .8);
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
display: none;
text-align: center;
}
#overlay img {
margin: 10% auto 0;
width: 550px;
border-radius: 5px;
}
#photos {
width: 100%;
padding: 10px;
}
#photo-gallery {
width: 100%;
}
Cheers for the help guys!
You should float li elements instead of img elements, just change the css,
Here is the updated jsfiddle
#photos li {
width: 30%;
float: left;
display: block;
margin: 1px;
}
#photos img {
max-width: 100%
}
Your problem is due to the first image having a bigger height than the others. If you inspect your images, you'll see that all of them have a height of 339px - EXCEPT the first image - that one is 339.33.
Since you are floating your images, this very slight difference throws off the alignment. There 2 solutions:
1) Set all of the images the same height
2) Clear the first image of each row so it resets the alignment. So with your example, having 3 images across you would want to clear the 4th image:
#photo-gallery li:nth-child(3n+1) img {
clear: left;
}
its seems the first image height is .39 bigger so pushes them around. But you should be able to do this better etc
something like this might help as well.
http://codepen.io/simondavies/pen/VaRBMo
<div class="image-outer-wrapper">
<div class="image-wrapper CasinoLink"></div>
<div class="image-wrapper CorpLink"></div>
<div class="image-wrapper CasinoLink"></div>
<div class="image-wrapper CorpLink"></div>
<div class="image-wrapper CasinoLink"></div>
<div class="image-wrapper CorpLink"></div>
</div>
.image-outer-wrapper {
margin: 0 auto;
padding: 0;
width: 100%;
height: auto;
position: relative;
}
.image-outer-wrapper:before,
.image-outer-wrapper:after { content: " "; display: table;}
.image-outer-wrapper:after {clear: both;}
.image-outer-wrapper .image-wrapper {
margin:5px;
position: relative;
float: left;
width: 279px;
height: 237px;
text-decoration: none;
transition: background-position 500ms;
cursor: pointer;
}
.image-outer-wrapper .image-wrapper.CasinoLink {
background: url('http://placehold.it/558x237');
background-position: 0 0;
}
.image-outer-wrapper .image-wrapper.CorpLink {
background: url('http://placehold.it/558x237');
background-position: 0 0;
}
.image-outer-wrapper .image-wrapper:hover {
background-position: -279px 0;
}