Ok so obviously I'm doing something wrong. Basically I'm trying to create a vertical navigation bar at the top of my page, to the right of a picture.
It should look like this:
Home Resume Contact Me
Somehow it keeps ending up like this:
Home Resume
Contact Me
Can you guys take a look and help me out? This is my first website. Thanks!
Here's my code:
HTML
html {
background-color: #ffffff;
}
img {
width: 20%;
float: left;
}
#menu {
width: 550px;
height: 35px;
font-size: 55px;
font-family: Courier, Serif;
text-align: center;
float: right;
margin-right: 300px;
margin-top: 50px;
}
#menu ul {
height: auto;
}
#menu li {
display: inline;
}
#menu a {
text-decoration: none;
color: #000000;
}
#menu a:hover {
color: #224466;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<title>Tyler Tilton</title>
</head>
<body>
<div id="menu">
<ul>
<li>Home
</li>
<li>Bio
</li>
<li>Contact Me
</li>
</ul>
</div>
<img src="C:\Users\Tyler\Desktop\Personal Website\Images\Profile Pic.png" />
</body>
</html>
Your code is a bit messy. The issue lies mostly in your #menu class. Your width is too small, you're text is too big, you have unnecessary margins and floats added. Remove all of that or adjust it and your list will align horizontally:
#menu {
/*width: 550px;*/ //too small for text size
height: 35px;
/*font-size: 55px;*/ //to big for width size
font-family: Courier, Serif;
text-align: center;
/*float: right;*/ //not necessary, at least in your demo, pushing text off screen
/*margin-right: 300px;*/ //not necessary, at least in your demo
}
FIDDLE
I think it is the font-size in #menu. Try reducing the font-size to 40px in #menu. It should bring them in one line.
Hope it helps!
Related
So im making a website for a school project and all was hunky dory until i tried to put a paragraph element in and it displays above the title text behind the background color
.container {
width: 80%;
margin: 0;
padding: 0;
}
#logotext {
float: left;
font-family: 'Doppio One';
margin-left: 25px;
}
nav {
float: right;
}
#nav {
list-style-type: none;
text-decoration: none;
margin-top: 35px;
}
ul li {
display: inline;
}
li a {
text-decoration: none;
color: white;
}
li a:hover {
color: #fc9516;
}
.darkwrap {
background-color: #414a4c;
position: fixed;
overflow: hidden;
}
.active {
color: #22cc25;
}
#clock {
position: absolute;
top: 0;
right: 0;
margin-top: 25px;
margin-right: 25px;
font-family: Rajdhani;
font-size: 30px;
}
<div class="container darkwrap">
<div id="logotext">
<h1>JF Web Design</h1>
</div>
<!-- Navigation Bar -->
<nav>
<ul id="nav">
<li> Page 1 </li>
<li> About </li>
<li> Page 3 </li>
</ul>
</nav>
</div>
</header>
<span id="clock"></span>
<p>
Hello
</p>
<footer></footer>
i usedchrome to highlight the faulty element so its clear whats happening here its literall positioned at the top behind the bg color
Console Highhlighted element
.darkwrap is position: fixed.
This takes it out of normal flow and locks its position relative to the viewport.
The rest of the content is laid out as normal as if the .darkwrap element didn't exist … so it ends up covered up by it.
You could use margins to compensate for the space covered up by .darkwrap when the viewport is scrolled to the top. I would simply avoid using position: fixed in the first place: The benefits of having the menu on screen all the time very rarely outweigh the drawback of using up all that vertical space all the time.
If you use float: left and float:right please remember to add clear:both to the next element on the website. Here is fixed code:
https://codepen.io/anon/pen/jKRqLz
I am trying to make a template for my webpage. I am creating a header and a footer, and have the content in between. But for some reason, I cant get any of it to work. I have been fooling with this for hours and cant find answers.
I have a logo, I am trying to position it inside the that way it looks clean. But I cant. I wont stay centered on my navigation text! I then notice when I resize my browser, it shifts all my navigation links until they all fit on the screen. How do I fix that?
Upon looking around for the fix, I noticed that I should instead convert all my position: absolute; top: (so many px) left: (so many px); to percent style measurements..no such luck. Once I get this working, I should be pretty much over the hardest part.
here is the css file:
//this is not in the div tag rather a test logo outside.
#logo{
display: inline;
float: left;
}
.nav{
display: inline;
float: left;
width: 5;
border: 1px solid #C0C0C0;
margin: auto;
text-align: center;
}
.nav ul{
list-style-type: none;
}
.nav li{
display: inline;
}
.nav li img{
height: 30px;
}
.nav a{
text-decoration: none;
padding: 20px 5px 20px 20px;
font-weight: 900;
color: #C0C0C0;
font-family: monospace;
font-size: 20px;
display: inline;
}
.nav a:visited{
color: #C0C0C0;
}
.nav a:hover{
color: black;
}
here is the html
</head>
<meta charset="UTF-8">
<meta name="description" content="This is a website that offers free information on IT">
<body>
<!--
Creating the navigation bar. I used nav as the dic class name with an unordered list
-->
<img src="Images/logo.png">
<div class="nav">
<ul>
<li><img src="Images/logo.png"></li>
<li> Home</li>
<li>Contact</li>
<li>Service</li>
<li>About</li>
</ul>
</div>
<div class="ad">
<center>
<img src="Images/head_pic.jpg">
<center>
</div>``
adding
min-width: (whatever);
fixed most of my issues.
I am learning html/css and have the following issue when aligning the "navigation menu" to the left. There's a small gap (see the pic below with a question mark)
can someone tell me how to remove the gap on the left side?
Here is my html/css code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
#wrapper {
width: 800px;
margin-right: auto;
margin-left: auto;
}
#header {
height: 200px;
width: 800px;
background-color: #CCC;
}
#navi {
height: 50px;
background-color: #036;
width: 800px;
margin: 0px;
padding: 0px;
}
ul {
}
#content-area {
height: 400px;
width: 800px;
background-color: #FFC;
}
#footer {
height: 100px;
width: 800px;
background-color: #000;
}
h2 {
color: #FFF;
text-align: center;
margin: 0px;
padding-top: 50px;
}
h3 {
color: #FFF;
text-align: center;
padding-top: 10px;
margin: 0px;
}
p {
font-family: Tahoma, Geneva, sans-serif;
font-size: 18px;
padding: 10px;
margin: 0px;
}
ul {
list-style-type: none;
margin: 0px;
}
li {
font-family: Arial, Helvetica, sans-serif;
color: #FFF;
display: block;
font-size: 12px;
margin-top: 10px;
margin-right: 10px;
float: left;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="header"><h2>This is the header</h2></div><!--header end-->
<div id="navi">
<ul>
<li>Facebook</li>
<li>Twitter</li>
<li>LinkdIn</li>
<li>Google Plus</li>
</ul>
</div><!--navi end-->
<div id="content-area"><p>Isn't saw evening shall open them had behold thing said evening i herb. Yielding kind second night image. Grass void green. Make Man given replenish brought. Spirit them seed fifth for living said his. Man abundantly.<br /><br />
Sixth yielding saying. Make female said they're night from fourth you'll make signs be. Our. Earth from. Replenish form living grass tree creepeth own. Had rule land from living, replenish appear the their days shall bearing waters moving seas living you, forth fourth.<br /><br />
Sixth whose stars i a. Creeping sea second above beast living signs created had first, face male dry our a his.</p></div>
<!--content area end-->
<div id="footer"><h3>This is the Footer</h3></div><!--footer end-->
</div><!--wrapper end-->
</body>
</html>
Apply padding:0; for your ul style.
ul {
list-style-type: none;
margin: 0px;
padding:0;
}
The space is being applied from the default user agent style sheet.
You can remove it by explicitly setting padding, margin of <ul> to 0.
It's a common practice to override it throughout the document like
*{
margin:0;
padding:0;
}
Demo
Please check this
ul {
list-style-type: none;
margin: 0px;
padding: 0px;
}
Add
ul{
padding:0;
}
This will solve this issue. In general, you can use the following at the top of your CSS file:
*{
padding:0;
margin:0;
}
If you use this snippet at the top of your CSS, these problems won't occur and default padding etc. vary from browser-to-browser. So this will make it more consistent.
I can't see where you are using CSS position property? This is quite helpful. Also you can use these resources:
CSS Box model
CSS Padding
CSS Margin
CSS Positioning
more CSS Positioning
You can use the 'Try it yourself' option to see it in real action. It's helpful and a good practice to set to zero all paddings and margins at the beginning at your code, like this:
body{
padding:0;
margin:0;
}
I would suggest you to avoid floating and use:
display: inline-block;
also you should give your ul id and apply the css settings to that #ulid >li this way you avoiding the rest of your li to get the menu rules.
Also I will recommend using some reset code as suggested in other answers so your CSS wont include the default browser CSS rules.
here are my modifications:
#ulmenu > li {
font-family: Arial, Helvetica, sans-serif;
color: #FFF;
font-size: 12px;
display: inline-block;
line-height: 50px;
padding-left: 10px;
padding-right: 0px;
margin: 0px;
}
#ulmenu{
margin:0px;
padding:0px;
list-style-type: none;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="header"><h2>This is the header</h2></div><!--header end-->
<div id="navi">
<ul id="ulmenu">
<li>Facebook</li>
<li>Twitter</li>
<li>LinkdIn</li>
<li>Google Plus</li>
</ul>
I just ran into the same issue and all the paddings and margins were zero already, after much trawling through the inspector, I noticed there was text-indent on the li
li{
margin:0;
padding:0;
text-indent:0;
}
Fixed my issue.
(HTML / CSS newbie here) It seems I cannot find the right specifier to prevent a menu bar
from wrapping around to the next line if the user narrows the browser window under a certain threshold. My working sample is this:
http://www.w3schools.com/css/tryit.asp?filename=trycss_navbar_horizontal_float_advanced
Below is the unmodified code from that site:
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
li {
float: left;
}
a:link, a:visited {
display: block;
width: 120px;
font-weight: bold;
color: #FFFFFF;
background-color: #98bf21;
text-align: center;
padding: 4px;
text-decoration: none;
text-transform: uppercase;
}
a:hover, a:active {
background-color: #7A991A;
}
</style>
</head>
<body>
<ul>
<li>Home</li>
<li>News</li>
<li>Contact</li>
<li>About</li>
</ul>
</body>
</html>
I found some references to "white-space: nowrap;" but I couldn't get it to work (maybe because none of these other samples related to such a simple example as above). Any clues appreciated !
Best,
Chris
just add some css width to the <ul> with the fixed width of your navbar, like in this JSFIDDLE
or if the width of your navbar is fluid, use css min-width rather than width
I have a couple un-ordered lists on my page. Both lists use list-style: disc inside;. Each list's list-items have a couple div's inside them. The problem is that the list-item's content takes up multiple lines and the disc is appearing vertically, at the bottom of the multi-line list-item.
Here is a screenshot kind of showing the problem I am experiencing. Note that I stole the image from a similar question, it is not my HTML or CSS.
Here is a striped down version of my HTML:
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="billing_form">
<div id="purchase_items">
<h2>Your purchase</h2>
<h4>Items:</h4>
<div class="items">
<ul>
<li>
<div class="item">First Product - one year license</div>
<div class="price">$99.00 USD</div>
</li>
<li>
<div class="item">Second product & 3 year Product Plan</div>
<div class="price">$125.00 USD</div>
</li>
</ul>
</div>
<div class="subtotal">SUBTOTAL: $224.00 USD</div>
<h4>Discounts:</h4>
<div class="discount">
<ul>
<li>
<div class="item">A really long discount item name - with extra info on three lines!</div>
<div class="price">- $20.00 USD</div>
</li>
</ul>
</div>
<div class="total">TOTAL: $204.00 USD</div>
</div>
</div>
</body>
</html>
And here is the CSS, as small as I thought was relevant:
html
{
font-family: sans-serif;
}
#billing_form
{
width: 350px;
margin: 0 auto;
font-size: 14px;
background-color: #EEEEEE;
}
#billing_form .items
{
position:relative;
}
#billing_form .discount
{
position:relative;
color:#3665B0;
}
#billing_form ul
{
margin: 0;
padding: 0;
list-style: disc inside;
}
#billing_form .items .item,
#billing_form .discount .item
{
display: inline-block;
width: 190px;
}
#billing_form .price
{
float: right;
padding-left: 20px;
}
#billing_form .items,
#billing_form .discount,
#billing_form .subtotal,
#billing_form .total
{
width: 100%;
}
#billing_form .subtotal,
#billing_form .total
{
text-align: right;
margin-top: 5px;
border-top: 1px solid;
font-weight: bold;
}
#billing_form #purchase_items
{
margin: 10px 10px 10px;
}
I found a similar SO question. Unfortunately, the accepted (and only) answer to it states to try position: relative; and vertical-align: top; but it didn't work for me. I tried it with both #billing_form ul and #billing_form ul li and neither worked. They also mention a IE7 hack fix, but I don't think that is relevant to me because I am experiencing the problem in Firefox 3 & 4 and Google Chrome.
Does anyone know how I can make the list-item bullets (discs) appear at the top of each line item?
It looks like vertical-align: text-top; will do what you want (see spec). I believe the reason is that you are creating tall inline blocks that are aligning to the top of the box which is being pushed up by the tall inline box so aligning to top doesn't do what you want. However, I believe that using text-top will align it with the top of where the text is (and the bullet point).
http://jsfiddle.net/Yayuj/ is a fiddle that does what you want (I believe) and has primarily this updated section from your CSS:
#billing_form .discount .item
{
display: inline-block;
width: 190px;
vertical-align: text-top;
}
Any other differences to what you have pasted above should be cosmetic.