css 背景图片定位在菜单效果中的应用实例
网站建设 2023-01-28 21:37www.1681989.com免费网站
这款菜单大家需要注意HOVER状态下背景图片定位发生了变化,从而实现了这样的效果。
本实例是一位国外的朋友所写,不进行任何翻译,直接发出来,大家可以偿试阅读,如果遇到困难可以求助于翻译软件。
不断的提高自己的英文阅读能力也是我们一直所提倡的,让我们一起努力吧!
Overview
Here are the required graphics to assembe the menu
1. Ma background
Open the Photoshop file. Turn off the menu text Layer Group and save the ma background as menu-bg.jpg.
2. Button graphics
Turn off the background Layer Group and leave only the menu text layers visible. Make a rectangle selection cover the "home" item, go to menu Edit > Copy Merged (Cmd + Shift + C).
Create a new file and take note of the file dimension (w x h), my case the "home" graphic is 144 x 58px. Paste the "home" graphic the new file. Go to menu Image > Canvas Size, adjust the image height x 2 (58 + 58 = 116px). Duplicate the home graphic layer and align it to the bottom. Erase the highlight strokes the upper layer.
Here is how the hover effect will work. We will set the lk button to 144 x 58px, when mouseover, we will shift the background image from to bottom.
Repeat this step for the other buttons. You should have the follow graphics:
3. HTML source
When you are done with the graphics, let’s start codg. Start with an un-ordered list <ul>.
● note there is an id="menu" assigned to the<ul> tag
● an unique class name assigned to each lk <a>
● an empty <span> tag (the purpose of this is to make the mouseover effect)
#menu
Reset the menu to no paddg, no marg, and no list-style. Specify the width and height same dimension as the menu-bg.jpg. Then attach the menu background image. The key pot to remember here is set the position property to relative.
#menu span
Specify the span element to display:none (so they will be visible by default). Specify position:absolute, so we can place the mouseover GIF image on exact position.
#menu a
The key pot here is the text-dent property. We specify the text-dent property with a negative value (-900%), so the text will be hidden.
#menu a:hover
When mouseover the lk, we want to shift the background image from to bottom.
#menu a:hover span
When mouseover the lk, we want the span element to display:block.
#menu .home
Specify the width, height, and background image. Sce we already specified all <a> element postition:absolute previous step, now just say where the .home button should be by specifyg the left and property.
#menu .home span
Here we are specifyg the width, height, background, and position of the span element of .home (mouseover GIF image)
#menu .about
Copy the .home rules and rename them to .about. Now just change the width, height, background, left, and property.
#menu .rss
Repeat this step for .rss
All one:
本实例是一位国外的朋友所写,不进行任何翻译,直接发出来,大家可以偿试阅读,如果遇到困难可以求助于翻译软件。
不断的提高自己的英文阅读能力也是我们一直所提倡的,让我们一起努力吧!
Overview
Here are the required graphics to assembe the menu
1. Ma background
Open the Photoshop file. Turn off the menu text Layer Group and save the ma background as menu-bg.jpg.
2. Button graphics
Turn off the background Layer Group and leave only the menu text layers visible. Make a rectangle selection cover the "home" item, go to menu Edit > Copy Merged (Cmd + Shift + C).
Create a new file and take note of the file dimension (w x h), my case the "home" graphic is 144 x 58px. Paste the "home" graphic the new file. Go to menu Image > Canvas Size, adjust the image height x 2 (58 + 58 = 116px). Duplicate the home graphic layer and align it to the bottom. Erase the highlight strokes the upper layer.
Here is how the hover effect will work. We will set the lk button to 144 x 58px, when mouseover, we will shift the background image from to bottom.
Repeat this step for the other buttons. You should have the follow graphics:
3. HTML source
When you are done with the graphics, let’s start codg. Start with an un-ordered list <ul>.
● note there is an id="menu" assigned to the<ul> tag
● an unique class name assigned to each lk <a>
● an empty <span> tag (the purpose of this is to make the mouseover effect)
Example Source Code [.52css.]
<ul id="menu">
<li><a href="#" class="home">Home <span></span></a></li>
<li><a href="#" class="about">About <span></span></a></li>
<li><a href="#" class="rss">RSS <span></span></a></li>
</ul>
<li><a href="#" class="home">Home <span></span></a></li>
<li><a href="#" class="about">About <span></span></a></li>
<li><a href="#" class="rss">RSS <span></span></a></li>
</ul>
#menu
Reset the menu to no paddg, no marg, and no list-style. Specify the width and height same dimension as the menu-bg.jpg. Then attach the menu background image. The key pot to remember here is set the position property to relative.
Example Source Code [.52css.]
#menu {
list-style: none;
paddg: 0;
marg: 0;
width: 774px;
height: 210px;
background: url(images/menu-bg.jpg) no-repeat;
position: relative;
}
list-style: none;
paddg: 0;
marg: 0;
width: 774px;
height: 210px;
background: url(images/menu-bg.jpg) no-repeat;
position: relative;
}
#menu span
Specify the span element to display:none (so they will be visible by default). Specify position:absolute, so we can place the mouseover GIF image on exact position.
Example Source Code [.52css.]
#menu span {
display: none;
position: absolute;
}
display: none;
position: absolute;
}
#menu a
The key pot here is the text-dent property. We specify the text-dent property with a negative value (-900%), so the text will be hidden.
Example Source Code [.52css.]
#menu a {
display: block;
text-dent: -900%;
position: absolute;
outle: none;
}
display: block;
text-dent: -900%;
position: absolute;
outle: none;
}
#menu a:hover
When mouseover the lk, we want to shift the background image from to bottom.
Example Source Code [.52css.]
#menu a:hover {
background-position: left bottom;
}
background-position: left bottom;
}
#menu a:hover span
When mouseover the lk, we want the span element to display:block.
Example Source Code [.52css.]
#menu a:hover span {
display: block;
}
display: block;
}
#menu .home
Specify the width, height, and background image. Sce we already specified all <a> element postition:absolute previous step, now just say where the .home button should be by specifyg the left and property.
Example Source Code [.52css.]
#menu .home {
width: 144px;
height: 58px;
background: url(images/home.gif) no-repeat;
left: 96px;
: 73px;
}
width: 144px;
height: 58px;
background: url(images/home.gif) no-repeat;
left: 96px;
: 73px;
}
#menu .home span
Here we are specifyg the width, height, background, and position of the span element of .home (mouseover GIF image)
Example Source Code [.52css.]
#menu .home span {
width: 86px;
height: 14px;
background: url(images/home-over.gif) no-repeat;
left: 28px;
: -20px;
}
width: 86px;
height: 14px;
background: url(images/home-over.gif) no-repeat;
left: 28px;
: -20px;
}
#menu .about
Copy the .home rules and rename them to .about. Now just change the width, height, background, left, and property.
Example Source Code [.52css.]
#menu .about {
width: 131px;
height: 51px;
background: url(images/about.gif) no-repeat;
left: 338px;
: 97px;
}
#menu .about span {
width: 40px;
height: 12px;
background: url(images/about-over.gif) no-repeat;
left: 44px;
: 54px;
}
width: 131px;
height: 51px;
background: url(images/about.gif) no-repeat;
left: 338px;
: 97px;
}
#menu .about span {
width: 40px;
height: 12px;
background: url(images/about-over.gif) no-repeat;
left: 44px;
: 54px;
}
#menu .rss
Repeat this step for .rss
Example Source Code [.52css.]
#menu .rss {
width: 112px;
height: 47px;
background: url(images/rss.gif) no-repeat;
left: 588px;
: 94px;
}
#menu .rss span {
width: 92px;
height: 20px;
background: url(images/rss-over.gif) no-repeat;
left: 26px;
: -20px;
}
width: 112px;
height: 47px;
background: url(images/rss.gif) no-repeat;
left: 588px;
: 94px;
}
#menu .rss span {
width: 92px;
height: 20px;
background: url(images/rss-over.gif) no-repeat;
left: 26px;
: -20px;
}
All one:
Example Source Code [.52css.]
#menu {
list-style: none;
paddg: 0;
marg: 0;
width: 774px;
height: 210px;
background: url(images/menu-bg.jpg) no-repeat;
position: relative;
}
#menu span {
display: none;
position: absolute;
}
#menu a {
display: block;
text-dent: -900%;
position: absolute;
outle: none;
}
#menu a:hover {
background-position: left bottom;
}
#menu a:hover span {
display: block;
}
#menu .home {
width: 144px;
height: 58px;
background: url(images/home.gif) no-repeat;
left: 96px;
: 73px;
}
#menu .home span {
width: 86px;
height: 14px;
background: url(images/home-over.gif) no-repeat;
left: 28px;
: -20px;
}
#menu .about {
width: 131px;
height: 51px;
background: url(images/about.gif) no-repeat;
left: 338px;
: 97px;
}
#menu .about span {
width: 40px;
height: 12px;
background: url(images/about-over.gif) no-repeat;
left: 44px;
: 54px;
}
#menu .rss {
width: 112px;
height: 47px;
background: url(images/rss.gif) no-repeat;
left: 588px;
: 94px;
}
#menu .rss span {
width: 92px;
height: 20px;
background: url(images/rss-over.gif) no-repeat;
left: 26px;
: -20px;
}
list-style: none;
paddg: 0;
marg: 0;
width: 774px;
height: 210px;
background: url(images/menu-bg.jpg) no-repeat;
position: relative;
}
#menu span {
display: none;
position: absolute;
}
#menu a {
display: block;
text-dent: -900%;
position: absolute;
outle: none;
}
#menu a:hover {
background-position: left bottom;
}
#menu a:hover span {
display: block;
}
#menu .home {
width: 144px;
height: 58px;
background: url(images/home.gif) no-repeat;
left: 96px;
: 73px;
}
#menu .home span {
width: 86px;
height: 14px;
background: url(images/home-over.gif) no-repeat;
left: 28px;
: -20px;
}
#menu .about {
width: 131px;
height: 51px;
background: url(images/about.gif) no-repeat;
left: 338px;
: 97px;
}
#menu .about span {
width: 40px;
height: 12px;
background: url(images/about-over.gif) no-repeat;
left: 44px;
: 54px;
}
#menu .rss {
width: 112px;
height: 47px;
background: url(images/rss.gif) no-repeat;
left: 588px;
: 94px;
}
#menu .rss span {
width: 92px;
height: 20px;
background: url(images/rss-over.gif) no-repeat;
left: 26px;
: -20px;
}
上一篇:CSS实现的图片宽高自适应固定边框
下一篇:CSS 速记口诀 可以解决一些常见问题
网站设计
- 静宁会SEO的网站建设公司:全面提升您的网络影
- 提升在线业务的关键:选择最佳的丽水网站建设
- 浙江网站优化发展潜力如何
- 井研专业的网站建设公司:打造您的在线品牌
- 灵山SEO网站建设公司:提升您的在线业务表现
- 蒙城网站建设优化公司:提升您网站表现的理想
- 阳谷企业网站优化:提升线上业务力的关键
- 樟树专业的网站建设公司:打造您在线业务的坚
- 通河百度SEO排名的策略与技巧
- 重庆百度快照排名如何进行精准的客户引流
- 重庆百度快照排名
- 常宁便宜的建站公司:助您轻松打造在线业务
- 巫溪百度网站优化:提升网站曝光率与流量的关
- 湖北整站优化怎么做才能放大客户需求
- 闸北网站建设多少钱?全面解析与预算规划
- 辽宁企业网站优化怎么做电话营销