I've created a basic layout and on the page are 2 links, one register and one login button.
Take a look at my jsfiddle link to see how it looks. There's a black box which will be the logo and you will see the green and blue boxes which are my buttons.
I need them at the top of the page.
http://jsfiddle.net/4EZa5/
Not sure what I need to do to the CSS to make the links sit at the top of the very page?
HTML:
<div id="accountLinks">
<ul>
<li class="login">Log in</li>
<li class="register">Register</li>
</ul>
</div>
CSS:
#accountLinks{
float: right;
height:20px;
width: 170px;
margin: 0;
padding: 0;
}
#accountLinks ul{
list-style-type: none;
margin: 0;
padding: 0;
}
#accountLinks li{
float: left;
text-align: center;
}
#accountLinks .login{
background: url(../images/button_login.gif) no-repeat;
width: 70px;
height: 20px;
color: #FFF;
}
#accountLinks .register{
background: url(../images/button_register.gif) no-repeat;
width: 70px;
height: 20px;
color: #FFF;
}
Thanks
Your H1 tag is a block element and is pushing the rest down. Just add float: left; to h1 css
h1{
width: 351px;
height: 49px;
background: #000;
text-indent: -9999px;
float: left;
}
To style the link only in login:
#accountLinks .login a {
color: #FFF;
}
#accountLinks .login a:hover {
color: yellow;
}
They're being pushed down by the <h1>Salesboard</h1> - is it possible to move that to just after the accountLinks div, or does that need to stay before them in the HTML?
If so, then this should fix the accountLinks:
#accountLinks{
position: absolute;
top: 0px;
right: 0px;
height:20px;
width: 170px;
}
See this fiddle: http://jsfiddle.net/NZ2T5/
I added a style next to the id="accountLinks" this will be easier to position you div which contains the login etc..
<h1>Salesboard</h1>
<div id="accountLinks" style="margin-top:-45px;">
<ul>
<li class="login">Log in</li>
<li class="register">Register</li>
</ul>
</div>
Simply place h1 at the bottom of #header.
You couldn't see your links, because they were floating left! underneath your css-styled Salesboard
Additionally your text-intend (9999) is such that no text will be shown.
Solution
Newer browsers offer, the attribute fixed which will do exactly as it says.
Add this "position: fixed;"
#accountLinks{
position: fixed;
top: 0px;
right: 0px;
height:20px;
width: 170px;
}
#Container{
width:100%;
}
Related
I have a navigation which holds either text or images for links. I want the image to change on hover, so am using CSS backgrounds inside an empty div. However, I am looking for a way of doing this without using "position: absolute;" as the containing a tag will not expand to fill its dimensions. I would also like to do this without using a transparent placeholder image as I want to find a more elegant solution.
Here's the jsfiddle and the code:
http://jsfiddle.net/urhLs736/1/
<nav id="navigation">
<ul>
<li><a onclick="example1.html">PAGE 1</a></li>
<li><a onclick="example2.html">PAGE 2</a></li>
<li><div id="nav-image"></div></li>
</ul>
</nav>
and for the CSS:
#navigation {
z-index: 1;
background-color: #3A5E90;
color: #FFFFFF;
text-align: center;
width: 100%;
padding-top: 5px;
padding-bottom: 5px;
}
#navigation.fixed {
position: fixed;
top: 0px;
}
#navigation li {
display: inline;
}
#navigation a {
cursor: pointer;
padding-left: 3.5%;
padding-right: 3.5%;
color: #FFFFFF;
text-decoration: none;
}
#navigation a:hover {
background: #FFFFFF;
color: #3A5E90;
padding-top: 2%;
padding-bottom: 2%;
}
#nav-image {
display: inline;
background: url('https://avatars1.githubusercontent.com/u/3081095?v=2&s=72') no-repeat;
background-size: 100%;
margin-bottom: -6px;
height: 24px;
width: 100px;
}
#nav-image:hover {
height: 24px;
width: 100px;
background: url('https://avatars3.githubusercontent.com/u/5278945?v=2&s=96') no-repeat;
background-size: 100%;
}
I think that your layout will work as is with a minor adjustment to the CSS:
#nav-image {
display: inline-block;
background: url('https://avatars1.githubusercontent.com/u/3081095?v=2&s=72') no-repeat;
background-size: 100%;
margin-bottom: -6px;
height: 24px;
width: 100px;
border: 1px dotted yellow;
}
If you use display: inline-block, the div will take up the specified width and height and the background image will be visible, and the hover effect will work as you expect.
See demo: http://jsfiddle.net/audetwebdesign/9fd1dxn4/
In order to achieve this, you have to change both your HTML and your CSS.
First, your HTML should go like this:
<nav id="navigation">
<ul>
<li><a onclick="example1.html">PAGE 1</a>
</li>
<li><a onclick="example2.html">PAGE 2</a>
</li>
<li id="nav-image">PAGE 3
</li>
</ul>
</nav>
Note that I have added some content in your empty div. If you have an empty <li>, you'll have no background at all (just like your example) since you have a 0x0 pixels li element. I have added some content so the li displays as a general rule, which anyways won't be necessary after you see the CSS, which is the following:
#navigation {
z-index: 1;
background-color: #3A5E90;
color: #FFFFFF;
text-align: center;
width: 100%;
padding-top: 5px;
padding-bottom: 5px;
}
#navigation.fixed {
position: fixed;
top: 0px;
}
#navigation li {
display: inline-block;
height: 24px;
width: 100px;
padding-left: 3.5%;
padding-right: 3.5%;
}
#navigation ul li a {
cursor: pointer;
padding:2% 3.5%;
color: #FFFFFF;
text-decoration: none;
display:block;
height: 24px;
width: 100px;
}
#navigation a:hover {
background: #FFFFFF;
color: #3A5E90;
}
#nav-image {
background: url('https://avatars1.githubusercontent.com/u/3081095?v=2&s=72') no-repeat;
background-size: 100%;
}
#nav-image:hover {
background: url('https://avatars3.githubusercontent.com/u/5278945?v=2&s=96') no-repeat;
background-size: 100%;
}
#nav-image:hover a {
background:transparent
}
OK, now you see I have made some changes and added width and height to the li (the same you had in your sample, but you can change it to anything you want). Now, if you delete the content inside the empty DIV, you'll see how the rendering changes. While it's very easy to solve, I'll leave it to you so you can practice and understand how the whole positioning and display thing works. Also, you can add paddings, margins, et
Here you have a fiddle so you can see it in action and play around
My webpage has static navigation menu at top, but is lowered a bit and background is visible above it. When text in page is scrolled down it goes beneath menu and then is again visible above the menu. How can I hide the part of text which is above menu. Also the background will be an image.
If I place the text in <div> element below menu and set overflow:auto, scroll bar is then moved to the side of div element, not the page body as it is intended to be.
EDIT: Here is jsfiddle link http://jsfiddle.net/EmpireGlitch/N9xg2/
HTML:
<div class="topline">
<div class="menu">
<ul class="interpage_navigation">
<li>Choice 1
</li>
<li id="active_tab">Choice 2
</li>
</div>
<div id="top_seperator"></div>
</div>
<div class="article">
<h1>Lorem ipsum</h1>
<p>Lorem ipsum.</p>
</div>
CSS:
.menu .interpage_navigation li {
background-color: rgba(25, 102, 25, 0.8);
}
.side, #top_seperator, #active_tab {
background-color: rgba(50, 205, 50, 0.8);
}
.topline {
position: fixed;
top: 60px;
width: 100%;
}
#top_seperator {
height: 40px;
width: 100%;
clear: both;
}
.menu {
margin:0px;
margin-left:100px;
position: absolute;
bottom: 40px;
}
.menu > ul {
overflow: auto;
list-style-type: none;
padding:0px;
padding-left: 15px;
margin:0px;
//border: solid blue 1px;
}
.menu li {
float:left;
margin:0px;
}
.menu .interpage_navigation li {
width:120px;
height: 40px;
margin-right: 15px;
font-family: verdana, arial;
text-align: center;
line-height: 40px;
text-decoration: none;
text-transform: uppercase;
}
.article {
background-color: rgba(200, 200, 200, 1);
margin-bottom: 20px;
padding:20px;
padding-top: 5px;
font-size: 18px;
position: absolute;
top: 0px;
margin-top: 125px;
left: 30%;
right:15%;
z-index: -1;
}
I have used the :before pseudo element to create an element to place over the top of the page - http://jsfiddle.net/N9xg2/1/
The problem with this is that it is dependant on having a solid colour.
You may want to re-think how you're positioning the article - using position:absolute is going to really limit you.
My solution was similar to Richard's, except I just gave .menu a background (and tweaked its padding).
.menu {
margin:0px;
padding-left:100px;
position: absolute;
bottom: 40px;
background-color: white;
width: 100%;
padding-top: 20px;
}
Demo here
But I know you want to use an image background. You can solve that problem by using:
background-attachment: fixed;
Demo here
The question doesn't describe this pretty well.
So I got three small images that are suppose to change on hover and work as a link, but it ''detects'' the hover only in a small part of the image. If I drag my mouse to the bottom of the image link, it's not even clickable, so the link only works in the top part of the image.
See for yourself:
http://jsfiddle.net/M3LC9/ (JSFiddle doesn't like pictures..)
<div class="kielet">
<nav>
<!--Englanti-->
<img class="icon" src="iconit/en.gif" title="in english" onmouseover="this.src='iconit/en_hover.gif'" onmouseout= "this.src='iconit/en.gif'">
<!--Ruotsi-->
<img class="icon" src="iconit/swe.gif" title="på svenska" onmouseover="this.src='iconit/swe_hover.gif'" onmouseout="this.src='iconit/swe.gif'">
<!--Venäjä-->
<img class="icon" src="iconit/ru.gif" title="По русски" onmouseover="this.src='iconit/ru_hover.gif'" onmouseout="this.src='iconit/ru.gif'">
</div>
.kielet {
top:0px;
width:100%;
background: black;
right: 0px;
margin-bottom:0px;
padding:0px;
}
.kielet nav {
right: 0px;
margin-right: 0px;
text-align: right;
}
.icon {
width: 50px;
height: 100%;
right: 0px;
margin: 20px;
margin-top:0px;
margin-bottom:0px;
display:inline;
padding: 0px;
}
You currently have your images set to display as inline. This will make them adhere to any line-height defaults a browser may have set on your a element, keeping your a element at a smaller height. This can be visualised in Chrome's Element Inspector:
To change this, simply set the display on your a elements to inline-block:
a {
display: inline-block;
}
JSFiddle demo.
Note that you may want to be a bit more specific with your a selector by specifying .kielet nav a, for instance, or giving your a elements their own class identifier.
Try changing the display property to display:inline-block
.icon {
width: 50px;
height: 100%;
right: 0px;
margin: 20px;
margin-top:0px;
margin-bottom:0px;
display:inline-block; <----
padding: 0px;
}
JSFiddle
Usually you don't implement your hover-state with javascript and <img />
You can easily do this with CSS.
HTML
<div class="kielet">
<nav>
<!--Englanti-->
<!--Ruotsi-->
<!--Venäjä-->
</nav>
</div>
CSS
.kielet {
background: black;
padding: 5px;
text-align: center;
}
a.icon {
display: inline-block;
width: 16px;
heiht: 16px;
line-height: 16px;
}
a.icon_ru { background: url(http://placehold.it/16x16/ffc) center no-repeat; }
a.icon_ru:hover { background: url(http://placehold.it/16x16/ff0) center no-repeat; }
a.icon_en { background: url(http://placehold.it/16x16/cff) center no-repeat; }
a.icon_en:hover { background: url(http://placehold.it/16x16/0ff) center no-repeat; }
a.icon_swe { background: url(http://placehold.it/16x16/fcf) center no-repeat; }
a.icon_swe:hover { background: url(http://placehold.it/16x16/f0f) center no-repeat; }
jsFiddle
I am trying to align a menu to the right of a div. As it stands the menu is sitting in the div top left. I want it top right... what am I missing? I have added text-align: right.... Ive tried float: right... I just can't get it.
<div id="UserPanel">
<div id="menu">
<ul>
<li>All Apps | </li>
<li>My Account | </li>
<li>Support | </li>
<li>Register / Login</li>
</ul>
</div>
</div>
The CSS CODE is
#UserPanel
{
width: 962;
height: 98;
background-image: url('bg-topbar.png');
}
#menu
{
text-align: right;
width: 962;
}
#menu ul /* Remove The Bullets */
{
list-style: none;
padding: 0;
margin: 0;
}
#menu li /* Place list in line */
{
float: left;
margin: 0 0.15em;
}
#menu li a /* Design it */
{
font-size: 0.75em;
background: url(background.gif) bottom left repeat-x;
height: 2em;
line-height: 2em;
float: left;
width: 8em;
display: block;
/* border: 0.1em solid #dcdce9; */
color: #C0C0C0;
text-decoration: none; /* Remove Underline */
text-align: center;
}
use this
#menu {
float: right;
text-align: right;
width: auto;
}
here is the jsFiddle Link
Try this:
#UserPanel
{
width: 962;
height: 98;
background-image: url('bg-topbar.png');
float : right;
}
JSFiddle
Add float:right; to #userpanel
Try this-
#menu
{
position:absolute;
top:0;
right:0;
width: 962;
}
LIke this
DEMO
CSS
#menu
{
text-align: right;
float:right;
}
First of all you have not defined width and height attribute properly. What i mean is either defined it with px or %; e.g width:962px;
By the way here is an working example http://jsfiddle.net/hT4Bd/1/
Update #menu styles as follows.
#menu
{
text-align: right;
width: 962;
float: right;
}
None of these worked but I did find Arif Khan gave me an idea. I solved this by doing...
#menu
{
position: relative;
left: 500px;
}
I am trying to put a logo between two menu lists, but it isnt working. I made a PSD before hand and this is what it is supposed to look like:
However, I just cant accomplish this in html and css for some reason. Here is what it looks like right now:
How am I supposed to do this? It just wont work for some reason.
My HTML:
<body>
<div class="nav">
<div class="container">
<div class="menu-left">
<ul>
<li><a id="hello" href="#">Home</a></li>
<li><a id="about" href="#">About</a></li>
</ul>
</div>
<div class="logo"></div>
<div class="menu-right">
<ul>
<li><a id="portfolio" href="#">Portfolio</a></li>
<li><a id="contact" href="#">Contact</a></li>
</ul>
</div>
</div>
</div>
</body>
My CSS:
div {
display: block;
}
.nav {
height: 64px;
background: url(navigation_bg.png);
width: 100%;
margin:0 auto;
}
.container {
width: 960px;
position: relative;
margin:0 auto;
}
.menu-left, .menu-right {
width: 300px;
height: 64px;
position: absolute;
top: 0;
}
.menu-left {
left: 200px;
}
.menu-right {
right: 200px;
}
.nav ul {
list-style:none;
margin: 0;
padding: 0;
height: 64px;
line-height: 64px;
}
.nav ul li {
float: left;
font-family: 'FuturaStdBoldCondensed';
font-size: 20px;
text-shadow: 1px 1px 1px black;
text-transform: uppercase;
margin:0 20px;
}
.menu-right ul li {
float: right;
}
.logo {
margin: 0 auto;
width: 140px;
height: 128px;
background: url(logo.png) center center rgba(0,0,0, 0.4);
border-radius: 0 0 20px 20px;
}
How do I get this perfectly centered?
I wouldn't actually separate menu into two pieces. Make it in one piece, and then set one of the middle LI to class lets say hspace and apply padding-left (or right) to that class. Then absolutely postion your logo.
To perfectly center the text in LI, just apply text-align: center; to it.
http://jsfiddle.net/L2VrN/
I got the logo centered in between the two menus.
To do this, I put another DIV around the logo with left:50% and then a negative value for left on the logo to compensate for it's width.
You might have to play around with your left/right values for your menus and logo to get the positioning exactly where you want it.
This is how to center your ul...
Remove the "margin:0 auto" from the "nav", there's no need for it as the width is 100%, and you want to center the ul.
Set the right width to the "UL" them use the 'margin: 0 auto" on it.