I am trying to set the background to go horizontally across this bar to be behind the logo and nav
Here is the HTML
<!--NAV-->
<div class="header">
<div class="title">
<img src="img/logo.png">
</div><!--/.title-->
<nav class="nav">
<ul>
<li>Home</li>
<li>Services</li>
<li>Contact</li>
</ul>
</nav>
</div>
and here is the css
.title
{
display:inline;
float:left;
margin:0 auto;
}
.nav
{
font-size:20px;
color:#0F3;
display:inline;
float:right;
margin:0 1.7%;
padding:1% 4% 0;
}
ul
{
display:inline;
float:right;
list-style:none;
}
li
{
display:inline;
}
You can modify .header class.
Keep in mind that floating divs don't affect the size of the surrounding element. So you can use overflow: auto; in header class to make the surrounding element take the floating elements in consideration:
Example
.header {
background: url(http://lorempixel.com/800/100/abstract/);
width: 100%;
overflow: auto;
}
img {
padding: 12px;
}
.title {
display: inline;
float: left;
margin: 0 auto;
}
.nav {
font-size: 20px;
color: black;
text-shadow: 2px 2px 2px rgba(150, 150, 150, 1);
display: inline;
float: right;
margin: 0 1.7%;
padding: 0 4%;
padding-top: 1%;
margin-bottom: 0;
}
ul {
display: inline;
float: right;
list-style: none;
}
li {
display: inline;
}
<div class="header">
<div class="title">
<img src="http://lorempixel.com/100/40/people/">
</div>
<!--/.title-->
<nav class="nav">
<ul>
<li>Home</li>
<li>Services</li>
<li>Contact</li>
</ul>
</nav>
</div>
Related
I am trying to move my Nav Bar to the Top Right with my logo on the Top Left all on one line. But I am unable to do so and I could use some help. I am new to learning HTML and CSS. The nav bar currently rests below the name/logo on the top right.
Demo
.container{
padding: 40px 40px 40px 40px;
margin: 10px 10px 10px 10px;
position: relative;
display: block;
text-shadow: 1px 1px 1px rgba(0,0,0,0.2);
text-align: left;
border: 1px solid blue;
color:white;
}
.container h1{
text-align: left;
font-size: 50px;
}
.container nav{
height: 70px;
line-height: 70px;
border: 1px solid green;
}
.container nav ul {
list-style: none;
width: 100%;
border: 1px solid red;
text-align:right
}
.container nav ul li {
display: inline-block;
font-size: 100%;
color:white;
margin-right: 0;
border : 1px solid yellow;
}
<div class="container">
<header>
<h1>Srikanth Gowda</h1>
</header>
<nav class="navbar">
<ul>
<li>Design</li>
<li>Photography</li>
<li>About</li>
<li>Contact</li>
<li>Blog</li>
</ul>
</nav>
</div>
One way would be to use float.
Per documentation found on MDN Web Docs
The float CSS property specifies that an element should be placed along the left or right side of its container, allowing text and inline elements to wrap around it. The element is removed from the normal flow of the web page, though still remaining a part of the flow (in contrast to absolute positioning).
Learn more about float
Add the following to your CSS
.container header {
float: left;
}
Change your .container nav to:
.container nav{
height: 70px;
line-height: 70px;
border: 1px solid green;
float: right;
}
This will get you what you want...
Working demo
A couple of quick and dirty methods as starting points:
Method 1, using flexbox:
.container{
display: flex;
align-items: center;
justify-content: space-between;
}
nav ul {
display: flex;
list-style: none;
}
nav ul li {
margin-right: 20px;
}
<div class="container">
<header>
<h1>Srikanth Gowda</h1>
</header>
<nav class="navbar">
<ul>
<li>Design</li>
<li>Photography</li>
<li>About</li>
<li>Contact</li>
<li>Blog</li>
</ul>
</nav>
</div>
Method 2, using floats:
header {
float: left;
}
nav {
float: right;
}
nav ul {
list-style: none;
padding-top: 18px;
}
nav ul li {
display: inline-block;
margin-right: 5px;
}
<div class="container">
<header>
<h1>Srikanth Gowda</h1>
</header>
<nav class="navbar">
<ul>
<li>Design</li>
<li>Photography</li>
<li>About</li>
<li>Contact</li>
<li>Blog</li>
</ul>
</nav>
</div>
you can use flex box property. and float right and left to align your div
.container{
position: relative;
display: block;
text-shadow: 1px 1px 1px rgba(0,0,0,0.2);
height:70px;
border: 1px solid blue;
color:blue;
}
.container h1{
font-size: 50px;
}
.container .navbar{
height: auto;
line-height: auto;
border: 1px solid green;
float:right;
}
.container .navbar ul {
list-style: none;
width: auto;
border: 1px solid red;
}
.container .navbar ul li {
display: inline;
font-size: 100%;
color:blue;
border : 1px solid yellow;
}
.header{
float:left;
}
.d1{
float:clear;
height:100px;
width:1000px;
}
<div class="container">
<div class="header">
<h4>Srikanth Gowda</h4>
</div>
<div class="navbar">
<ul>
<li>Design</li>
<li>Photography</li>
<li>About</li>
<li>Contact</li>
<li>Blog</li>
</ul>
</div>
</div>
<div>
<div class="d1">
rest of your content
eferfer
</div></div>
When you want to align elements in a div on the same line but on different sides always use the float property. You can change the header's position to left and nav to right by using the float property as below:
.header{
float:left;
}
.container nav{
height: 70px;
line-height: 70px;
border: 1px solid green;
float: right;
}
There are two ways. the first one is given below.
.container header{
display:inline-block;
float:left;
}
.navbar{
display:inline-block;
float:right;
}
The second method is you can put them in a table like below.
<div class="container">
<table>
<tr>
<td>
<header>
<h1>Srikanth Gowda</h1>
</header>
</td>
<td>
<nav class="navbar">
<ul>
<li>Design</li>
<li>Photography</li>
<li>About</li>
<li>Contact</li>
<li>Blog</li>
</ul>
</nav>
</td>
</tr>
</table>
</div>
So i'm currently working on building my own website but ran into some trouble when it came to centering my actual ul within my navigation bar. The nav bar is already centered and fine but i am trying to center the actual ul and still keep it left aligned. I am using Brackets text editor. Any Help ?
Thanks in advance and heres my CSS code:
body {
background-color: #333333;
margin: 100 0;
}
.mainimg {
border-style: solid;
width: 80%;
margin: 10 auto;
}
.mainimg img {}
.nav-bar {
text-align: center;
width: 85%;
margin: 0 auto;
}
.nav-bar ul {
width: 100%;
list-style-type: none;
margin: 0 auto;
padding: 0 auto;
overflow: hidden;
background-color: #333333;
}
.nav-bar li {
float: left;
width: 10%;
}
.nav-bar li a {
display: block;
color: white;
text-align: center;
padding: 16px;
text-decoration: none;
}
.nav-bar li a:hover {
background-color: #111111;
}
<html>
<head>
<title>Satori</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="imageslider">
<img src="images/SATORI%20ARROW%20LEFT.png" width=100px alt="left">
<img class="mainimg" src="images/satori-for-web-background.png" alt="oauihgoiw">
<img src="images/SATORI%20ARROW%20RIGHT.png" width=100px alt="right">
</div>
<div class="nav-bar">
<ul>
<li>Station</li>
<li>Search</li>
<li>Shop</li>
<li>Films</li>
<li>Art</li>
<li>Podcast</li>
<li>Blog</li>
<li>Games</li>
<li>Music</li>
</ul>
</div>
</body>
</html>
Update below css part
.nav-bar li {
display:inline-flex; /* OR display:inline-block */
/* float:left; */
/* width: 10%; */
}
body {
background-color: #333333;
margin: 100 0;
}
.mainimg {
border-style: solid;
width: 80%;
margin: 10 auto;
}
.mainimg img {}
.nav-bar {
text-align: center;
width: 85%;
margin: 0 auto;
}
.nav-bar ul {
width: 100%;
list-style-type: none;
margin: 0 auto;
padding: 0 auto;
overflow: hidden;
background-color: #333333;
}
.nav-bar li {
display:inline-flex; /* OR display:inline-block */
/* float:left; */
/* width: 10%; */
}
.nav-bar li a {
display: block;
color: white;
text-align: center;
padding: 16px;
text-decoration: none;
}
.nav-bar li a:hover {
background-color: #111111;
}
<div class="imageslider">
<img src="images/SATORI%20ARROW%20LEFT.png" width=100px alt="left">
<img class="mainimg" src="images/satori-for-web-background.png" alt="oauihgoiw">
<img src="images/SATORI%20ARROW%20RIGHT.png" width=100px alt="right">
</div>
<div class="nav-bar">
<ul>
<li>Station</li>
<li>Search</li>
<li>Shop</li>
<li>Films</li>
<li>Art</li>
<li>Podcast</li>
<li>Blog</li>
<li>Games</li>
<li>Music</li>
</ul>
</div>
I'm completely new at coding so I apologize in advance for this question.
I'm trying to centrally align an image to the right of a fixed navigation menu.
Here's my code right now:
HTML:
ul {
list-style-type: none;
float: left;
position: relative;
margin: 0;
padding: 0;
}
li {
padding: 3px;
margin-bottom: 8px;
background-color: #33b5e5;
color: #ffffff;
font-family: "Courier";
}
div.image{
display: block;
display: inline-block;
float: left;
}
<nav>
<ul>
<li>about</li>
<li>cv</li>
<li>adventures</li>
<li>books</li>
<li>blog</li>
<li>quotes</li>
<li>contact</li>
</ul>
</nav>
<div class="image"><img src="vietnam.jpg" alt="" width="450" height="350" /></div>
I want the navigation menu to be fixed to the left, and the image to be to the right of the navigation menu but at the CENTER of the page. here's an image of what I have right now: current homepage. How can I put the image at the center of the page?
Thanks!
If you are trying the centre the whole lot then your nav and div.image should be inline-block to display them side by side. You should then put the lot in a wrapper which you can centre:
section {text-align:center}
nav,
div.image {
display: inline-block;
vertical-align:middle;
}
ul {
list-style-type: none;
position: relative;
margin: 0;
padding: 0;
text-align:left;
}
li {
padding: 3px;
margin-bottom: 8px;
background-color: #33b5e5;
color: #ffffff;
font-family: "Courier";
}
<section>
<nav>
<ul>
<li>about</li>
<li>cv</li>
<li>adventures</li>
<li>books</li>
<li>blog</li>
<li>quotes</li>
<li>contact</li>
</ul>
</nav>
<div class="image"><img src="vietnam.jpg" alt="" width="450" height="350" /></div>
<section>
Updated...
Now that I better understand what you are after (nav on left, image centered in remaining space on the right) it seems that flex-box is the simplest solution:
section {
display:flex;
justify-content: space-between;
align-items: flex-start;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
text-align:left;
}
li {
padding: 3px;
margin-bottom: 8px;
background-color: #33b5e5;
color: #ffffff;
font-family: "Courier";
}
<section>
<nav>
<ul>
<li>about</li>
<li>cv</li>
<li>adventures</li>
<li>books</li>
<li>blog</li>
<li>quotes</li>
<li>contact</li>
</ul>
</nav>
<div class="image"><img src="vietnam.jpg" alt="" width="450" height="350" /></div>
<section>
Attempt 3...
Based on your comments (fyi, you really should try harder to explain your requirements) it sounds like what you want is to centre the image regardless of the nav's position. In the following example I have used margin:auto to centre the .image and position:absolute to fix the nav in the top left. Now the image in centred but the nav may overlap it depending on the viewport width.
nav {display:block; position:absolute;}
ul {
list-style-type: none;
margin: 0;
padding: 0;
text-align:left;
}
li {
padding: 3px;
margin-bottom: 8px;
background-color: #33b5e5;
color: #ffffff;
font-family: "Courier";
}
.image {display:block; width:450px; margin:auto;}
<nav>
<ul>
<li>about</li>
<li>cv</li>
<li>adventures</li>
<li>books</li>
<li>blog</li>
<li>quotes</li>
<li>contact</li>
</ul>
</nav>
<div class="image"><img src="vietnam.jpg" alt="" width="450" height="350" /></div>
you can use your div class if class is not work then use id for div like id="image"
#media All and (max-width: 641px) {
ul {
list-style-type: none;
float: left;
position: relative;
margin: 0;
padding: 0;
}
li {
padding: 3px;
margin-bottom: 8px;
background-color: #33b5e5;
color: #ffffff;
font-family: "Courier";
}
div.image{
padding-top: 25%;
margin-left: 16%;
}
}
#media screen and (min-width: 641px) and (max-width: 800px) {
ul {
list-style-type: none;
float: left;
position: relative;
margin: 0;
padding: 0;
}
li {
padding: 3px;
margin-bottom: 8px;
background-color: #33b5e5;
color: #ffffff;
font-family: "Courier";
}
div.image{
padding-top: 23%;
margin-left: 21%;
}
}
#media screen and (min-width: 801px) and (max-width: 1024px) {
ul {
list-style-type: none;
float: left;
position: relative;
margin: 0;
padding: 0;
}
li {
padding: 3px;
margin-bottom: 8px;
background-color: #33b5e5;
color: #ffffff;
font-family: "Courier";
}
div.image{
padding-top: 18%;
margin-left: 24%;
}
}
#media screen and (min-width: 1025px){
ul {
list-style-type: none;
float: left;
position: relative;
margin: 0;
padding: 0;
}
li {
padding: 3px;
margin-bottom: 8px;
background-color: #33b5e5;
color: #ffffff;
font-family: "Courier";
}
div.image{
padding-top: 13%;
margin-left: 30%;
}
}
}
<nav>
<ul>
<li>about</li>
<li>cv</li>
<li>adventures</li>
<li>books</li>
<li>blog</li>
<li>quotes</li>
<li>contact</li>
</ul>
</nav>
<div class="image"><img src="vietnam.jpg" alt="" width="450" height="350" /></div>
kindly check my codes i'll create for you
.image{
display: block;
text-align: center;
}
.image > img{
background-color: red;
}
You can also check this link for your exact code http://codepen.io/myco27/pen/dNxWWK
You can put the img element into nav and style nav with display:flex, justify-content: space-between See the code snippet
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
li {
padding: 3px;
margin-bottom: 8px;
background-color: #33b5e5;
color: #ffffff;
font-family: "Courier";
}
nav {
display: flex;
justify-content: space-between;
}
<nav>
<ul>
<li>about</li>
<li>cv</li>
<li>adventures</li>
<li>books</li>
<li>blog</li>
<li>quotes</li>
<li>contact</li>
</ul>
<div class="image"><img src="vietnam.jpg" alt="" width="450" height="350" /></div>
</nav>
In the #nav ul li, i cant seem to fix the position of the text without changing the size of the block. Whenever I try to use padding, the size of the block changes. How can I move the text without changing the size of the block? Here is the code.
<!DOCTYPE html>
<html>
<head>
<style>
body
{
padding: 0;
background-color: #FFC0CB;
}
#container
{
margin: 0 auto;
width:100%;
height: 1500px;
padding: 0px;
}
#header
{
overflow: auto;
background-color: red;
margin: 0px;
}
#headTable
{
float:right;
}
#logo
{
background-color: green;
margin: 5px 0px 5px 70px;
float: left;
width:150px;
height:100px;
}
#headTable ul
{
list-style-type: none;
margin: 0;
}
#headTable ul li
{
font-size: 35px;
padding-top: 20px;
color: black;
float: left;
margin: 20px 50px;
}
#headTable ul li:hover
{
background-color: blue;
color:red;
}
#nav
{
clear: both;
width:100%;
height: 95px;
background-color: purple;
}
#nav ul
{
overflow: auto;/*
background-color: yellow;*/
margin: 0px;
padding: 0px;
}
#nav ul li
{
background-color: black;
color:white;
font-size: 30px;
list-style-type: none;
text-decoration: underline;
margin: 20px;
padding: 10px 10px 10px 20px;
float: left;
/*text-indent: 0px;
*/}
#page
{
float: left;
margin: 10px;
height:700px;
width:700px;
background-color: #FFC0CB;
}
#page p
{
padding:100px 0px 0px 50px;
font-size: 20px;
color: navy;
}
#content
{
height: 1000px;
width: 1334px;
position: absolute;
margin:0px;
background-color: #00B2EE;
}
#top
{
float: right;
position: relative;
margin: 10px;
background-color: #7A67EE;
width:500px;
height:300px;
}
#low
{
position: relative;
clear: both;
float: right;
margin:-300px 10px 10px 10px;
background-color: #7A67EE;
width:500px;
height:300px;
}
</style>
</head>
<body>
<div id="container">
<div id="header">
<div id="logo">
<img src="plane.jpg" width="150" height="100">
</div>
<div id="headTable">
<ul>
<li>Google</li>
<li>Google</li>
<li>Google</li>
</ul>
</div>
</div>
<div id="nav">
<ul>
<li>Menu</li>
<li>Blog</li>
<li>Ins</li>
<li>BBC</li>
<li>Contact</li>
<li>Wow</li>
<li>Doge</li>
<li>Such fun</li>
</ul>
</div>
<div id="content">
<div id="page">
<p>This is a paragraph that should
stay intact inside the id of Page.
</p>
</div>
<div id="top">
<p>THis is a paragraph that should
stay intact inside the id of top.
</p>
</div>
<div id="low">
<p>This is a paragraph that should
stay intact inside the id of bottom.
</p>
</div>
</div>
</div>
</body>
</html>
You need to set the width for an li element, and wrap the nav text in span tags. Then you can move them left or right and the width of the nav li will not change.
<li><span>Menu</span></li>
<li><span>Blog</span></li>
<li><span>Ins</span></li>
<li><span>BBC</span></li>
<li><span>Contact</span></li>
<li><span>Wow</span></li>
<li><span>Doge</span></li>
<li><span>Such fun</span></li>
#nav ul li{width:70px;background-color: black;color:white;font-size: 30px;list-style-type: none;text-decoration: underline;margin: 20px;padding: 10px 10px 10px 20px;float: left;}
#nav ul li span{margin-left:70px;}
See a working solution here: http://jsfiddle.net/mtruty/73uav/
This might be a really basic css question but I tried to create my fluid layout following instructions from a book, so far my header and nav bar seems to be in the place but the content div isn't, also I'd like to make my content height flexible because it's for a dynamic web app so the footer should be positioned below it accordingly. Ok so here's the mockup of what id like to achieve
<body>
<div id="header">
<h1>LOGO</h1>
<ul>
<li> Home </li>
<li> Logout </li>
</ul>
</div>
<div id="navigation">
<ul>
<li>Home</li>
<li>My account</li>
<li>Help</li>
<li>Contact Us </li>
</ul>
</div>
<div id="personalised">
<p>Hey there</p>
</div>
<div id="content">
</div>
<div id="footer">
<p>© TEST</p>
</div>
</body>
</html>
here's my css code:
body{
width: 90%;
margin: 0 auto;}
#content {
overflow: auto;
height: 29em;}
#header{
height: 60px;
overflow: hidden;
}
#header h1 {
float: left;
}
#header ul {
float: right;
}
#header li {
display: inline;
padding: 0.5em;
}
#personalised p {
float: left;
width: 20%;
margin-top:5%;}
#navigation{
margin: 1%;}
#navigation ul {
font-family: Arial, Verdana;
font-size: 14px;
padding: 0px;
list-style: none;
}
div#navigation {
float:right;
position: absolute;
top: 10%;
right: 5%;
}
#navigation ul li {
display: block;
position: relative;
float: left;
}
#navigation li ul { display: none; }
#header, #footer, #navigation, #personalised {
margin: 1%;
}
#footer {
padding: 0.5em 0;
font-family: Arial, Verdana;
font-size: 10px;
text-align: center;}
I know this is long, but I'd really appreciate your help. Thanks in advance
Try working on your formatting first. (It's not too bad, but can use improvement.) That's one of the biggest benefits to you is code that you can read. You can look through what I've done here and play with what you like. http://jsfiddle.net/mPH8X/
<head>
<style>
div {
border: 1px dashed #FF0000;
}
body {
margin: 0px;
padding: 0px;
}
.clear {
clear: both;
}
#header {
min-height: 60px;
overflow: hidden;
margin: 1%;
}
#header h1 {
float: left;
}
#header ul {
float: right;
}
#header li {
display: inline;
padding: 0.5em;
}
#navigation{
margin: 1%;
float: right;
}
#navigation ul {
font-family: Arial, Verdana;
font-size: 14px;
padding: 0px;
margin: 0px;
list-style: none;
}
#navigation ul li {
margin: 0px;
padding: 0px;
display: block;
position: relative;
float: left;
}
#navigation li ul {
display: none;
}
.body {
clear: both;
}
#personalised {
margin: 1%;
float: left;
width: 20%;
}
#content {
margin: 1%;
float; right;
min-height: 29em;
}
#personalised p {
margin: 0px;
padding: 0px;
}
#header, #footer, #navigation, #personalised {
}
#footer {
padding: 0.5em 0;
font-family: Arial, Verdana;
font-size: 10px;
text-align: center;
}
</style>
<body>
<div id="header">
<h1>LOGO</h1>
<ul>
<li> Home </li>
<li> Logout </li>
</ul>
<div class="clear"></div>
</div>
<div id="navigation">
<ul>
<li>Home</li>
<li>My account</li>
<li>Help</li>
<li>Contact Us </li>
</ul>
<div class="clear"></div>
</div>
<div class="body">
<div id="personalised">
<p>Hey there</p>
<div class="clear"></div>
</div>
<div id="content">
</div>
</div>
<div id="footer">
<p>© TEST</p>
</div>
</body>
</html>
Edit: Looking at your content statement, you are looking for CSS's min-height. Min-height will set it to a minimum height and grow when necessary. overflow: auto; says if your content stretches past the maximum height, add a scrollbar.
I think the culprit is this:
#content {
overflow: auto;
height: 29em;}
You are explicitly setting the height of the content div. Try setting it to inherit.
Here is a fiddle where the container grows according to the number of elements in it:
http://jsfiddle.net/pUb6q/2/
Uses your layout. The changes are
#content {
border:1px solid black;
float: right;
overflow: auto;
height: inherit;
}