I am trying to assign a same size (Width) to all items inside in side a CSS powered Horizontal Menu Nav. as you cab see from the linked example the "li" size is rendering based on the length of the strings inside. Now my question is how I can set a fix size for items (For example: 80px for all)?
Can you please take a look at following example:
http://jsfiddle.net/Behseini/hBDv9/
I also would like to know how I can center the Menu bar in box(div)
Thanks for your time and comments
Set the width on the "a" elements.
http://jsfiddle.net/hBDv9/2/
You can also apply text centering on the "a", if you need that.
Add width: 80px; to #nav li a and #nav li a:hover.
To get the li elements the same size you need to use:
#nav li {
display:inline-block;
width:80px;
}
To center one element inside of another:
div.wrapper { width:100%;}
div.wrapper .centered {
display:inline-block;
width:80%; // or whatever you want it to be
margin: 0 auto;
}
Does this help?
Related
I have an issue with inline list elements.
The issue is that when I limit the width of my menu, which contains inline list elements, to put it onto multiple lines (for mobile devices) the right-side of elements is being cut off.
Here's a JSFiddle showing this: http://jsfiddle.net/vk2bK/7/
The menu in the orange with:
width: 210px;
background-color: #ffc20e;
In this JSFiddle the right-side of the 2nd list element is cut off. There's lots of space beside it in the div with the class 'menu', so it's not because of that. I assume it's because of some inline list property I'm unaware of.
How do I prevent the right-sides of inline list elements being cut off when the list expands onto a second line?
Simple CSS fix should do it.
You need to modify the li elements so they are inline block with a defined width:
.menu li {
display: inline-block;
width: 90px;
}
See it here: http://jsfiddle.net/vk2bK/21/
EDIT
I played around with it, see if this is what you want: http://jsfiddle.net/vk2bK/22/
ok i found a solution : JsFiddle
.menu a {
display: inline-block;
}
.menu a {
width:80px;
background-color: #7dc242;
line-height: 30px;
margin: 3px;
}
i removed the lists and made all elements inline-block u can edit their width and height if u need to.
I'm making a NavBar out of images.
The images are inside a list item li which is inside an unordered list ul which is inside a div.
The problem I'm having is that when I make an unordered list displaying inline, it doesn't align to the left of the div like it should, it starts about 40 pixels in. I tried setting position:absolute;left:0; on the ul but it doesn't make a difference.
position:absolute; is supposed to make it align relative to its parent element, but it's not doing that.
Here is a JSFiddle displaying the problem.
(The red block is the div, it's red just to show you where the side of the div is so you can see how far off the ul is)
Is there something I'm missing? Why does the image start 40 pixels to the right of where it should?
CSS
#navbar ul{
position:absolute;
left:0px;
margin:0 0 0 0;
padding: 0 0 0 0;
}
You need to add padding: 0;
#navbar ul{
padding:0;
}
Also, 2 things you might want to look into that will cause you similar problems:
1) Inheritance
Inheritance is something where if you don't specify certain values, it will simply take the value of the same elements from the parents.
2) CSS reset
All browsers have their own default values for certain things. you want to make sure that you reset some of those values, if you want full control. It will likely impact the speed of your website loading minimally.
ul and other lists have 40px padding-left by default, in older IE it is margin, so just remove padding and margin.
I am trying to solve this issue for a few days now. I am unable to place the Child1, 2 and 3 between the 25px orange spot. The parent and child menu is a CSS based ul - li menu, where I set the <a> as an inline-block and set the width and height but it still ignores those parameters. I am out of ideas on how to solve this matter. Thank you for your help in advance.
Due to the length of the code I decided to upload the "whole" source code:
source.zip
The problem is that your <a> tags on the sub-menu have the padding:15px from the main menu. You will need to set it to 0. You can then set the line-height of the element to match the orange bar's height to center it vertically.
Add this to fix it:
#header .cssMenuA a{
padding:0;
line-height:25px;
}
It looks like the Child 1, 2, 3 a tags have padding applied to them, which is pushing them down past the orange. See screenshot:
Try removing the padding from the a tags (bodystyle.css, line 78), and reapplying it only to the parent menu items.
You have 15px of padding around all of the <a> elements in the nav list (including PARENT), but this also applies to the "Childs." Add the rule:
#header li li a {
padding-top: 0;
}
This may not look exactly like you want because the <a> is set at 25px high, but the font is smaller than that. Also add
#header li li a span {
line-height: 25px;
}
learning html/css here. I can't seem to understand how to tweak this drop down menu. I'm trying have to tweak it to hold an image and a name, then to have the links.
Right now the image is getting cut off due to the <li> height, when I change the <li> height to 100% it get some weird behavior that I don't understand. Any help would be really appreciated to learn whats going on.
image getting cut off
http://jsfiddle.net/FyU89/
odd behavior after I add height: 100%
.menu ul li ul li{
padding:0;
float:none;
margin:0 0 0 0px;
width:100%;
height: 100%
}
http://jsfiddle.net/FyU89/1/
Add to your css
ul.menu-drop li {
display: inline-block;
}
Fiddle link
Update:
Upon adding the new css rule you'll find the name disappears from next to the image on Chrome, at least it does for me. To fix that add a float: left on your image and the name will appear next to the image on Chrome, Firefox, and IE; you can then style it more to your liking. Fiddle link with the float change.
just going through your css and code, it appears that these drop downs would inherit the height from their parent (.menu), which is set to 30px. the images seem like they are set to have a height of 48px; this maybe causing your cutoff.
Add this to your css code:
ul.menu-drop li {
height: 50px;
}
That sets the height of your list within the menu-drop menu thing so its big enough for the picture.
I have dropdown menu and its made via a list and position absolute, however the dropdown links are very very very small area and do not cover the text completely.
How can I fix this?
Example http://outreviews.com/v%202/index.html (the dropdown menus)
Remove the padding from the sub menu's UL and LI and give the A element "display:block" This will make the A element take up the entire width of the menu.
You can fiddle with the padding to get it the way you want it.
If you add:
ul li a {
display: inline-block;
width: 100%;
height: 100%;
}
It should work okay, and since even IE allows display: inline-block; on natively in-line elements it should be relatively cross-browser friendly (certainly under a valid doctype).
It's worth remembering that padding on the parent li will also reduce the possible width of the child a element, and the display: inline on the same parent li is also likely to cause you a little trouble (since display: block; on the a would be so much simpler).
Edited to note that #Chris Bentley correctly noted the points in my final paragraph (above the hr) just prior to my answer.
make the following changes:
in #headermenu li change the padding:20px; to padding :0 20px;
add delete the top:55px; from #headermenu li ul
What you can do is make the li elements display:list-item and the a elements display:block. That's what's being done on the site you're linking to.