用实例详细讲解将PSD转成HTML&CSS




将PSD转成一个静态的html/css对一些朋友来说是一个很大的困扰。这个教程通过对一个完整实例的详细讲解,来教大家如何将psd转成html/css,以及JS插件的使用,制作完成的html/css页面兼容各种主流浏览器。

我们将设计页面分成基本的5个部分,每一个部分都有自己的容器wrapper和内容。基本的流程是先编写Html代码,然后通过编写CSS来还原psd设计稿。

photography-psd-template-thumb.png (221.95 KB, 下载次数: 96)

下载附件  保存到图库

2011-3-30 15:43 上传


1. 我们需要从PSD文件得到什么?

如下图,我们只需要从这个psd文件得到4个非常基本的东西。推荐内容(featured)的背景、底部背景、欢迎文字(Welcome)、推荐图片的框(少女面部图的白色透明边框)。其余的部分我们只需要通过CSS生成或者在html里嵌入相应图片。

下图红线圈起来的地方,就是我们需要从psd获取的内容。本部分内容需要读者具备一定的Photoshop的基础知识和操作能力。
你可以借助Photoshop的切片工具或者自己手动切片,并将其保存成相应的图片格式。

photography-psd-slices-thumb.jpg (42.91 KB, 下载次数: 33)

下载附件  保存到图库

2011-3-30 15:50 上传


2.设置站点

为一个网站设置良好的开发环境是非常重要的,我已经创建了一个非常基本的文件夹结构来建立这个网站,下面是文件夹结构设置,也可称之为模板。

文件夹结构下面这个文件夹结构是由html文件、CSS文件、js等文件组成,你可以根据自己的需要调整文件夹结构。

folder-structure.png (4 KB, 下载次数: 14)

下载附件  保存到图库

2011-3-30 15:51 上传



  • 根目录

    • 这是放置index首页文件的地方
    • 这是网站的顶级目录
  • JavaScript 文件夹

    • 这是放置JS文件或者js框架jquery的地方
    • 我们在这个教程用到的jquery插件Nivo-Slider(做推荐内容)也放在这个文件夹里
  • 样式(Styles )文件夹

    • 这里是存放css文件的地方,网页所要用到的图片放在另一个独立的文件夹,图片文件夹还包括两个子文件夹:
    • Images: 这是我们存放推荐内容部分的图片以及网站展示的图片的地方
    • Template: 这是存放和网页设计样式相关图片的地方,比如说底部背景图
具体文件的放置

将index.html文件放置在根目录,这个文件也是我们编写html代码的文件。
将jquery插件Nivo-Slider里面的三个文件jQuery-1.4.2.min.js和HTML5-Shiv.js以及Nivo-Slider.min.js放到Javascript文件夹。
将两个css文件,reset.css和global.css放到样式文件夹。
这样我们的文件夹结构设置就差不多完成了。

3.编写HTML代码

1)编写首页Html文件

将psd转换成html/css的工作流程是先编写出html文件,随后再编写css,并加入js动态效果。
下面我们会一步步讲解html的编写,先编写出大概完整的框架,代码如下:
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <!-- Site Title -->
  5. <title>PSD to HTML: A Photography Site</title>

  6. <!-- Meta Data -->
  7. <meta charset="UTF-8" />
  8. </head>
  9. <body>

  10. </body>
  11. </html>
复制代码

2)编写html文件的head部分

下面我们要开始为刚才的html文件添加细节。首先是head部分,在head部分我们要添加一些meta信息,这样有利于搜索引擎读取。

我们增加了keywords、authors、description、copyright等meta信息,并把语言编码设置为utf-8。代码如下:
  1. <meta name="keywords" content="photography, commercials, exposure videos, senior pictures">
  2. <meta name="description" content="Your company description.">
  3. <meta name="author" content="TutToaster.com/authors/CodyRobertson">
  4. <meta name="copyright" content="Copyright 2010 TutToaster.com">
  5. <meta name="robots" content="follow, index">
复制代码

现在要开始在html载入一些必须js和css的文件,以便让这些文件起作用,同时为了考虑到浏览器的兼容性,还增加了一些相应的判断条件。具体代码如下:
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <!-- Site Title -->
  5. <title>PSD to HTML: A Photography Site</title>

  6. <!-- Meta Data -->
  7. <meta charset="UTF-8" />
  8. <meta name="keywords" content="photography, commercials, exposure videos, senior pictures">
  9. <meta name="description" content="Your company description.">
  10. <meta name="author" content="TutToaster.com/authors/CodyRobertson">
  11. <meta name="copyright" content="Copyright 2010 TutToaster.com">
  12. <meta name="robots" content="follow, index">

  13. <!-- Site Theme Styling -->
  14. <link rel="stylesheet" href="style/reset.css" />
  15. <link rel="stylesheet" href="style/global.css" />

  16. <!--[if lt IE 9]>
  17. <script type="text/javascript" src="javascript/HTML5-Shiv.js"></script>
  18. <![endif] -->
  19. </head>
  20. <body>

  21. <!-- jQuery and Nivo Slider -->
  22. <script type="text/javascript" src="javascript/jQuery-1.4.2.min.js"></script>
  23. <script type="text/javascript" src="javascript/Nivo-Slider.min.js"></script>
  24. </body>
  25. </html>
复制代码

3)编写html的body部分

body部分是html文件的主要部分,网页上显示主要是body部分的内容,我们会将这个网页的布局分成以下5个部分:header、featured、status、content、footer。我们为每个部分增加一个div并在每个部分的内部加一个类名为container的div。
  1. <div id="header">
  2. <div class="container">

  3. </div>
  4. </div>
  5. <div id="featured">
  6. <div class="container">

  7. </div>
  8. </div>
  9. <div id="status">
  10. <div class="container">

  11. </div>
  12. </div>
  13. <div id="cotent">
  14. <div class="container">

  15. </div>
  16. </div>
  17. <div id="footer">
  18. <div class="container">

  19. </div>
  20. </div>

复制代码

04)编写#header部分

这个网页的header部分主要由两部分组成,一个是logo,另一个是导航栏。logo是简单div,而导航栏则是列表ul。
  1. <!-- Logo -->
  2. <h1 id="logo">YourLogo</h1>

  3. <!-- Navigation Menu -->
  4. <ul id="menu">
  5. <li class="active"><a href="#">HOME</a></li>
  6. <li><a href="#">PHOTOGRAPHY</a></li>
  7. <li><a href="#">COMMERCIALS</a></li>
  8. <li><a href="#">SPORTS</a></li>
  9. <li><a href="#">EXPOSURE VIDEOS</a></li>
  10. <li><a href="#">CONTACT</a></li>
  11. </ul>
复制代码

05)编写#featured部分

网页的#featured是我们放置推荐内容的部分,这部分也有两部分组成,一个是欢迎文字(welcome),另一个滑动图片Slider。

Welcome区域

welcome区域是一个id为welcome的div,由标题文字和描述文字组成,标题文字h2的显示用图片来代替。描述的文字用p标签包起来。
  1. <div id="welcome">
  2. <h2>Welcome</h2>
  3. <p>Welcome to Your Site! We are a full service production company, and are a one-stop shop for your production needs. We love interacting with people and have a passion for creating a product that wows! As a husband and wife team and graduates of Specs Howard School of Broadcast Arts, we love to learn new things and are continually striving to perfect our craft.</p>
  4. <p>Whether it be Family Photographs, a College Sports Exposure Video, Senior Pictures, or Video Editing, we do it all! Thanks for stopping by and feel free to look around!!!</p>
  5. </div>

复制代码

Slider区域

slider区域由一个透明边框和几张滑动图片组成。滑动图片放在class为slides的列表里边。

  1. <div id="slider">
  2. <div id="frame"> </div>
  3. <ul class="slides">
  4. <li><img src="style/images/slider-placeholder.png" /></li>
  5. <li><img src="style/images/slider-placeholder2.png" /></li>
  6. <li><img src="style/images/slider-placeholder.png" /></li>
  7. <li><img src="style/images/slider-placeholder2.png" /></li>
  8. </ul>
  9. </div>
复制代码

完整的#featured部分的代码

下面是完整的#featured部分的代码,读者可以参照对比查看。

  1. <div id="featured">
  2. <div class="container">
  3. <!-- Welcome Text/Site Welcome -->
  4. <div id="welcome">
  5. <h2>Welcome</h2>
  6. <p>Welcome to Your Site! We are a full service production company, and are a one-stop shop for your production needs. We love interacting with people and have a passion for creating a product that wows! As a husband and wife team and graduates of Specs Howard School of Broadcast Arts, we love to learn new things and are continually striving to perfect our craft.</p>
  7. <p>Whether it be Family Photographs, a College Sports Exposure Video, Senior Pictures, or Video Editing, we do it all! Thanks for stopping by and feel free to look around!!!</p>
  8. </div>

  9. <!-- Nivo-Slider -->
  10. <div id="slider">
  11. <div id="frame"> </div>
  12. <ul class="slides">
  13. <li><img src="style/images/slider-placeholder.png" /></li>
  14. <li><img src="style/images/slider-placeholder2.png" /></li>
  15. <li><img src="style/images/slider-placeholder.png" /></li>
  16. <li><img src="style/images/slider-placeholder2.png" /></li>
  17. </ul>
  18. </div>
  19. </div>
  20. </div>
复制代码

6)编写#status部分

这部分非常简单,由一段文字和一个按钮组成。

  1. <div id="status">
  2. <div class="container">
  3. <span>I am currently accepting new projects/appointmentsat this time.</span>
  4. <button>Hire Me</button>
  5. </div>
  6. </div>
复制代码

7)编写#content部分

在psd文件中,你可以看到#content部分的内容会比较多一点,所以我将它按上下分成两个部分。

第一部分

在psd文件中,你可以看到,第一部分由两块区域组成,这两块区域各占据了50%的宽度,一个区域是About Us,另一个区域是What others think,两个区域都有一个标题和一些文字描述。

  1. <div id="about_us">
  2. <h3>A little about us...</h3>
  3. <p>We are a full service production companel that company that is your one stop needs, weither it be family photographs, a college sport exposure video, senior pictures or.</p>
  4. </div>
  5. <div id="others_say">
  6. <h3>What others think...</h3>
  7. <p>When I first came to Johnny for a first time job I was a bit nervous n how the service would be, but after the first job and how smooth it went i’ll never go anywhere else.
  8. <br /><cite>- Cody Robertson (<a href="#">Website</a>)</cite>
  9. </p>
  10. </div>

复制代码

第二部分

第二部分是由四个各占据25%宽度的小区域组成,这些小区域是由一些预览图、标题和文字组成。

  1. <ul id="services">
  2. <!-- Photography -->
  3. <li>
  4. <img src="style/images/service_preview_1.gif" alt="placeholder" />
  5. <h4>Photography</h4>
  6. <p>Praesent imperdiet nulla at tortor. Phasellus non lectus eget massa rhoncus consequat. Donec lectus ligula, posuere vel, semper a, posuere in, orci. Praesent imperdiet nulla at tortor. Phasellus non lectus eget massa rhoncus consequat. Donec lectus ligula, posuere vel.</p>
  7. </li>

  8. <!-- Commercials -->
  9. <li>
  10. <img src="style/images/service_preview_2.gif" alt="placeholder" />
  11. <h4>Commercials</h4>
  12. <p>Praesent imperdiet nulla at tortor. Phasellus non lectus eget massa rhoncus consequat. Donec lectus ligula, posuere vel, semper a, posuere in, orci. Praesent imperdiet nulla at tortor. Phasellus non lectus eget massa rhoncus consequat. Donec lectus ligula, posuere vel.</p>
  13. </li>

  14. <!-- Sports -->
  15. <li>
  16. <img src="style/images/service_preview_3.gif" alt="plceholder" />
  17. <h4>Sports</h4>
  18. <p>Praesent imperdiet nulla at tortor. Phasellus non lectus eget massa rhoncus consequat. Donec lectus ligula, posuere vel, semper a, posuere in, orci. Praesent imperdiet nulla at tortor. Phasellus non lectus eget massa rhoncus consequat. Donec lectus ligula, posuere vel.</p>
  19. </li>

  20. <!-- Exposure Videos -->
  21. <li>
  22. <img src="style/images/service_preview_1.gif" alt="placeholder" />
  23. <h4>Exposure Videos</h4>
  24. <p>Praesent imperdiet nulla at tortor. Phasellus non lectus eget massa rhoncus consequat. Donec lectus ligula, posuere vel, semper a, posuere in, orci. Praesent imperdiet nulla at tortor. Phasellus non lectus eget massa rhoncus consequat. Donec lectus ligula, posuere vel.</p>
  25. </li>
  26. </ul>
复制代码

8)编写#footer部分

现在是#footer部分的编写,包含一些联系信息和版权信息等。

  1. <ul id="footer-widgets">
  2. <li>
  3. <h5>Contact Us</h5>
  4. <ul>
  5. <li>3352 Streetname rd.</li>
  6. <li>Commerce Township, MI, 48382.</li>
  7. <li> </li>
  8. <li>Tell: (248)838-9823</li>
  9. <li>Fax: (248)942-2342</li>
  10. <li>Email: johnnywaller@me.com</li>
  11. </ul>
  12. </li>
  13. <li>
  14. <h5>Services</h5>
  15. <ul>
  16. <li><a href="#">Home</a></li>
  17. <li><a href="#">Photography</a></li>
  18. <li><a href="#">Commercials</a></li>
  19. <li><a href="#">Sports</a></li>
  20. <li><a href="#">Exposure Videos</a></li>
  21. <li><a href="#">Contact</a></li>
  22. </ul>
  23. </li>
  24. <li>
  25. <h5>About Johnny</h5>
  26. <p>Hey, my name is Johnny, this is a quick little one or two sentences about how im awesome and you should pay me money to do stuff for you!</p>
  27. </li>
  28. <li>
  29. <h5>About Amber</h5>
  30. <p>Hey, my name is Amber, this is a quick little one or two sentences about how im awesome and you should pay me money to do stuff for you!</p>
  31. </li>
  32. </ul>

  33. <!-- Positioning Fix -->
  34. <br class="clear" />
  35. <br /><br />

  36. <!-- Copyright -->
  37. <div id="copyright">
  38. <span>&copy; Copywright 2010 TutToaster.com. All Rights Reserved.</span>
  39. <a href="#">Back to top</a>
  40. </div>
复制代码
Html最终显示结果下图是我们编写好的html文件的最终显示结果,下面还有一份完整的html的代码,方便读者阅读对比。

ps.jpg (27.7 KB, 下载次数: 19)

下载附件  保存到图库

2011-3-30 16:14 上传

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <!-- Site Title -->
  5. <title>PSD to HTML: A Photography Site</title>

  6. <!-- Meta Data -->
  7. <meta charset="UTF-8" />
  8. <meta name="keywords" content="photography, commercials, exposure videos, senior pictures">
  9. <meta name="description" content="Your company description.">
  10. <meta name="author" content="TutToaster.com/authors/CodyRobertson">
  11. <meta name="copyright" content="Copyright 2010 TutToaster.com">
  12. <meta name="robots" content="follow, index">

  13. <!-- Site Theme Styling -->
  14. <link rel="stylesheet" href="style/reset.css" />
  15. <link rel="stylesheet" href="style/global.css" />

  16. <!--[if lt IE 9]>
  17. <script type="text/javascript" src="javascript/HTML5-Shiv.js"></script>
  18. <![endif] -->
  19. </head>
  20. <body>
  21. <div id="header">
  22. <div class="container">
  23. <!-- Logo -->
  24. <h1 id="logo">YourSite Title</h1>

  25. <!-- Navigation Menu -->
  26. <ul id="menu">
  27. <li class="active"><a href="#">HOME</a></li>
  28. <li><a href="#">PHOTOGRAPHY</a></li>
  29. <li><a href="#">COMMERCIALS</a></li>
  30. <li><a href="#">SPORTS</a></li>
  31. <li><a href="#">EXPOSURE VIDEOS</a></li>
  32. <li><a href="#">CONTACT</a></li>
  33. </ul>
  34. </div>
  35. </div>
  36. <div id="featured">
  37. <div class="container">
  38. <!-- Welcome Text/Site Welcome -->
  39. <div id="welcome">
  40. <h2>Welcome</h2>
  41. <p>Welcome to Johnny Waller Productions! We are a full service production company, and are a one-stop shop for your production needs. We love interacting with people and have a passion for creating a product that wows! As a husband and wife team and graduates of Specs Howard School of Broadcast Arts, we love to learn new things and are continually striving to perfect our craft.</p>
  42. <p>Whether it be Family Photographs, a College Sports Exposure Video, Senior Pictures, or Video Editing, we do it all! Thanks for stopping by and feel free to look around!!!</p>
  43. </div>

  44. <!-- Nivo-Slider -->
  45. <div id="slider">
  46. <div id="frame"> </div>
  47. <ul class="slides">
  48. <li><img src="style/images/slider-placeholder.png" /></li>
  49. <li><img src="style/images/slider-placeholder2.png" /></li>
  50. </ul>
  51. </div>
  52. </div>
  53. </div>
  54. <div id="content">
  55. <!-- Working Status -->
  56. <div id="status">
  57. <div class="container">
  58. <span id="avalibility">I am currently accepting new projects/appointmentsat this time.</span>
  59. <button>Hire Me</button>
  60. </div>
  61. </div>

  62. <div class="container" id="main">
  63. <!-- About Us/What They Say -->
  64. <div id="about_us">
  65. <h3>A little about us...</h3>
  66. <p>We are a full service production companel that company that is your one stop needs, weither it be family photographs, a college sport exposure video, senior pictures or.</p>
  67. </div>
  68. <div id="others_say">
  69. <h3>What others think...</h3>
  70. <p>When I first came to Johnny for a first time job I was a bit nervous n how the service would be, but after the first job and how smooth it went i’ll never go anywhere else.
  71. <br /><cite>- Cody Robertson (<a href="#">Website</a>)</cite>
  72. </p>
  73. </div>

  74. <!-- Clear Fix -->
  75. <br class="clear" />

  76. <!-- Services -->
  77. <ul id="services">
  78. <!-- Photography -->
  79. <li>
  80. <img src="style/images/service_preview_1.gif" alt="placeholder" />
  81. <h4>Photography</h4>
  82. <p>Praesent imperdiet nulla at tortor. Phasellus non lectus eget massa rhoncus consequat. Donec lectus ligula, posuere vel, semper a, posuere in, orci. Praesent imperdiet nulla at tortor. Phasellus non lectus eget massa rhoncus consequat. Donec lectus ligula, posuere vel.</p>
  83. </li>

  84. <!-- Commercials -->
  85. <li>
  86. <img src="style/images/service_preview_2.gif" alt="placeholder" />
  87. <h4>Commercials</h4>
  88. <p>Praesent imperdiet nulla at tortor. Phasellus non lectus eget massa rhoncus consequat. Donec lectus ligula, posuere vel, semper a, posuere in, orci. Praesent imperdiet nulla at tortor. Phasellus non lectus eget massa rhoncus consequat. Donec lectus ligula, posuere vel.</p>
  89. </li>

  90. <!-- Sports -->
  91. <li>
  92. <img src="style/images/service_preview_3.gif" alt="plceholder" />
  93. <h4>Sports</h4>
  94. <p>Praesent imperdiet nulla at tortor. Phasellus non lectus eget massa rhoncus consequat. Donec lectus ligula, posuere vel, semper a, posuere in, orci. Praesent imperdiet nulla at tortor. Phasellus non lectus eget massa rhoncus consequat. Donec lectus ligula, posuere vel.</p>
  95. </li>

  96. <!-- Exposure Videos -->
  97. <li>
  98. <img src="style/images/service_preview_1.gif" alt="placeholder" />
  99. <h4>Exposure Videos</h4>
  100. <p>Praesent imperdiet nulla at tortor. Phasellus non lectus eget massa rhoncus consequat. Donec lectus ligula, posuere vel, semper a, posuere in, orci. Praesent imperdiet nulla at tortor. Phasellus non lectus eget massa rhoncus consequat. Donec lectus ligula, posuere vel.</p>
  101. </li>
  102. </ul>
  103. </div>
  104. </div>
  105. <div id="footer">
  106. <div class="container">
  107. <!-- Footer Widgets -->
  108. <ul id="footer-widgets">
  109. <li>
  110. <h5>Contact Us</h5>
  111. <ul>
  112. <li>3352 Streetname rd.</li>
  113. <li>Commerce Township, MI, 48382.</li>
  114. <li> </li>
  115. <li>Tell: (248)838-9823</li>
  116. <li>Fax: (248)942-2342</li>
  117. <li>Email: johnnywaller@me.com</li>
  118. </ul>
  119. </li>
  120. <li>
  121. <h5>Services</h5>
  122. <ul>
  123. <li><a href="#">Home</a></li>
  124. <li><a href="#">Photography</a></li>
  125. <li><a href="#">Commercials</a></li>
  126. <li><a href="#">Sports</a></li>
  127. <li><a href="#">Exposure Videos</a></li>
  128. <li><a href="#">Contact</a></li>
  129. </ul>
  130. </li>
  131. <li>
  132. <h5>About Johnny</h5>
  133. <p>Hey, my name is Johnny, this is a quick little one or two sentences about how im awesome and you should pay me money to do stuff for you!</p>
  134. </li>
  135. <li>
  136. <h5>About Amber</h5>
  137. <p>Hey, my name is Amber, this is a quick little one or two sentences about how im awesome and you should pay me money to do stuff for you!</p>
  138. </li>
  139. </ul>

  140. <!-- Positioning Fix -->
  141. <br class="clear" />
  142. <br /><br />

  143. <!-- Copyright -->
  144. <div id="copyright">
  145. <span>&copy; Copywright 2010 TutToaster.com. All Rights Reserved.</span>
  146. <a href="#">Back to top</a>
  147. </div>
  148. </div>
  149. </div>

  150. <!-- jQuery and Nivo Slider -->
  151. <script type="text/javascript" src="javascript/jQuery-1.4.2.min.js"></script>
  152. <script type="text/javascript" src="javascript/Nivo-Slider.min.js"></script>
  153. </body>
  154. </html>

复制代码

4.为HTML编写CSS样式

我们将css文件分成两个,一个是css重置文件,css reset可以让html元素在各个浏览器上有相同的显示效果,有关于css的重置(css reset)读者可以去查阅相关的资料,这里的CSS reset文件的代码主要来自于雅虎的YUI reset。另一个文件css文件是这个网页的样式。

1)Reset.css

  1. body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td {
  2. margin:0;
  3. padding:0;
  4. }
  5. table {
  6. border-collapse:collapse;
  7. border-spacing:0;
  8. }
  9. fieldset,img {
  10. border:0;
  11. }
  12. address,caption,cite,code,dfn,em,strong,th,var {
  13. font-style:normal;
  14. font-weight:normal;
  15. }
  16. ol,ul {
  17. list-style:none;
  18. }
  19. caption,th {
  20. text-align:left;
  21. }
  22. h1,h2,h3,h4,h5,h6 {
  23. font-size:100%;
  24. font-weight:normal;
  25. }
  26. q:before,q:after {
  27. content:'';
  28. }
  29. abbr,acronym { border:0;
  30. }
复制代码

2)基本的样式

首先我们要为网页做一些基本的css样式,包括文字字体、基本结构等。下面开始设置背景色、字体、去掉超链接的下划线以及一些容器的尺寸。
  1. body {
  2. background: #F2F2F2;
  3. font: 10px Verdana;
  4. }

  5. a {
  6. text-decoration: none;
  7. }

  8. p, span {
  9. line-height: 20px;
  10. }

  11. #header, #featured, #content, #footer {
  12. overflow: hidden;
  13. }

  14. .container {
  15. margin: 0 auto;
  16. width: 1024px;
  17. }

  18. .clear {
  19. clear: both;
  20. }

复制代码

现在的css样式效果如下:

ps2.jpg (28.2 KB, 下载次数: 3)

下载附件  保存到图库

2011-3-30 16:19 上传



3)编写#header的样式

现在开始为header部分编写样式,将header部分的高设为68px,背景为灰色,2px的下边框。

通过将logo文字的text-indent设为-9999px,可以让图像来代替文字的显示。然后我们为导航栏设置左浮动(float:left),让它变成横向导航。通过增加一个.active来编写导航栏当前页的样式。
  1. #header {
  2. background: #171717;
  3. border-bottom: 2px solid #252525;
  4. height: 68px;
  5. }

  6. #header #logo {
  7. float: left;
  8. text-indent: -9999px;
  9. }

  10. #header ul {
  11. float: right;
  12. height: 68px;
  13. padding: 17px 0;
  14. }

  15. #header ul li {
  16. color: #D1D1D1;
  17. display: block;
  18. float: left;
  19. font: bold 10px Verdana;
  20. padding: 10px 15px;
  21. }

  22. #header ul li a {
  23. color: #D1D1D1;
  24. text-decoration: none;
  25. }

  26. #header ul li a:hover {
  27. color: #FFF;
  28. }

  29. #header ul li:hover a {
  30. color: #FFF;
  31. }

  32. #header ul li.active {
  33. background: #252525;
  34. border-radius: 2px;
  35. -webkit-border-radius: 2px;
  36. -moz-border-radius: 2px;
  37. -o-border-radius: 2px;
  38. }

  39. #header ul li.active a {
  40. color: #FFF;
  41. }

  42. #header ul li:last-child {
  43. padding: 10px 0 10px 15px;
  44. }

复制代码

现在的css样式效果如下:

ps3.jpg (28.34 KB, 下载次数: 1)

下载附件  保存到图库

2011-3-30 16:20 上传


4)编写#featured部分样式

我们为featured部分添加相应的背景,这个背景设为水平居中,这样即使图片比一些屏幕分辨率大,也能居中显示。然后我们要将welcome部分的文字设为不可见,这样我们就可以用图像来代替它。
同时为welcome下的文字加一些css3的属性,文字阴影。

  1. #featured {
  2. background: #476D13 url('layout/header.png') no-repeat center top;
  3. height: 290px;
  4. }

  5. #featured #welcome {
  6. float: left;
  7. width: 440px;
  8. }

  9. #featured #welcome h2 {
  10. background: url('layout/welcome.png') no-repeat left top;
  11. line-height: 57px;
  12. padding: 0 0 20px;
  13. text-indent: -9999px;
  14. }

  15. #featured #welcome p {
  16. color: #FFF;
  17. font: 10px Verdana;
  18. line-height: 20px;
  19. margin: 15px 0;
  20. text-shadow: 0px 1px 0px #3F6211;
  21. -webkit-text-shadow: 0px 1px 0px #3F6211;
  22. -moz-text-shadow: 0px 1px 0px #3F6211;
  23. -o-text-shadow: 0px 1px 0px #3F6211;
  24. }

复制代码

5)编写#slider
的样式

slider部分样式编写也比较简单,我们将slider的overflow设为hidden,这样超出slider区域部分的内容就不会显示出来。边框的部分用绝对定位的方式(position:absolute),将透明的边框覆盖在slider的图片上。
  1. #featured #slider {
  2. float: right;
  3. position: relative;
  4. width: 512px;
  5. overflow: hidden;
  6. }

  7. #slider #frame {
  8. background: transparent url('layout/frame.png') no-repeat center top;
  9. height:300px;
  10. position: absolute;
  11. top: 0;
  12. left: 0;
  13. width: 512px;
  14. z-index: 100;
  15. }

复制代码

现在的css样式效果如下图:

ps5.jpg (33.67 KB, 下载次数: 3)

下载附件  保存到图库

2011-3-30 16:21 上传


6)编写#status样式

这个部分只是一段文字和一个按钮,因为#featured部分有一个40px的margin,所以我们要为#status加一个-40px的margin来抵消它。

按钮的制作是用了一些css的属性,这样一些不支持css3的浏览器将会显示不同的效果,如果需要所有浏览器显示相同效果,可以考虑用图片。具体代码如下:
  1. #status {
  2. background: #F1EEEE;
  3. border-bottom: 1px solid #DCDEDE;
  4. margin: -40px 0 0;
  5. padding: 20px 0;
  6. }

  7. #status span {
  8. color: #CCC9C9;
  9. font: bold 20px Verdana;
  10. line-height: 50px;
  11. }

  12. #status button {
  13. background-color: #E9E5E5;
  14. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#FFF), to(#E9E5E5));
  15. background: -moz-linear-gradient(top, #FFF 0%, #E9E5E5 100%);
  16. filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr='#FFFFFF', endColorstr='#E9E5E5'); /* IE6 & IE7 */
  17. -ms-filter: "progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr='#FFFFFF', endColorstr='#E9E5E5')"; /* IE8 */
  18. border: 1px solid #D9D9D9;
  19. box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
  20. -webkit-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
  21. -moz-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
  22. -o-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
  23. color: #333;
  24. float: right;
  25. font: bold 20px Verdana;
  26. height: 50px;
  27. line-height: 30px;
  28. width: 175px;
  29. }

  30. #status button:hover {
  31. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#E9E5E5), to(#FFF));
  32. background: -moz-linear-gradient(top, #E9E5E5 0%, #FFF 100%);
  33. }

复制代码

现在css样式效果如下:

ps6.jpg (33.42 KB, 下载次数: 2)

下载附件  保存到图库

2011-3-30 16:22 上传


7)编写#content第一部分的样式

#content的第一部分由两个各占据50%宽度的div组成,标题部分文字大小我们设为20px并且设为粗体、斜体,让它更为突出:
  1. #content #about_us, #content #others_say {
  2. float: left;
  3. padding: 20px 0 30px;
  4. width: 50%;
  5. }

  6. #content #about_us h3, #content #others_say h3 {
  7. color: #474747;
  8. font: bold italic 20px Verdana;
  9. line-height: 40px;
  10. }

  11. #content #others_say p cite {
  12. font: bold italic 10px Verdana;
  13. padding: 0 0 0 60px;
  14. }

  15. #content #others_say p cite a {
  16. color: #000;
  17. }

复制代码

8)编写#content第二部分的样式

第二部分的四块区域每个大概占据23%左右的宽度,这样我们就能为各区域之间增加一些margin,同时由于我们为图片加了1px的边框,所以宽度要计算好。同时最后一块区域的右边距要设为0。
  1. #content ul li {
  2. float: left;
  3. margin: 0 28px 0 0;
  4. width: 235px;
  5. }

  6. #content ul li img {
  7. background: #F1EEEE;
  8. border: 1px solid #DCDEDE;
  9. padding: 5px;
  10. }

  11. #content ul li h4 {
  12. color: #474747;
  13. font: bold 14px Verdana;
  14. line-height: 30px;
  15. }

  16. #content ul li:last-child {
  17. margin: 0;
  18. }

复制代码

现在的css样式效果如下:

ps8.jpg (34.33 KB, 下载次数: 2)

下载附件  保存到图库

2011-3-30 16:23 上传


9)编写#footer的样式

footer部分只是一些简单的css属性,比如背景、填充(padding)、颜色等。
  1. #footer {
  2. background: #171717 url('layout/footer.png') no-repeat center top;
  3. height: 250px;
  4. }

  5. #footer ul {
  6. padding: 40px 0 0;
  7. }

  8. #footer ul li {
  9. float: left;
  10. margin: 0 28px 0 0;
  11. width: 235px;
  12. }

  13. #footer ul li h5 {
  14. color: #CCCDD2;
  15. font: bold 14px Verdana;
  16. padding: 0 0 10px;
  17. }

  18. #footer ul li p {
  19. color: #7E7E7E;
  20. font: bold 11px Verdana;
  21. line-height: 20px;
  22. }

  23. #footer ul li ul {
  24. margin: 0;
  25. padding: 0;
  26. }

  27. #footer ul li ul li {
  28. color: #7E7E7E;
  29. font: bold 11px Verdana;
  30. line-height: 20px;
  31. }

  32. #footer ul li ul li a {
  33. color: #7E7E7E;
  34. }

  35. #footer ul li ul li a:hover {
  36. color: #9E9E9E;
  37. }

  38. #footer ul li:last-child {
  39. margin: 0;
  40. }

  41. #footer #copyright {
  42. border-top: 1px solid #424242;
  43. font-size: 11px;
  44. width: 100%;
  45. }

  46. #footer #copyright span {
  47. color: #424242;
  48. float: left;
  49. line-height: 30px;
  50. }

  51. #footer #copyright a {
  52. color: #63961A;
  53. float: right;
  54. line-height: 30px;
  55. }

复制代码

现在的css样式效果如下图。基本的CSS样式已经编写完成,这是css样式的最终效果。

ps9.jpg (36.99 KB, 下载次数: 9)

下载附件  保存到图库

2011-3-30 16:24 上传



5.为HTML的js动态效果添加样式

现在我们要开始为滑动图片slider部分增加一些样式。图片的滑动我们用到了nivo-slider这个插件,这个插件自身带有默认的css样式,我们只需要把它默认的css样式添加到我们的css样式文件即可。如果有兴趣的话,也可以自己更改里面的css样式。
nivo-slider默认的css样式如下,我们把它复制到我们的css文件的最后面。
  1. /*
  2. * jQuery Nivo Slider v2.1
  3. * http://nivo.dev7studios.com
  4. *
  5. * Copyright 2010, Gilbert Pellegrom
  6. * Free to use and abuse under the MIT license.
  7. * http://www.opensource.org/licenses/mit-license.php
  8. *
  9. * March 2010
  10. */

  11. /* The Nivo Slider styles */
  12. .nivoSlider {
  13. position:relative;
  14. }
  15. .nivoSlider img {
  16. position:absolute;
  17. top:0px;
  18. left:0px;
  19. }
  20. /* If an image is wrapped in a link */
  21. .nivoSlider a.nivo-imageLink {
  22. position:absolute;
  23. top:0px;
  24. left:0px;
  25. width:100%;
  26. height:100%;
  27. border:0;
  28. padding:0;
  29. margin:0;
  30. z-index:60;
  31. display:none;
  32. }
  33. /* The slices in the Slider */
  34. .nivo-slice {
  35. display:block;
  36. position:absolute;
  37. z-index:50;
  38. height:100%;
  39. }
  40. /* Caption styles */
  41. .nivo-caption {
  42. position:absolute;
  43. left:0px;
  44. bottom:0px;
  45. background:#000;
  46. color:#fff;
  47. opacity:0.8; /* Overridden by captionOpacity setting */
  48. width:100%;
  49. z-index:89;
  50. }
  51. .nivo-caption p {
  52. padding:5px;
  53. margin:0;
  54. }
  55. .nivo-caption a {
  56. display:inline !important;
  57. }
  58. .nivo-html-caption {
  59. display:none;
  60. }
  61. /* Direction nav styles (e.g. Next & Prev) */
  62. .nivo-directionNav a {
  63. position:absolute;
  64. top:45%;
  65. z-index:99;
  66. cursor:pointer;
  67. }
  68. .nivo-prevNav {
  69. left:0px;
  70. }
  71. .nivo-nextNav {
  72. right:0px;
  73. }
  74. /* Control nav styles (e.g. 1,2,3...) */
  75. .nivo-controlNav a {
  76. position:relative;
  77. z-index:99;
  78. cursor:pointer;
  79. }
  80. .nivo-controlNav a.active {
  81. font-weight:bold;
  82. }

复制代码

插入Java Script语句来调用插件我们需要在html里面加入一段js语句来调用这个插件,记住这个语句要放在导入Nivo-slider.min.js之后。至于具体的一些选项,读者可以到这个插件的官网查询相应的文档。
  1. <script type="text/javascript">
  2. $(window).load(function() {
  3. // Slider
  4. $('#slider .slides').nivoSlider({
  5. effect: 'random',
  6. directionNav: false,
  7. controlNav: false
  8. });
  9. });
  10. </script>

复制代码

总结

经过漫长的操作,终于完成了将psd转成html/css的过程,现在读者应该对这个工作的流程有一个系统的了解,转换psd到html/css的工作包括psd图片的切片、html和css文件的编写、js插件的使用等。现在你可以开始尝试做一个网页,相信很快就会懂得如何转换psd到html/css。

  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值