CSS 框架替代指南(全)
原文:CSS Framework Alternatives
协议:CC BY-NC-SA 4.0
一、为直观的网页设计选择轻量级框架
什么是框架?
A framework is a premeditated set of concepts, modules, and standardized criteria that make the task of developing web sites and web applications easier. It provides generic functionality with already written modules and tailored components created in a standard manner. In short, it is a reusable software environment that allows web designers and developers to easily build their projects and solutions with minimal coding and without worrying about the low-level details. This reduces development time and provides easy upkeep and alterations whenever necessary. Usually, there are two kinds of frameworks .
- 前端框架(CSS 和 JavaScript 框架)
- 后端或服务器端编程框架
While back-end frameworks are used by web developers and programmers to build applications on the server-side, front-end frameworks are used by web designers and developers for implementing the Cascading Style Sheets language. In this book, you will get a glimpse into front-end frameworks, which basically are pre-prepared packages containing the structure of files and folders of Hypertext Markup Language (HTML) and CSS documents (some with JavaScript functions), which help designers and developers build interactive and immersive web sites. Frameworks allow you to use a common standardized structure that cuts out much of the groundwork of writing code from scratch and helps you reuse components, modules, and libraries, freeing you up to focus on core tasks at a high level.
CSS 框架的组件
The following are the basic components of a CSS framework:
- 网格(帮助组织内容和设计布局的结构)
- 排版元素
- 跨浏览器兼容性
- 用于定位元素的帮助器类
- 实用程序类别
- 导航元素
- 用 Sass 等预处理程序编写的源代码
- 媒体元素(徽章、工具提示、评论等)
使用 CSS 框架的优势
Though some people have advocated not using CSS frameworks, mainly because of issues such as bloated structure, ingrained HTML markup, and a common aesthetic across framework-based web sites, using a CSS framework has several benefits. You should try using a CSS framework for the following reasons:
- 干净一致的编码
- 跨浏览器兼容性
- 基于网格的设计
- 整合健康编码实践的能力
- 易于构建的原型
- 易于维护和保养
- 允许重用和干净的同质代码结构
- 易于扩展和修改
- 可靠的文件
- 构建沉浸式网站的共同基础
- 易接近
A budding developer can find it difficult to build web sites just based on pure HTML, CSS, and JavaScript. In addition, grid-based layouts help budding designers to position, structure, and design the layout quite easily. You do not have to reinvent the wheel, meaning you can get some hands-on experience without the intricacies and dilemmas that you will come across when you code from scratch. Good and clean coding practices are imperative when you grow as a web designer, and frameworks are all about awesome cohesiveness and consistent coding that will hold you in good stead in times to come.
各种流行的框架
In this section, you will look at the most popular frameworks used by web designers across the globe. The most popular frameworks for designing web sites are Bootstrap, Foundation, and Materialize. Which one a developer chooses depends on the needs and requirements of a web site and its design. However, just because a framework is popular doesn’t mean it fits the bill when it comes to designing your projects. You need to consider several issues when it comes to selecting a framework; we’ll talk more about that later. Let’s now take a look at the various superlative frameworks that are in vogue today.
引导程序
Bootstrap is the most popular mobile-first framework in web design; it’s used extensively by developers across the globe (Figure 1-1). You can find more information on the official web site at getbootstrap.com/
. Figure 1-1Bootstrap Bootstrap adopts a mobile-first paradigm by which you can build responsive web sites. It comes with components, modules, JavaScript functions, and media queries that help developers build immersive web sites with ease.
基础
Foundation was the earliest responsive framework and is as massive and advanced as Bootstrap for building web products and services (Figure 1-2). Foundation comes with cool features such as Flex Grid and Motion UI . The latest version, Foundation 6, is quicker, is lighter in size compared to its earlier versions, and is a solid front-end framework for designing beautiful web sites, e-mails, and apps that look good on any device. You can find more information on the official web site at foundation.zurb.com/
. Figure 1-2 Foundation
实现
Materialize is a modern front-end framework based on Google’s Material Design philosophy that helps developers build and design immersive web sites (Figure 1-3). You can find more information on the official web site at materializecss.com/
. Figure 1-3Materialize Materialize has a superlative, creative user interface (UI) component library that incorporates cross-browser compatibility and device-agnostic capabilities for developing attractive and consistent web sites.
骨骼
As mentioned earlier, sometimes you don’t need a large framework, especially if you are embarking on a small project. Skeleton is a simple, responsive boilerplate and is extremely lightweight with 400 lines of code and with a mobile-based philosophy (Figure 1-4). You can find more information on the official web site at getskeleton.com/
. Figure 1-4Skeleton
Milligram
Milligram is a minimalistic framework with just enough styles for small and interactive web sites (Figure 1-5). Its zipped file size is only 2KB. It comes with a mobile-first philosophy and supports the modern browser versions of Chrome, Firefox, Safari, IE, and Opera. Its cutting-edge features include the FlexBox grid system, and it is a simple, top-notch framework from a usability point of view. You can find more information on the official web site at milligram.io/
. Figure 1-5 Milligram
UIkit
UIkit is a light and modular front-end framework for developing faster and powerful web interfaces (Figure 1-6). It has a massive collection of HTML, CSS, and JavaScript components and modules that can be extended with themes. It is flexible because it can be customized to give a unique feel to your web sites. You can find more information on the official web site at getuikit.com/v2/
. Figure 1-6UIkit
材质设计精简版
Google released its own front-end framework called Material Design Lite (MDL) that is based on its Material Design philosophy (Figure 1-7). MDL is a lightweight framework with few dependencies and is focused on simple web sites such as blogs and landing pages. It allows you to customize styles and web sites designed using MDL degrade gracefully in legacy browsers. You can find more information on the official web site at getmdl.io/
. Figure 1-7Material Design Lite
Susy!Susy
In today’s era of agile development and constant changes, the layout designs are crucial and cannot be restricted to a single framework, especially if your web site is intricate design-wise. With Susy (Figure 1-8), the settings are not set in stone, meaning you can use its integrated Sass-based libraries to create immersive layouts with potent structural designs. Susy is not a typical framework but more of a UI utility as it simplifies and streamlines the task of designing intricate grid layouts. You can find more information on the official web site at susy.oddbird.net/
. Figure 1-8 Susy
选择框架
As you can see, we have covered many popular frameworks. Choosing the right framework is quite important and depends on the needs and requirement of your projects. Some frameworks are bloated, meaning they have too many built-in styles, which might not be required for a small project. The following are some of the factors that you should consider when choosing a framework:
- 一个现有的 web 项目可能已经在使用一个特定的框架,而该框架不能与您想要的框架一起使用。
- 对于与性能相关的问题,一些项目可能不需要与重量级框架相关的混乱。
- 您可能需要不同的预处理器支持,比如对于 LESS 或 Sass,它们没有与您想要的框架集成。
- 使用特定框架构建的网站可能看起来很相似,如果没有进行定制以提供真实的外观和感觉的话。
There are several other factors such as the ease of use, speed of configuration, usability, features, widgets, components, long-term support, and reliability that you need to consider when choosing a framework. In summary, you need to choose your framework based on the requirements and needs of the project; especially when choosing lightweight front-end kits for small projects, given the bloat and bulk associated with massive frameworks.
网格的概念
A grid system allows you to structure and stack content horizontally and vertically in an easy manner. It is easily adaptable for any web site or web application and has a lot of advantages. It is usually responsive, meaning it adjusts itself based on the browser or device width. So, it displays the content appropriately in a mobile device, a laptop, a tablet, or a desktop depending on the size of the device. Plus, you have media queries, which help you define the grid layout based on the device width. Grids are usually 12-column containers in many frameworks but can be customized using methods specific to the framework. You can have flexible layouts wherein you can divide the page into several regions and place content using the markup. Another concept catching on in CSS designs is the FlexBox . The difference between a grid and FlexBox layout is that grid layouts are two-dimensional, while a FlexBox is usually one-dimensional wherein you can lay out content in a row or a column. The choice of using a grid layout or a FlexBox depends on how you want to structure your content. With a FlexBox you space out the content and build a structure using that content. Suppose you have certain items; it is up to you to decide how much space each item should take. Grid layouts, on the other hand, are content-agnostic. In grid layouts, you create a layout and place the content into rows and columns. In most modern frameworks, both the grid and the FlexBox are supported. While the usability of the grid layout is awesome, a FlexBox can help you place things more aesthetically. For a detailed explanation of the grid concept , you can refer the Mozilla developer network web site, specifically the following web page, for in-depth information: developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout
.
摘要
In this chapter, we gave you an overview of some popular CSS frameworks. We also covered the benefits of using a CSS framework. CSS frameworks are comprised of components, modules, libraries, navigational elements, typography, media queries, tailor-made widgets, and grid layouts that make web design a breeze. We also gave you an overview of grid and FlexBox layouts. We will now dedicate a chapter for each of the frameworks mentioned in the introduction of the chapter, starting with Skeleton. With each chapter, we use a progressive approach, meaning the next framework is more extensive and a framework’s resourcefulness increases as you move through the book.
二、使用框架构建登录页面
安装骨架
To get started, go to the Skeleton web site at getskeleton.com/
. You will see the Download button, which is highlighted in a red box in Figure 2-1. Figure 2-1Skeleton download page Click Download to download the Skeleton .zip file. After unzipping the file, you will see the file structure shown in Figure 2-2. Figure 2-2 Content of the Skeleton framework The css folder is where you save your CSS files . By default, the css folder contains the Normalize and Skeleton style sheets. Normalize.css is a small CSS file that provides better cross-browser consistency in the default styling of HTML elements. It makes browsers render all elements more consistently and in line with modern standards. It precisely targets only the styles that need normalizing. You can find more information about Normalize on the official web site at necolas.github.io/normalize.css/
. You can also see the images folder where you can store your images. By default, the images folder contains the favicon image for Skeleton. The index.html file is your default web page. When you edit the page in Notepad++ or any editor, you will see the code displayed in Listing 2-1.
Basic Page
This index.html page is a placeholder with the CSS, font and favicon. It's just waiting for you to add some content! If you need some help hit up the Skeleton documentation.
骨架网格系统
Like most other frameworks, Skeleton has its own grid system. It is essentially a 12-column grid with a maximum width of 960px. It is a responsive grid that adjusts itself depending on the browser/device size. Take a look at the code snippet in Listing 2-2 to understand how the grid system works.
</div
element for spacing between each row. Basically, the code in Listing 2-2 defines different rows with a
骨骼属性概述
Let’s take a look at some attributes of the Skeleton framework.
-
Skeleton 的排版基础是 Raleway,一个基于 Google 的排版。字体大小默认为 HTML 的字体大小,版式保留类似于 HTML 基本版式的属性,如锚点、粗体、强调和下划线。
-
骨架中的按钮可以使用 button-primary 类创建,这很容易区分。如果不想要增强按钮,也可以选择标准按钮。为此,您只需使用 button 类,而不是 button-primary。您还可以使用
-
使用
-
代码样式可以通过使用`类来设置。对于几个代码块,可以在一个
元素中使用元素。
-
Skeleton 中的表格类似于 HTML 表格,其中使用了和元素。与 HTML 类似,使用定义表格行,定义表格数据,定义表格标题;您将所有内容包装在主元素中。
-
Skeleton 使用以最小宽度为目标的移动优先查询。查询之外的样式适用于所有设备。这样做是为了防止手机和平板电脑等小型设备解析大量未使用的 CSS。框架根据设备大小使用以下媒体查询大小:
- 手机:400 像素
- Phablet: 550px
- 平板电脑:750 像素
- 桌面:1000 像素
- HD 桌上型电脑:1200px
Skeleton also comes with many helper classes that can be used to limit the elements within a container , float the element to the left or right, and clear the floats on both sides.
用框架构建登陆网页
In this section, you will create a landing page for a freelance portal called RemoteDesk . The landing page shows the various things you can do on the freelance portal. You will design a web page that shows several aspects of the freelance portal along with company information and other basic features. We will divide the process of building the web page into six Steps. After these six Steps, you will have a complete landing page.
步骤 1:定义内容区域
You will define the tags and then move on to include the necessary links for Skeleton and Normalize (included by default in Skeleton) and the custom style sheet in the tags (more about that in the code explanation). Then you will define the section after the tags and within the tags. Inside the tags, you will define the
developers.google.com/speed/docs/insights/ConfigureViewport
. Then, by default in Skeleton, you set the links for Normalize and Skeleton. Remember that if the path to your files is different, you need to specify so. For now, they should be in the root folder , so the default path is good to go. Then you define the path for the custom style sheet called as style.css , which you will place in the css folder. You define a tag and assign the container class to it. The container is the main centered wrapper. You define a 步骤 2:完成标签内容
Now, you will create the rest of the content within the tags. You will start with inserting an image, as shown in Listing 2-4. (Refer to the entire code in the code bundle to see the positioning of the various elements; we have included code in steps in the code bundle so that you can have a better understanding of each step. Finally, index.html contains the entire code for the landing page.)
Listing 2-4Inserting the Header Image You have just used the row class and assigned a class called masthead to it. The image is defined in the code in the style sheet called Style.css. The image referred to, masthead.png, is located in the images folder where you will keep all the images. In style.css, you define the code, as shown in Listing 2-5. .masthead{ background: url("img/masthead.png") no-repeat center; height: 462px; background-size: cover; } Listing 2-5Inserting Header Image Remember that the code shown in Listing 2-5 is the code in the custom CSS style sheet called style.css . You assign a height of 462px and center the image. You also assign the value cover to the background-size property; this scales the background image to be as large as possible so that the background area is fully covered by the image. Now on executing the index.html page , you will get the output shown in Figure 2-6. Figure 2-6Output of the header image步骤 3:定义自由职业门户
Next, you will create a later section of the page where you define the features of the freelance portal . To create this section, let’s look at the code snippet shown in Listing 2-6.
Plenty of rewarding projects
RemoteDesk is a great place to find more clients, and to run and grow your own freelance business.
- Freedom to work on ideal projects. On RemoteDesk, you run your own business and choose your own clients and projects. Just complete your profile and we’ll highlight ideal jobs. Also search projects, and respond to client invitations.
- Wide variety and high pay. Clients are now posting jobs in hundreds of skill categories, paying top price for great work.
- More and more success. The greater the success you have on projects, the more likely you are to get hired by clients that use Upwork.
- tags and define the list items using the
- tags. Then, you create the second spanning six columns where you insert an image using the tag. You also add a custom rewardingImg class to it. Next, you can see what to do with the custom classes, rewardingContent and rewardingImg, in the style.css style sheet, as shown in Listing 2-7. .rewardingContent { margin-top:10px; } .rewardingImg { width: 75%; margin: 0 auto; display: block; } Listing 2-7Defining Styles Related to the “Rewarding” Section In this code, you add a margin to the rewardingContent class to set the whitespace around the border. You use the display: block for the rewardingImg so that it occupies the space of the parent element. (You need to use the display: block property because Skeleton does not have any utility classes for responsive images.) You also define a width for the image and center it using margin: 0 auto. Figure 2-7 shows the later section of the page as created in Step 3. Figure 2-7Output of the “rewarding” section
步骤 4:完成各部分
Next, you will create the remaining three sections using the code in Listing 2-8.
Get hired quickly
RemoteDesk makes it easy to connect with clients and begin doing great work.
- Streamlined hiring. RemoteDesk's sophisticated algorithms highlight projects you're a great fit for.
- Top Rated and Rising Talent programs. Enjoy higher visibility with the added status of prestigious programs.
- Do substantial work with top clients. RemoteDesk pricing encourages freelancers to use Upwork for repeat relationships with their clients.
Work efficiently, effectively.
With Upwork, you have the freedom and flexibility to control when, where, and how you work. Each project includes an online workspace shared by you and your client, allowing you to:
- Send and receive files. Deliver digital assets in a secure environment.
- Share feedback in real time. Use Upwork Messages to communicate via text, chat, or video.
- Use our mobile app. Many features can be accessed on your mobile phone when on the go.
Get paid on time
All projects include Upwork Payment Protection — helping ensure that you get paid for all work successfully completed through the freelancing website.
- All invoices and payments happen through RemoteDesk. Count on a simple and streamlined process.
- Hourly and fixed-price projects. For hourly work, submit timesheets through RemoteDesk. For fixed-price jobs, set milestones and funds are released via Upwork escrow features.
- Multiple payment options. Choose a payment method that works best for you, from direct deposit or PayPal to wire transfer and more.
s with the row class. In the firstcontaining the row class, you create twos each spanning six columns. In the first child, you insert an image using the tag, and in the second child, you create a heading followed by creating a list using the- and
- tags. In short, you create the next three content blocks using a similar technique as you did in Step 3. Similarly, you create a similar structure for the remaining two s with the row class by inserting two childs, each spanning six columns. You also insert an image and create an unordered list similar to the previouss. Then, you define the CSS styles for the custom CSS code in the style.css style sheet just like you did in Step 3. Listing 2-9 shows the CSS style sheet code. .rewardingContent,.hiredContent,.workEfficiency,.getPaid{ margin-top:10px; } .rewardingImg,.hiringImg,.messagingImg,.paidImg { width: 75%; margin: 0 auto; display: block; } Listing 2-9Adding Styles for the Remaining Sections Figure 2-8 shows the output of the code in Step 4. Figure 2-8Output of the content of the remaining sections
步骤 5:设计注册表单
In this Step, you will create a small sign-up form. Listing 2-10 shows the code for the form.
Ready to get hired?
Sign upand assign the row class to it. You then add threes with the columns class within thewith the row class. You then add inputs in the first twos for the full name and e-mail. Here you use a utility class provided by Skeleton; for example, u-full-width is used so that the fields occupy the full width of the container. You then place a Sign Up button in the last. Figure 2-9 shows the output of the form. Figure 2-9Output of the sign-up form步骤 6:创建页脚
Finally, you will create the footer. Listing 2-11 shows the code for the footer section.
Listing 2-11Footer In Listing 2-11, you create atag and assign a row class to it. Within that, you create three childs, each spanning four columns using the four columns class. The first childcontains anchor links, , for the company information. The second childcontains anchor links for the additional services, whereas the third childcontains anchor links for the Browse section. Figure 2-10 shows the footer section of the web page. Figure 2-10Output of the footer section You have just designed a landing page for the RemoteDesk freelance portal using Skeleton!摘要
Skeleton is a simple framework that beginners can adopt quickly. It has a clean and concise code base. However, Skeleton does have its drawbacks.
- 它缺少其他框架提供的几个 CSS 特性。正因为如此,使用 Skeleton 的开发时间比同类产品要长。
- 12 列流体网格支持的最大宽度为 960 像素。
- 另一个缺点是缺乏社区支持。这个框架的最后一次更新是在三年前。此外,许多“拉”请求和问题仍然是开放的,这意味着所有的差异都还没有随着实质性的更新而得到解决。
Therefore, when it comes to massive, immersive web sites, Skeleton falls short. Nevertheless, it is a handy utility suitable for web projects, meant mainly for smaller screens. In the next chapter, you will design a product page with Milligram, another intuitive lightweight framework.
三、使用 Milligram 建立产品页面
安装 Milligram
There are different ways you can install Milligram. In this section, you will learn how to install Milligram by downloading the Milligram files. Go to the Milligram web site at
milligram.io/
and click the Download Milligram button, as highlighted in Figure 3-1. The zip file will be downloaded. Figure 3-1Milligram download page Figure 3-2 shows the file structure . Figure 3-2Content of the Milligram framework The CSS files (both the usual ones as well as the minified versions) are present in the dist folder. Figure 3-3 shows the file structure. Figure 3-3File structure of Milligram framework (source: Milligram) You can also download the Milligram files or install it using Bower, NPM, or Yarn. For installation through Bower, NPM, and Yarn, you need to use the following commands from the command-line prompt: $ bower install milligram $ npm install milligram $ yarn add milligram Once you download Milligram, add the tags for the files in the head section of your HTML code. There is a preferred way of using Milligram that we will be showing in this chapter, which is to use a content delivery network (CDN) . A CDN is basically a system of distributed networks delivering web pages and other web content according to the geographic location of the users, the source of the web pages, and the location of the CDN server. There are many benefits of using CDN.- 降低服务器负载
- 实现快速内容交付
- 确保高可用性
- 促进高并发网络主干容量
- 更好地控制资产交付
You can add the CDN code for Milligram using the following lines of code: The first line of code is the CDN link for the Google Roboto font. The second line of code is for the Milligram CSS minified file.
Milligram 框架概述
In this section, you will get an overview of the various attributes of Milligram before you learn how to build a product page with the framework.
-
在字体设计上,Milligram 坚持 CSS3 的 rem 单位思想,为根元素定义了一个单一的字体大小,然后所有其他的 rem 单位都是该根元素的一个百分比,从而提供了更容易的可维护性和更简洁的代码。顺便说一下,Milligram 使用 Roboto 字体系列作为其排版的默认字体。
-
以 Milligram 为单位的块引号被引用在
标记之间。在`标签之间定义了一个代码元素。如果你需要一个块,在
标签中包装元素。
-
clearfix 实用程序与 clearfix 类一起使用,而 float 由 float-left 和 float-right 类定义,这取决于您是否希望分别向左和向右浮动。
-
与 HTML 类似,以 Milligram 为单位的列表在
标签中分别定义为有序列表、无序列表和描述列表。每个列表项都被包装在类似 HTML 的
- 标签之间。
-
按钮由 button 类定义,带有锚标记
-
以 Milligram 为单位的表格类似于 HTML 表格,其中使用了和元素。与 HTML 类似,使用定义表格行,定义表格数据,定义表格标题,然后将所有内容包装在主元素中。
-
和 Skeleton 一样,Milligram 使用以最小宽度为目标的移动优先查询。查询之外的样式适用于所有设备。这样做是为了防止手机和平板电脑等小型设备解析大量未使用的 CSS。Milligram 根据设备大小使用以下媒体查询大小:
- 比移动设备/屏幕大:40 雷姆(640 像素)
- 大于平板设备/屏幕:80 雷姆(1280 像素)
- 大于桌面设备/屏幕:120 雷姆(1920 像素)
Milligram 网格系统
Grids in Milligram use the CSS Flexible Box Layout module standard wherein the grid is fluid, shrinking based on the browser at smaller sizes. The entire grid system is responsive with a maximum width of 112rem (1120px). See Listing 3-1 to understand the grid system in Milligram.
Grid system
OneTwoThreeFour
OneTwoelement with a container class. All columns are defined within a row just like in many grid-based frameworks. However, Milligram is different from other frameworks in that you can add any number of columns within a row. You are not restricted to 12 columns like with many popular frameworks. In Listing 3-1, initially you define a row within thewith the container class. Then, you define four columns within that row using the column class. You use inline styles for assigning a border and aligning the text to the center for each column. Then you define another row and a column using a column class. Then you define another column within that row and use the column-50 class along with the column-offset-25 class. What the column-50 class does is assign a column width of 50 percent to the column, which will allocate 50 percent of the column content within the parent row. The column-offset-25 class moves the column to the right by 25 percent column space for that parent row. Figure 3-4 shows the output of the code. Figure 3-4Implementation of grid system of Milligram In Figure 3-4, you can see four columns, named One, Two, Three, and Four, in the first row. The second row has a column named One and a column named Two, which is offset by 25 percent and occupies 50 percent of the row width.用 Milligram 建立产品页面
Now that you have a brief idea about Milligram, you will learn how to create a product page with Milligram. The Product page contains information about a Virtual Private Network (VPN) along with its features and pricing.
步骤 1:定义标题
Let’s look at the code in Listing 3-2 to start the first step of building the secure VPN product page.
Secure VPN Your IP: 115.166.129.152Your Location: UnknownYour Status: UNPROTECTEDwith the row class. You assign another custom class called contactArea to it, which you will use to define the custom CSS code. Next, you define awith a column of 50 percent width within the parent row and offset it by 50 percent within that row by using the column-50 and column-offset-50 classes. Within that, you create threes wherein you define the content that comprises the IP address, location, and status. Then, you define the custom CSS code using the contactArea and contactColumn classes in the custom style.css file. Listing 3-3 depicts the code in the style.css custom CSS file using the contactArea and contactColumn classes for the correspondings. .contactArea{ background: #666; color: #fff; text-align: right } .contactColumn{ font-size: 12px; display: inline-block; margin-right: 10px; } Listing 3-3Defining CSS for the Header In Listing 3-3, you define the background as gray and the color of the words as white for the contactArea class. You align the text to the right. For thethat is defined by the contactArea class, you define the font size as 12px and use a margin. You use the display: inline-block property, which essentially creates a grid of boxes that fills the browser width and wraps it. Here, it helps the content blocks of the header to retain their block-level characteristics and helps them appear next to each other without using a float attribute. Figure 3-5 shows the output of the code. Figure 3-5Output of the header area In Figure 3-5, you can see the elements floated to the right with the IP address and the rest of the content.步骤 2:定义导航
Let’s now look at the code in Listing 3-4 to proceed with step 2.
Listing 3-4 Defining the Navigation In Listing 3-4, you create aand assign a row class to it. You also assign a custom navigation class to it, wherein you will define the custom CSS code in the style.css style sheet . You then create awithin thewith the row class and assign a column width of 25 percent to it by using the column-25 class. You also add a logo custom class to it. You then insert an image for thatusing the element. The path to the images is set to the images folder, with the logo.png as the image name. Within the same row, you create anotherand assign a column width of 50 percent to it using the column-50 class for that parent row, and you offset that column by 25 percent to the right. You define the content in anchor link, , tags. Listing 3-5 shows the custom CSS code linked to the code in Listing 3-4. .logo { text-align: left; } .logo img { width: 25%; margin: 10px 0; } .navigation{ background: #ffc400; text-align: right; padding: 10px 0; font-weight: bold; } .navigation a{ color: #000; padding: 5px; border: 2px solid #000; } Listing 3-5Defining the CSS for the Navigation As you can see in Listing 3-5, you define an image width of 25 percent and set a margin for it. In the navigation class, you define dark orange as the background color and align the text to the right. You set the padding and define the bold font weight for it. To the anchor links containing the Home, Pricing, Support, and Login links, you assign the black color and a black border with a padding of 5px. Figure 3-6 shows the output of the code. In Figure 3-6, you can see the orange background and the links in the anchor tags (i.e., Home, Pricing, Support, and Login) to the right of the screen. You can also see the logo on the left of the screen. Figure 3-6Output of the navigation步骤 3:定义横幅区域
Let’s look at the code in Listing 3-6 to see the next step in the coding process for the secure VPN product page.
Secure your data. Protect your privacy
Protect your IP address and surf the web anonymously
tags and assign the row class as well as the custom mastHead class to it. Inside that row, you define a with a column of 60 percent width for the row for thetag. Listing 3-7 shows the corresponding code for the mastHead class in the custom style.css style sheet. .mastHead { height: 450px; overflow: hidden; background: #ffc400; color: #000; } .mastHead h1,.mastHead h2,.mastHead h3,.mastHead h4,.mastHead h5,.mastHead h6{ color: #000 } Listing 3-7CSS for the Banner Area What you have done is set the height of the with the mastHead class to 450px and set the background to dark orange, the same color as in step 2. Then, you define black color to the content in that section. You also set the color of all the headings in that section to black with the mastHead class. Now you will split the sprite image shown in Figure 3-7 into three parts for the App Store, Google Play, and Windows Phone Store . The rest of the image for the Mac App Store and Windows PC will not be displayed on the page. Figure 3-7Sprite image for store icons You define the code for the unordered list in Listing 3-8 within which you assign a column width of 60 percent, after the headings. within the same section class. Figure 3-8Application image for the banner area You assign a column width of 40 percent for the parenttag and add the mastHeadImage class to it. Listing 3-10 shows the code within the entire tags after incorporating everything from the sprite images into this Android image. element with the last mastHeadImage class. .mastHeadImage{ background: url("img/android-device1.png") no-repeat; background-size: cover; background-position: 0 15px; } Listing 3-11Adding the CSS for the Application Image in the Banner Area In Listing 3-11, you refer to the background and assign the image link. Then you set background-size to cover and set background-position as 15px. Figure 3-9 shows the output of the entire code so far. Figure 3-9Code output so far步骤 4:设计内容区域
Moving Forward, you will design the content area . Listing 3-12 shows how to proceed with building the “benefits” section.
BENEFITS OF USING VPN IN TOUCH
Unblock Websites
Bypass internet restriction and access to any websites: Unblock Facebook, Unblock Youtube.
Secure Your Data
Encrypt your private data before sending it from your computer, smartphone or tablet over the internet.
Bypass content restrictions
Watch Netflix and BBC iPlayer, no matter where you are. Use Skype, Viber and all Voip services without restrictions.
Protect Your Privacy
Hide your IP address, protect your online identity while browsing and surf the web anonymously.
Wifi Hotspot Security
Prevent sniffers and hackers from stealing your private data while using public hotspots.
Data Saving and Ad Blocker on Mobile
Save more bandwidth on your mobile 3G/4G data plan. Clear your mobile screen of obtrusive ads with Ad Blocking mode.
tag and enclose a Listing 3-13HTML for the Pricing Area In Listing 3-13, you define thewith a row class. Within that parent row, you use theheading to define the content for the level 3 heading. After that
, you create awith the row class. You create twos each with a column width of 50 percent of the parentusing the column-50 class. You define a level 4and a paragraph element,
, with their respective content within each child
. Repeat the process three more times, wherein you create twos within a parentwith a row class. Similarly, defineand
under each child
with their respective content. Figure 3-10 shows the output of the code. Figure 3-10Output of the content area步骤 5:创建定价区域
Next, you will create a pricing table wherein you will list the subscription price for the monthly, half-yearly, and yearly timeline. Let’s look at the code in Listing 3-13.
Pricing Overview
pricing 1 Month 6 Months 1 Year Price $9.98/month $2.99/month $2.49/month Save 0% 50% 75% tags within which you define the tables. Initially, you define a with a row class where you use a heading ofwith the column class to define the content, i.e., Pricing Overview. Then, you create a
with the row class after the precedingand assign anotherwith the column class within it. Moving forward, you define the table headings and the table rows with the list of items in the table, which is quite similar to the way you create tables in HTML. Place the content within thetags. Figure 3-11 shows the output of the code. Figure 3-11Output of the pricing area 步骤 6:创建页脚
Finally, you will create a footer for your product page. Let’s look at the code in Listing 3-14 to understand how you design the footer of the web page.
Listing 3-14HTML for the Footer In Listing 3-14, you define the footer content within the