Basically, I am new to using CSS Sprites and wish to do so for icon navigations. Basically, at the moment i have created a sprite which consists of two icons, 21px x 21px and the document size is 21px x 43px.
.nav-main {
position:relative;
top: 19.5px;
}
.nav-main li a {
background-image:url(../images/nav_sprite.png);
background-repeat: no-repeat;
height: 21px;
width: 21px;
display: block;
}
.nav-main li a.1 {
background-position:0px 0px;
}
.nav-main li a:hover.1 {
background-position:0px -23px;
}
That's my attempt, i tried another way where i removed the height and width of the nav-main li a however when i did this i was left with no image. Then i had to do it so that i had a text-indent to remove the text and still display the image but it didn't display the whole image.
The image is the navigation one that looks like this
I would use a screenshot but i am not able to include an image yet :) But yeah i want this to work but it's being an absolute pain.
Any ideas?
You can't use "numbers" as class name. Change to:
.nav-main li a.one {
background-position:0px 0px;
}
.nav-main li a:hover.one {
background-position:0px -23px;
}
I also cleaned up this block of CSS too.
.nav-main li a {
background-image:url(../images/nav_sprite.png) no-repeat; // put no repeat on the same line
height: 21px;
width: 21px;
display: block;
background-position:0px 0px; // you can put this here as your base...the a.one is not needed. If you go this route, just remove ".nav-main li a.one" css function, but keep the "a:hover"
}
You can't use numbers for class names, so
.nav-main li a.1 { /*wrong*/
.nav-main li a.link1 { /*good*/
When using background images for sprites, you are making your site inaccessible. Background images are not visible to low vision users that are using high-contrast mode. The Following is from Yahoo's Accessibility Blog, and is a good example of accessible sprites.
The HTML:
<div role="toolbar" class="toolbar">
<button type="button" class="prnt">Print</button>
<button type="button" class="find">Find</button>
<button type="button" class="save">Save</button>
<button type="button" class="sets">Settings</button>
<button type="button" class="info">Info</button>
</div>
The CSS:
.toolbar {
border: 1px solid #666;
background: #ddd;
padding: 3px;
font-size: 0;
/* Eliminates white space below and between buttons */
}
.toolbar button {
border: 1px solid #333;
background: #bbb;
padding: 0;
margin: 0 3px 0 0;
width: 36px;
height: 36px;
overflow: hidden;
vertical-align: top; /* Needed for Firefox to ensure buttons are properly aligned inside the toolbar. */
}
/* Remove the extra padding and border given to buttons by
default in Firefox to ensure correct alignment of the img. */
.toolbar button::-moz-focus-inner {
border: 0;
padding: 0;
}
/* The above rule removes the focus outline in Firefox. This rule restores it. */
.toolbar button:focus {
outline: dotted 1px #000;
}
/* Hide the text label by inserting an image before it. */
.toolbar button:before {
display: inline-block;
content: url('http://findicons.com/files/icons/2340/preview/toolbar_icon_set_full.png');
}
.toolbar button {
*background: url('http://findicons.com/files/icons/2340/preview/toolbar_icon_set_full.png') no-repeat;
*text-indent: 36px;
}
.toolbar .prnt {
*background-position: -38px -74px;
}
.toolbar .prnt:before {
margin: -73px 0 0 -37px;
}
.toolbar .find {
*background-position: -182px -146px;
}
.toolbar .find:before {
margin: -145px 0 0 -181px;
}
.toolbar .save {
*background-position: -146px -74px;
}
.toolbar .save:before {
margin: -73px 0 0 -145px;
}
.toolbar .sets {
*background-position: -74px -110px;
}
.toolbar .sets:before {
margin: -109px 0 0 -73px;
}
.toolbar .info {
*background-position: -146px -146px;
}
.toolbar .info:before {
margin: -145px 0 0 -145px;
}
For the hover effect, you can use the class and the psuedo selector :hover to adjust the margins to the appropriate values.
Related
Problem
No space between image logo and menu although i assign margin-top:20px ?
actually i need to show full logo as you see logo cutting
logo problem
my fiddle work as below :
https://jsfiddle.net/ahmedsa/z2pmwsnr/
i need to modify fiddle to leave space between logo image and menu .
image logo
http://www.mediafire.com/view/qd5otyc1w9yv5e9/logo.png
my code
ul {
border-top: 4px solid red;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
position: fixed; /* Set the navbar to fixed position */
top: 0; /* Position the navbar at the top of the page */
width: 100%; /* Full width */
}
li {
float: right;
}
li a {
color: white;
padding: 16px;
text-decoration: none;
}
li i{
color:white;
}
.w3ls_header_middle {
padding: 0 0;
padding-top:30px
}
.agileits_logo{
float:right;
margin-right:0em;
margin-top:20px
}
I have a problem in my css that I can figure it out, I need to align the text and the img in my drop down list in the center.
The igm looks in center but the text is a bit lower.
I want also to make the text a bit far from the img
Any help ?
This is what I get
I deleted alot of source code CSS to be able to publish the auestion, I hope my issue is not in what I deleted.
HTML
<section class="main">
<div class="wrapper-demo">
<div id="dd" class="wrapper-dropdown-2">
<span>Deutsch</span>
<ul class="dropdown">
<li><img src="./images/flags/flags_iso/32/de.png" >Deutsch</li>
<li><img src="./images/flags/flags_iso/32/en.png" >English</li>
<li><img src="./images/flags/flags_iso/32/fr.png" >Français</li>
<li><img src="./images/flags/flags_iso/32/es.png" >Español</li>
</ul>
</div>
</div>
</section>
CSS
/* DEMO 2 */
.wrapper-dropdown-2 {
/* Size and position */
position: relative; /* Enable absolute positionning for children and pseudo elements */
width: 200px;
margin: 0 auto;
padding: 10px 15px;
/* Styles */
background: #fff;
border-left: 5px solid grey;
cursor: pointer;
outline: none;
}
.wrapper-dropdown-2:after {
content: "";
width: 0;
height: 0;
position: absolute;
right: 16px;
top: 50%;
margin-top: -3px;
border-width: 6px 6px 0 6px;
border-style: solid;
border-color: grey transparent;
}
.wrapper-dropdown-2 .dropdown {
/* Size & position */
position: absolute;
top: 100%;
left: -5px;
right: 0px;
/* Hiding */
opacity: 0;
pointer-events: none;
}
.wrapper-dropdown-2 .dropdown li a {
display: block;
text-decoration: none;
color: #333;
border-left: 5px solid;
padding: 10px;
}
.wrapper-dropdown-2 .dropdown li i {
margin-right: 5px;
color: inherit;
vertical-align: middle;
}
/* Active state */
.wrapper-dropdown-2.active:after {
border-width: 0 6px 6px 6px;
}
.wrapper-dropdown-2.active .dropdown {
opacity: 1;
pointer-events: auto;
}
/* No CSS3 support */
.no-opacity .wrapper-dropdown-2 .dropdown,
.no-pointerevents .wrapper-dropdown-2 .dropdown {
display: none;
opacity: 1; /* If opacity support but no pointer-events support */
pointer-events: auto; /* If pointer-events support but no pointer-events support */
}
.no-opacity .wrapper-dropdown-2.active .dropdown,
.no-pointerevents .wrapper-dropdown-2.active .dropdown {
display: block;
}
Try using
.wrapper-dropdown-2 .dropdown li a img{
vertical-align:middle;
}
Sorry I can only answer, I do not have enough points to comment. It looks like your flag images have a bigger height than the text. Therefore this will increase the height of the div that contains the flag and the text.
[]
[]English
Above, the 4 square brackets represent the flag. This is what is happening. Whereas if they were the same size:
[]English
.dropdown li a
{
display: inline-block;
line-height: 18px;
}
.dropdown li img
{
float: left;
margin-right: 5px;
}
I am trying to implement background image sprite hover effect from this CSS-tricks article: http://css-tricks.com/fade-image-within-sprite/
My problem is that the images do not align completely in the following case:
HTML:
<ul class="contact">
<li class="phone"><a class="bg_hover" href="#">Call me</a>
</li>
<li class="twitter"><a class="bg_hover" href="#">Follow me on Twitter</a>
</li>
<li class="email"><a class="bg_hover" href="#">Email me</a>
</li>
</ul>
CSS:
.bg_hover {
position: relative;
}
.bg_hover:after {
content:"";
background-image: inherit;
background-position: bottom left;
background-repeat: no-repeat;
opacity: 0;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
transition: 1s;
}
.bg_hover:hover:after {
opacity: 1;
}
.contact {
margin-left: 60px;
}
.contact li {
float:left;
margin: 30px 15px 0 0;
font-style: italic;
}
.contact li a {
padding: 3px 0 0 25px;
height: 18px;
background-repeat: no-repeat;
display: block;
}
.contact .phone a {
background-image: url(http://i.imgur.com/9d9hdiL.png);
}
.contact .email a {
background-image: url(http://i.imgur.com/9d9hdiL.png);
}
.contact .twitter a {
background-image: url(http://i.imgur.com/9d9hdiL.png);
}
li {
list-style: none;
}
jsfiddle: http://jsfiddle.net/47Lngd4t/2/
Can you tell me where is the problem?
Your background-position isn't quite right. The image sprite you used is a pixel or two out. Change background-position to the following:
.bg_hover:after {
background-position: 0 -21px;
}
See demo here: http://jsfiddle.net/AndyMardell/47Lngd4t/3/
I changed
.contact li a {
padding: 3px 0 0 25px;
...
}
to
.contact li a {
padding: 2px 0 0 25px;
...
}
So, from 3px to 2px. Seems to align for me.
If You're talking about effect like here http://take.ms/a6ar2 simply add line-height for example 10px to .contact li a selector
There are also some other ways to get effect:
You can change padding of <a> elements
You can change background-position of image
I am a little stuck. I am trying to build a horizontal navigation bar, 1024px across, which will allow for a submenu to display below it. But i want the submenu to also be 1024px in width and to display directly below the navigation bar, vertically aligned.
At the moment the submenu appears but fixes its left side to the left side of the current li that you are hovering over. How can I fix this?
Thanks!
EDIT: So on mouse over it would look something like this: http://eventav.biz/site/example.jpg
Link to what I've done so far -
http://www.eventav.biz/site/
ul.top_menu {
position: relative;
margin: 0;
margin-bottom: -1px;
list-style: none;
display: table;
width: 1024px;
border: 1px solid #111111;
border-bottom: 1px solid #000000;
border-radius: 10px 10px 0px 0px;
}
.top_menu li {
display: block;
position: relative;
border-right: 1px solid #111111;
float: left;
margin: 0px;
display: table-cell;
vertical-align: middle;
}
.top_menu li:first-child {
border-left: 1px solid #111111;
}
.top_menu li a {
display: block;
text-decoration: none;
color: #000000;
text-shadow: 3px 3px 8px #3A3A3A;
padding: 15px;
height: 30px;
display: table-cell;
vertical-align: middle;
margin: 0px;
}
#top_menu_item ul {
display: none;
margin: 0px;
}
#top_menu_item:hover ul {
display: block;
position: fixed;
margin: 0;
}
#top_menu_item:hover li {
width: 1024px;
background-color: #666;
text-align: left;
color: #FFF;
font-size: 12px;
margin: 0px;
}
<ul class="top_menu">
<li id="top_menu_item">HOME</li>
<li id="top_menu_item">OUR SERVICES
<ul><li id="top_menu_item">test</li></ul>
</li>
<li id="top_menu_item">EXAMPLES OF OUR WORK
<ul><li id="top_menu_item">test</li></ul>
</li>
<li id="top_menu_item">CONTACT US</li>
</ul>
Remove the fixed positioning from the child ul, and replace it with position:absolute. Add in left:0px, and then remove position:relative from the parent li.
Working jsFiddle example
#top_menu_item:hover ul {
display: block;
position: fixed; /* Change this to position:absolute; */
left:0px; /* Add this */
}
.top_menu li {
display: block;
position: relative; /* Remove this */
}
1) Remove position: relative; from #top_menu_item
2) Set #top_menu_item ul to position: absolute; left: 0; instead
3) Remove left padding on #top_menu with padding-left: 0;
4) Add:
#top_menu_item:first-child {
margin-left: 40px;
}
Essentially, the problem was that you've been positioning your inner ul tag relative to it's parent li. Instead, the solution above positions the secondary navigation absolutely in relation to the primary navigation, and we use left: 0; to make sure it's completely left-aligned.
It's also against the standard to use an id multiple times on a page. Therefore I'd recommend changing #top_menu_item into .top_menu_item and changing the HTML accordingly.
Let me know if you have any problems!
Quite difficult to explain, so I created a codepen for you to have a look at. When you hover over a navigation item and the dropdown menu appears. You'll see that some of the items don't line up correctly. I.e. the width of some items are bigger than their sibling items. I just want them all to stretch to the width of the widest list item. (confused yet?) Just have a look at the code pen..
You need to make changes to the below CSS to get them aligned.
For Instance.
#main-navigation ul li ul li {
background: none repeat scroll 0 0 #DE5D48;
width: 140px;
text-align:left;
}
WORKING DEMO
Hope this helps.
You should use display : inline-block instead of float: left in /* list item */ css and should add display : table-row; into /* sub list item */ .
#dark-blue: #31394C;
#light-gray: #E6E6E6;
#gray: #B1B2B5;
#dark-gray: #6D6D6D;
#dark-red: #d7351b;
#red: #ee2a2e;
#light-red: #f75d1f;
#dusty-red: #DE6450;
#light-dusty-red: #fdc29e;
#dark-dusty-red: #b50b03;
#sub-nav-red: #DE5D48;
#white: #ffffff;
#import url(http://fonts.googleapis.com/css?family=Rosario);
body {
background: #dark-blue;
}
#main-navigation {
/* initial list */
ul {
list-style: none;
/* list item */
li {
display: inline-block;
position: relative;
background: #dark-red;
min-width: 105px;
height: 21px;
text-align: center;
margin-right: 10px;
/* link */
a {
color: #white;
display: block;
line-height: 21px;
text-decoration: none;
font-family: 'Rosario', sans-serif;
font-size: 12px;
text-transform: uppercase;
}
a:hover {
color: #white;
background: #dark-red;
}
/* sub list */
ul {
position: absolute;
top: 100%;
left: -40px;
display: none;
border-top: 10px solid rgba(255, 255, 255, 0.0);
z-index: 99;
/* sub list item */
li {
background: #sub-nav-red;
display : table-row;
/* sub list link */
a {
padding: 0 5px 0 5px;
white-space: nowrap;
}
}
}
ul:hover {
display: block;
}
}
li:hover > ul {
display: block;
}
}
}
I suggest moving the background, size, and positioning from the li to the ul, that way the whole list will expand if one item is too big.
Try to give more min-width
#main-navigation ul li {
float: left;
position: relative;
background: #D7351B;
min-width: 140px;
in css, li element has: min-width: 105px;
change it to 155px and it will solve it.
hope that helps.
Its quite simple,
You can't use: top: 100%
You'll be wanting to update this to be top: 0 this will align it to the top of its parent.
You may need top: 11px in your exact case.