Positioning of Custom Unordered List Text - css

I made a custom and horizontal unordered list. Here's a code example (nothing special):
<div id="steps-left">
<ul>
<li class="active one">Start</li>
</ul>
</div>
Here's the CSS that styles it:
#steps-left {
margin: 0 auto;
display:inline-block;
padding-bottom: 40px;
font-weight: 200;
font-size: 14px;color:#333333;
}
#steps-left ul {
margin: auto;
padding: 0;
float: left;
}
#steps-left li {
display: inline;
}
#steps-left ul li.active {
background: transparent url('../images/steps-left-active.png') no-repeat top left;
padding: 0px 0px 30px 46px; /* Makes the text move to the right of the bullet */
line-height: 0px;
margin-right: 30px; /* Defines the horizontal spacing between the bullets */
}
#steps-left ul li.active.one {
background-position: 0 0;
height: 42px;
width: 43px;
}
Problem:
I'm trying to figure out how to shift the text down, because as shown by the image below, the text is too high. So far, I haven't found anything that shifts the text down. I know the line-height property works, but that only works if the list is vertical, which in this case I want it horizontal.
Here is the image:
http://i.stack.imgur.com/ia24l.jpg

One option you have is making a custom tag pair for each of your menu items. Did you try that?
Do it as follows:
<div id="steps-left">
<ul>
// And here you would be able to apply line height.
<li class="active one lineheight">Start</li>
</ul>
<ul>
<li class="blah blah lineheight"> Second item </li>
</ul>
</div>
CSS
.lineheight {
//your desired lineheight.
example: line-height:100px;
}
Here you have a more specific and descriptive text on how to do it: Vertical-Align for li tag

Related

CSS center floated links [duplicate]

This question already has answers here:
How can I horizontally center an element?
(133 answers)
Closed 7 years ago.
I have a jsfiddle here - https://jsfiddle.net/1w5c1qq2/3/
I know this is simple but it's driving me mad
I have a div containing a ul list with a links in.
I need the links to be dead center, I need the gap between the links to be dead center.
Whatever I do the links are always slightly off.
Is there a way to have them dead center.
In the actual design it is obvious as the page is split with a color down the center.
<div class="block">
<ul>
<li>Link One</li>
<li>Link Two</li>
</ul>
</div>
Here is another way to do what you want. Using position: absolute;, left: 50%;, and transform: translateX(-50%); on the ul element.
*{
margin: 0;
padding: 0;
}
.block{
background: gray;
padding: 10px;
height: 20px;
}
ul{
list-style: none;
position: absolute;
left: 50%;
transform: translateX(-50%);
}
li{
text-align: center;
display: inline-block;
}
a{
background: white;
padding: 5px;
}
<div class="block">
<ul>
<li>Link One</li>
<li>Link Two</li>
</ul>
</div>
Reference:
https://css-tricks.com/centering-percentage-widthheight-elements/
Seems pretty dead center to me. It looks like the 'handle' (the tiny mark) to resize the window in jsFiddle isn't centered, so maybe that's why you think it didn't work.
However, it may also be a font issue. If the text in the links doesn't have the same width, the links themselves also won't be the same width. In that case, the block is centered, but the space between them won't be exactly in the middle. To solve that, give the links both the same width.
If you want the space between them to be centered, regardless of the elements width, you can do that as follows:
Put the lis next to each other and give them a fixed width so they can be positioned properly. Then, you can use text-align left and right to align the links inside them.
In the example below, I've used floats and a self-clearing on the ul to do this, but you could also use display: inline-block for the lis.
*{
margin: 0;
padding: 0;
}
.block{
background: gray;
padding: 10px ;
}
ul{
text-align: left;
list-style: none;
}
li{
display: block;
float: left;
width: 50%;
}
/* Right-align the link in the left li. */
li:first-child {
text-align: right;
}
/* Clear the floated li's */
ul::after {
content: "";
clear: both;
display: block;
}
a {
background: white;
padding: 5px;
margin: 0 5px;
width: 110px;
}
<div class="block">
<ul>
<li>Link One</li>
<li>Link Two with a longer text.</li>
</ul>
</div>
Here's the solution: https://jsfiddle.net/1w5c1qq2/8/. It boils down to giving both boxes each 50% of the available width, and aligning the text within those boxes to the right and the left, respectively. Always mind implicit white-space with display-inline-blocked boxes!
<div class="block">
<ul>
<li>Link One</li><!--
--><li>Link Two is wider just for show</li>
</ul>
</div>
And:
*{
margin: 0;
padding: 0;
}
.block{
background: gray;
padding: 10px ;
}
ul{
list-style: none;
}
li{
display: inline-block;
box-sizing: border-box;
width: 50%;
text-align: right;
padding-right: 3px;
}
li:last-of-type {
text-align: left;
padding-left: 3px;
}
a{
background: white;
padding: 5px;
}

How to show a div behind navigation on rollover

I'm still trying to get the hang of this web coding thing. Lord knows there is no knowing it all. SO, I'm reaching out in hopes of some help.
I have a div containing a <nav>, and let's say this nav has a <ul> with <li>'s inside it....
How would I go about making a picture appear behind the navigation based on the li highlighted.
Say I have a vertical menu:
Home | Gallery | Contacts
and I want the images to extent freely. Lets say Mario appears in behind contacts on rollover. I want his head to overlap Gallery, but he should be behind Contacts. I do intend for these images to be to the far left so as not to interfere to badly with navigation. Can I do this with JUST CSS or will I need jQuery.
Is this what are you looking for http://jsfiddle.net/rMCMt/ ?
You can use first-child and nth-child selectors: http://jsfiddle.net/Qq9Nm/
As menu items have different widths, you have to adjust the padding and the margin individually.
The CSS code, below:
li
{
box-shadow: 4px 4px 2px grey;
margin: 10px;
list-style-type: none;
float: left;
}
li:first-child:hover,
li:nth-child(2):hover,
li:nth-child(3):hover,
li:nth-child(4):hover,
li:nth-child(5):hover
{
background-size: 200px 200px;
background-repeat: no-repeat;
padding-bottom: 180px;
margin-bottom: -170px;
}
li:first-child:hover
{
background-image: url('http://goo.gl/RqQtl');
padding-right: 145px;
margin-right: -135px;
}
li:nth-child(2):hover
{
background-image: url('http://goo.gl/TWI0t');
padding-right: 130px;
margin-right: -120px;
}
li:nth-child(3):hover
{
background-image: url('http://goo.gl/xRPiq');
padding-right: 115px;
margin-right: -105px;
}
li:nth-child(4):hover
{
background-image: url('http://goo.gl/u3Akz');
padding-right: 140px;
margin-right: -130px;
}
li:nth-child(5):hover
{
background-image: url('http://goo.gl/Em9Ij');
padding-right: 140px;
margin-right: -130px;
}
and the html:
<nav>
<ul>
<li> HOME </li>
<li> GALLERY </li>
<li> CONTACTS </li>
<li> EXTRA1 </li>
<li> EXTRA2 </li>
</ul>
</nav>

Horizontal justified menu in CSS with bar in space [duplicate]

This question already has answers here:
How do I justify a horizontal list?
(10 answers)
Closed 7 years ago.
I have used the code from this question to create a horizontal menu where each item is evenly spaced.
Here is my version:
<div id="navigation">
<ul>
<li class="first">
Home
</li>
<li>
About us
</li>
<li>
What we cover
</li>
<li>
Monitoring agencies
</li>
<li>
Publishers
</li>
<li>
News
</li>
<li>
Contact us
</li>
<span></span>
</ul>
</div>
And the CSS:
#navigation {
text-align: justify;
}
#navigation ul span {
display: inline-block;
position: relative;
width: 100%;
height: 0;
}
#navigation ul {
display: inline;
list-style: none;
}
#navigation ul li {
display: inline
}
#navigation ul li a {
display: inline;
border-right: solid 1px #ccc;
}
#navigation ul li.last a {
border-right: none;
}
Is there a way to make the vertical lines move to the right such that they are halfway between the end of the a tags and the end of the li tags?
Here is a fiddle.
I've added an answer here.
Hack Using Extra Elements for the Spacer Motif
Fiddle reference: http://jsfiddle.net/audetwebdesign/bF6ey/
Consider the following HTML:
<div id="navigation">
<ul class="navigation">
<li class="first">
Home
</li>
<li class="spacer-motif">|</li>
<li>
About us
</li>
<li class="spacer-motif">|</li>
...
<li class="spacer-motif">|</li>
<li>
Contact us
</li>
</ul>
</div>
I added an extra list item between the links: <li class="spacer-motif">|</li> (yes, I cringe also...).
The CSS is as follows:
#navigation {
padding: 0 20px; /* add spacing at left/right edges of list */
}
#navigation ul {
display: table;
width: 100%;
list-style: none;
margin: 0;
padding: 0;
}
#navigation ul li {
display: table-cell;
text-align: center;
width: 1%; /* force cell to shrink-to-fit text */
outline: 1px dashed blue;
}
#navigation ul li.spacer-motif {
width: 10%; /* force spacers to take up a lot of space */
outline: none;
}
#navigation ul li a {
white-space: pre;
}
The layout is based on using table display types.
For ul, use display: table and set the width to 100%. Remember to zero out margin and padding values.
For li, use display: table-cell and text-align: center.
The trick is to force the table cells to shrink-to-fit the text labels by
setting width: 1%, and then, for the li.spacer-motif, set width: 10% to force
the spacers to expand (evenly) to fill up the line.
To keep the text links from wrapping into 2 or 3 lines, set white-space: pre in the <a> elements (the links).
Cleaning Up The Semantics
The problem here is that the link texts vary in width and this makes it impossible to simply use table-cell's with a right or left border and centered text. The extra spacing will vary among the links and the left/right border will not be evenly spaced between the link texts.
The way around this is to add extra elements. I used a pipe (|) but I suppose you could add a pseudo-element with a 1px border and center it and so on.
However, if the elements are a problem, they could be inserted using jQuery or JavaScript.
IE 7 Support - Hack for CSS
If you need IE7 support, you need to adjust the CSS according to the following:
CSS: table and table-cell replacement for IE7
here take a look at this fiddle HERE
I made some small adjustments. I changed display:inline; to float:left; and centerd the text.
The space is coming from the 5px padding i gave to the
ul li a
I would use display: table on ul and display: table-cell on li for this.
and even padding on both sides for the a tag
Depending on the spacing your after, something like this should work:
#navigation ul li a {
padding-right: 10px;
}
Change the 'px' value to your needs.
You can try something like this:
#navigation ul li a {
display: inline;
margin-right: -14px;
padding-right: 14px;
border-right: solid 1px #ccc;
}
But it might not be cross-browser.
http://jsfiddle.net/gjFYf/2/
I found that padding-right: 30px; in #navigation ul li a worked nicely.
I've got this working by inserting extra list elements into the list and then setting the width of these elements to a single pixel. I've also set their background color and removed the border on the hyperlinks.
New styles...
#navigation ul li.line {
display: inline-block;
*display: inline;
zoom: 1;
width: 1px;
background-color: #ccc;
height: 24px;
position: relative;
top: 5px;
}
#navigation ul li a {
display: inline;
line-height: 36px;
height: 36px;
text-decoration: none;
font-size: 18px;
color: #14328C;
font-weight: bold;
}
New Html snippet...
<li>
Publishers
<li class="line" />
</li>
It doesn't work in IE7 though. The text align seems to ignore the extra li unless it contains content.
Its also now semantically incorrect.
Fiddle.

Adding a background to current page menu item

Should look like this:
(source: gyazo.com)
My attempt
<div class="header">
<div class="container">
<img id="logo" src="img/logo.png"/>
<ul class="menu">
<li class="current">Home</li>
<li>Forums</li>
<li>Donate</li>
<li>Vote</li>
<li>Info</li>
</ul>
</div>
</div>
I use Current class for the current page background.
Added the header
.header {
width: 100%;
height: 86px;
background-image: url("../img/gradient.png");
background-repeat: repeat-x;
border-bottom: solid 1px #a2a2a2;
}
Floated menu to right, made it display inline and centered the text
.menu {
float: right;
padding: 2.7%;
}
.menu a{
color: #1e1e1e;
}
.menu a:hover{
color: #5e5e5e;
}
.menu li {
display: inline;
float: left;
margin-left: 10px;
padding-left: 20px;
padding-top: 5px;
}
Now the part of the current background
.current {
background-image: url("../img/hoverdiamond.png");
background-repeat: no-repeat;
width: 78px;
height: 36px;
padding-left: 20px;
padding-top: 5px;
color: white;
}
Result:
(source: gyazo.com)
Can you see theres a big space between the current and other items? How do I remove this? make it equal to others spaces.
Things I tried:
Adding position relative
result:
Menu item 'current' goes over the menu item 'forums'
I could not find any other way to do so, what am I doing wrong?
Try the following HTML:
<div class="header">
<div class="container">
<img id="logo" src="img/logo.png"/>
<ul class="menu">
<li class="current">Home</li>
<li>Forums</li>
<li>Donate</li>
<li>Vote</li>
<li>Info</li>
</ul>
</div>
</div>
With the following amends to your CSS:
.menu {
float: right;
padding: 2.7%;
}
.menu li {
float: left;
margin-left: 10px;
}
.menu a{
color: #1e1e1e;
display: block;
padding-left: 20px;
padding-top: 5px;
}
.menu a:hover{
color: #5e5e5e;
}
.current {
background-image: url("../img/hoverdiamond.png");
background-repeat: no-repeat;
color: white;
}
Your HTML was structured incorrectly ... you shouldn't be placing the <li> elements inside the anchor elements.
You also don't need to have display: inline; on the list items, as they are floated left anyway, they should already be inline.
In future, you may want to check that your HTML is valid using the W3C validator, it should explain any errors in your HTML and how you can fix them.
Let me know if the above doesn't fix it and I'll happily have another look.
EDIT: Forgot to also state that I removed the height and width on the current css declaration, that was unnecessary, and almost definitely causing the spacing issues.
Remove the width on .current. That is what's adding the extra spacing.
If you don't want to change that, change the spacing on the the adjacent li:
.current + li {
padding-left: 0;
}
Here is a simplified demo of what you are trying to accomplish. Learn from it:
HTML
<ul>
<li class="current">Home</li>
<li>Forums</li>
<li>Donate</li>
<li>Vote</li>
<li>Info</li>
</ul>
CSS
ul {
float: right;
}
li {
display: inline;
padding: 10px;
}
.current {
background-image: url('http://placekitten.com/200/200');
}
​
Demo

Text on footer Bar

My website URL is http://www.hentaireader.com
At the bottom right corner, I wish to put a small link on the red footer bar.
I have created a simple image of what I wish to do.
How can I achieve this??
The code on this page is a disaster. With that said you would have to remove the http://www.hentaireader.com/images/bar.gif image from the HTML and use CSS to create a background-image.
Something similar to this would be required...
CSS:
#footer-bar {
width:100%;
background-color:#f40000;
background-image: url(http://www.hentaireader.com/images/bar.gif);
background-position:top center;
background-repeat:no-repeat;
text-align: right;
margin-bottom: 10px;
}
#footer-bar ul {
width: 950px;
height: 30px;
margin-left: auto;
margin-right: auto;
position: relative;
left: 0px;
top: 0px;
}
#footer-bar li {
display: inline;
line-height: 30px;
margin-left: 6px;
}
#footer-bar li a {
color: #FFFFFF;
}
HTML:
<div id="footer">
<div id="footer-bar">
<ul>
<li>Contact</li>
<li>Another Link</li>
</ul>
</div>
All characters on hentaireader.com are purely fictional and 18+ years of age.
</div><!--- FOOTER --->
Look here... http://jsfiddle.net/b8Xh7/1/
Ok, well first of all. Do you see the red bar? You have a div inside of the div you have an image. You should have put the (red bar) image as a background, and put a link inside the div. Then you could haver positioned the link where you wanted it with padding/margin.
#footer a {}
Example

Resources