i've created a simple topbar with text centered. My question is then how can i place a text logo in the left side with the text still appearing in the center of the navigation bar and still being responsive?
css:
nav {
position: absolute;
top: 0;
width: 100%;
height: 40px;
background: #000;
opacity: 1.0;
text-align: center;
}
nav li {
display: inline-block;
padding: 10px 10px;
}
nav li a {
color: #757575;
text-transform: uppercase;
}
#media only screen and (max-width: 520px) {
nav li {
padding: 10px 4px;
}
nav li a {
font-size: 14px;
}
}
html:
<section id="screen1">
<p>Scroll down</p>
<nav>
<ul>
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Team</li>
<li>Contact</li>
</ul>
</nav>
</section>
#user3646311, the CSS style that will accomplish having an image, text or any other element on the left while still centering the text is float: left;. When you float an element you are telling it to go to one side and not effect the other elements that it may be touching. It is also important that you set the parent element with position: relative; which will tell the floating child to not go outside the bounds of the parent. You can read a lot more about floats on css-tricks. I wrote a working example for you to play with at jsfiddle.net.
HTML
<nav>
<img src="http://doc.jsfiddle.net/_downloads/jsfiddle-logo.png" />
<span>Text Logo</span>
<ul>
<li>Home</li>
</ul>
</nav>
CSS
nav {
position: relative;
}
/* This is how to float an image */
nav img {
float: left;
max-height: 50px;
}
/* This is how to float text */
nav span {
color: #FFF;
float: left;
line-height: 3em; /* Use line-height to vertically position your text */
}
Related
Currently there is a functional and togglable navigation menu within a webpage. An image is also embedded within the navigation menu, position below the text.
It would be nice to reposition the image to be at the very bottom of the navigation menu to eliminate any empty space below it. What would be the best approach to accomplish this?
Here is a picture for context.
HTML
<html>
<div id="sideNav">
<nav>
<ul>
<li>HOME</li>
<li>COVID-19</li>
<li>SERVICES</li>
<li>REVIEWS</li>
<li>CONTACT</li>
</ul>
<div id="nav_pic">
<img src ="images/nav_lotus.JPEG">
</div>
</nav>
</div>
</html>
CSS
#sideNav{
width: 200px; /*changes the width of sideNav*/
height: 100vh;
position: fixed;
right: -250px; /*make side bar intially hidden*/
top:0;
background: #009688;
z-index: 2;
transition: 0.33s;
}
.nav ul li{
list-style: none;
margin: 45px 15px;
}
.nav ul li a{
text-decoration: none;
color: #fff;
font-family: 'Raleway', sans-serif;
}
.nav_pic{
vertical-align: bottom;
}
Add flex style to nav container.
nav {
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
}
i'm trying to push down this h1 to go below my navigation tag.
The way i've structured it is that there's header tag, inside the header tag theres a container tag, inside the container tag is the h1 tag, after the h1 tag theres a nav tag with a ul inside the nav tag and a li inside the ul.
.container {
width: 50%;
margin: auto;
}
/* Header */
header {
height: 100vh;
}
header h1 {}
/* An unordered list is basically an array of items*/
ul {
list-style-type: none;
float: right;
/* Top bottom right left*/
/* Margin-top pushes it down.*/
}
/* List item specifies how it should be aka 1 item of the array */
li {
display: inline-block;
/* Top bottom right left*/
}
/* A means all the links */
a {
text-decoration: none;
text-transform: uppercase;
color: black;
padding: 5px 20px;
/* Seperates them*/
border: 1px solid transparent;
}
<div class="container">
<h1>Random Number Generator</h1>
<nav>
<ul>
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</div>
Add h1 below the nav
<div class="container">
<nav>
<ul>
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
<h1>Random Number Generator</h1>
</div>
Moving the <h1> tag below your <nav> element will move the header element below the navigation element in the DOM (document object model).
.container {
width: 50%;
margin: auto;
}
/* Header */
header {
height: 100vh;
}
header h1 {}
/* An unordered list is basically an array of items*/
ul {
list-style-type: none;
float: right;
/* Top bottom right left*/
/* Margin-top pushes it down.*/
}
/* List item specifies how it should be aka 1 item of the array */
li {
display: inline-block;
/* Top bottom right left*/
}
/* A means all the links */
a {
text-decoration: none;
text-transform: uppercase;
color: black;
padding: 5px 20px;
/* Seperates them*/
border: 1px solid transparent;
}
<div class="container">
<nav>
<ul>
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
<h1>Random Number Generator</h1>
</div>
I'm having a hard time practicing and can't figure this out to save my life. 7 hours trying to find solutions to no avail! Nothing will budge.
I simply want the text to be in the middle like this site or this site a link. Instead of all white I want an opaque black box with text over it. My text is just all over the place. And the logo on the left and the nav bar/ menu to the right of it.
https://imgur.com/a/1oCKaco
Link to the code.
https://codepen.io/admitdefeat/pen/BEyMzK
HTML
<div class="post-body">
<p>Do you need something done to your home or around your home? Do you feel as if your home doesn't have the same appeal as when you got it? Call our team of professionals and we can do what is needed to your home, yard and business that will improve
its look and how you feel when you see it!</p>
</div>
CSS
post-body{
padding-top: 3rem;
position: relative;
box-sizing: inherit;
}
div {
display: block;
}
Thank you.
I've watched videos on how positioning, divs, containers and tried putting information together.However, there is something I'm not understanding.
I want the page to be aligned and positioned.
Just don't get stressed out, if you want the menu to be always on top right just give it the rules:
`#menu{
position: fixed;
right: 5px; /* or the amount you want */
top: 5px; /* or the amount you want */
}`
apply the same logic on the logo, and finally add text-align: center; for your text to be centered in the page, and voila !
In your .post-body class, remove the padding-top: 3rem and position: relative as they are messing up your formatting. Then add text-align: center to center the text on the page, and add margin: 100px 20% to restrict the positioning of the text. You can change both of these values to whatever you desire, depending on the positioning you are aiming for. The first value (100px) is how far from the top you want the text to begin (y-axis), and the second value (20%) is how far from the left and right edge you want the text to be (x-axis).
Note that using a % value for the second value will dynamically resize the text for you depending on the screen size. In this case, it will always be 20% of the screen size from the left and right edge of whatever device you are using.
body {
font-family: "Basier";
font-size: 20px;
}
html {
background: url(summer.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
}
.post-body {
box-sizing: inherit;
text-align: center;
margin: 100px 20%;
}
div {
display: block;
}
#font-face {
font-family: "Basier";
src: url("basiersquare-regular-webfont.ttf");
}
.logo {
width: 150px;
height: 140 px;
}
/*Strip the ul of padding and list styling*/
ul {
list-style-type: none;
margin: 0;
padding: 0;
position: absolute;
}
/*Create a horizontal list with spacing*/
li {
display: inline-block;
float: left;
margin-right: 0 px;
}
/*Style for menu links*/
li a {
display: block;
min-width: 140px;
height: 50px;
text-align: center;
line-height: 50px;
font-family: "Basier";
color: #fff;
background: #2f3036;
text-decoration: none;
}
/*Hover state for top level links*/
li:hover a {
background: #F4D03F;
}
/*Style for dropdown links*/
li:hover ul a {
background: #F4D03F;
color: #2f3036;
height: 40px;
line-height: 40px;
}
/*Hover state for dropdown links*/
li:hover ul a:hover {
background: f1c40f;
color: #fff;
}
/*Hide dropdown links until they are needed*/
li ul {
display: none;
}
/*Make dropdown links vertical*/
li ul li {
display: block;
float: none;
}
/*Prevent text wrapping*/
li ul li a {
width: auto;
min-width: 100px;
padding: 0 20px;
}
/*Display the dropdown on hover*/
ul li a:hover+.hidden,
.hidden:hover {
display: block;
}
/*Style 'show menu' label button and hide it by default*/
.show-menu {
font-family: "Basier";
text-decoration: none;
color: #F4D03F;
background: #F4D03F;
text-align: center;
padding: 10px 0;
display: none;
}
/*Hide checkbox*/
input[type=checkbox] {
display: none;
}
/*Show menu when invisible checkbox is checked*/
input[type=checkbox]:checked~#menu {
display: block;
}
#media screen and (max-width: 760px) {
/*Make dropdown links appear inline*/
ul {
position: static;
display: none;
}
/*Create vertical spacing*/
li {
margin-bottom: 1px;
}
/*Make all menu links full width*/
ul li,
li a {
width: 100%;
}
/*Display 'show menu' link*/
.show-menu {
display: block;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>CLT Designs</title>
<link href="hoise.ico" rel="shortcut icon" type="image/x-icon">
<meta charset="utf-8">
<link href="designs.css" rel="stylesheet">
</head>
<body>
<img class="logo" src="clt.png" alt="logoclt">
<h2> RENOVATION PROJECT</h2>
<label for="show-menu" class="show-menu">Show Menu</label>
<input type="checkbox" id="show-menu" role="button">
<ul id="menu">
<li>Home</li>
<li>About</li>
<li>
Services
<ul class="hidden">
<li>What is Design + Build?</li>
<li>Our Process</li>
</ul>
</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
<div class="post-body">
<p>Do you need something done to your home or around your home? Do you feel as if your home doesn't have the same appeal as when you got it? Call our team of professionals and we can do what is needed to your home, yard and business that will improve
its look and how you feel when you see it!</p>
</div>
</body>
</html>
I tried doing it with absolute and relative positioning, hope this solves your question. i modified your code just a little bit.
Check this codepen
https://codepen.io/jls314/pen/oOgVGz
You wanted the logo to the left and the navbar to the right so I put them together in a header tag and position them.
<header>
<img class="logo" src="clt.png" alt="logoclt">
<label for="show-menu" class="show-menu">Show Menu</label>
<input type="checkbox" id="show-menu" role="button">
<ul id="menu">
<li>Home</li>
<li>About</li>
<li>
Services
<ul class="hidden">
<li>What is Design + Build?</li>
<li>Our Process</li>
</ul>
</li>
<li>Portfolio</li>
<li>Contact</li>
</ul>
</header>
this is the CSS:
header {
position: relative;
}
.logo {
position: absolute;
left: 10px;
width: 150px;
height: 140px;
float: left;
}
#menu {
position: absolute;
right: 10px;
}
.post-body{
position: relative;
top: 200px;
box-sizing: inherit;
width: 50%;
margin: 0px auto;
background: rgba(0,0,0,.7);
color: white;
}
I have been learning htm, css and php all at once. I am creating a website that touch's all of
these things. Its for educational purposes only.
How can I make it so that I have my websites name beside the navigation text with it all centered.
Like right now I have the website name in the nav bar with the navigation text beside it but the
navigation text isnt in the center of the line its a bit low. Here is the site: http://66.172.10.179/resolver/
CSS:
/* Body */
body {
background-color: #FF5930;
margin: 0px;
}
a {
text-decoration: none;
color: white;
}
/* Navigation bar */
header {
background-color: #FF4719;
padding: 5px 0 8px 15px;
}
header nav h2 {
display: inline;
font-family: sans-serif;
}
header nav ul {
display: inline;
}
header nav ul li {
display: inline;
padding: 0 5px;
font-size: 15px;
font-family: sans-serif;
color: white;
height: 10px;
}
header nav ul li:hover {
}
HTML:
<header>
<nav>
<h2>Skype Resolver</h2>
<ul>
<li>Resolver</li>
<li>Blacklisting</li>
<li>Purchase API</li>
<li>Domain tools</li>
<li>Spam tools</li>
<li>Misc tools</li>
</ul>
</nav>
</header>
I added line-height to H2, create a CSS thing for nav and added: display: inline-block;
Worked like a charm!
To achieve this without actually putting in any line height you can add the following:
CSS
nav{
display:table;
}
nav h2 {
vertical-align: middle;
}
nav ul{
vertical-align: middle;
}
This will vertically center your text without you having to guess the line height...
DEMO JSFiddle
I'm trying to make my logo on my navbar be centered and the other items of the navbar be around it. Currently the logo is in the center of the text items where it should be but I cannot get the whole logo with the text around it to center.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Charity</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id='nav'>
<ul class='navigation'>
<li><a href='#'>Home</a></li>
<li><a href='#'>Events</a></li>
</ul>
<img src="images/main-logo.png" id="logo" />
<ul class="navigation">
<li><a href='#'>Full list of Charities</a></li>
</ul>
</div><!-- end of nav -->
</body>
</html>
The css
html, body {
padding: 0;
margin: 0;
}
#logo {
float: left;
margin:auto;
}
#nav {
margin:auto;
background-color: #CCC;
height: 66px;
box-shadow: 0px 1px 10px #5E5E5E;
}
.navigation {
list-style-type: none;
float: left;
}
li {
display: inline;
padding: 15px;
margin:auto;
}
#nav a {
font-size: 1.6em;
text-transform: uppercase;
text-shadow: 0 0 0.3em #464646;
font-weight: bold;
font-family: century gothic;
text-decoration: none;
color: #262626;
opacity: 0.26;
}
#nav a:hover {
opacity: 0.36;
}
If the point is to center the image between the li items, just make it an item also:
<div id='nav'>
<ul class='navigation'>
<li><a href='#'>Home</a></li>
<li><a href='#'>Events</a></li>
<li><img src="images/main-logo.png" id="logo" /></li>
<li><a href='#'>Full list of Charities</a></li>
</ul>
</div>
!!! Don't forget to remove the #logo style !!!
Check it out: http://jsfiddle.net/QUkPj/
In order for margins to work on an image, you need to declare display:block on them. img tags by default are displayed as inline elements (and margin will not do anything to inline elements).
See here: http://jsfiddle.net/9xtea/1/
because you want to center the logo and have the rest of the elements aligned to left and right of that, you'll need to use position absolute:
#logo { position: absolute; top: 0; left: 50%; margin-left: -??px; } /* negative margin half the width of the logo */
.navigation-left { list-style-type: none; position: absolute; right: 50%; margin-right: ??px } /* positive margin half the width of the logo */
.navigation-right { list-style-type: none; position: absolute; left: 50%; margin-left: ??px } /* positive margin half the width of the logo */
this centers the logo in the nav bar and then puts the left and right menu options around it regardless of their size
http://jsfiddle.net/EWf56/