跳转到帖子
在手机APP中查看

一个更好的浏览方法。了解更多

OKCCN - XenForo & IPS Plugin Marketplace

主屏幕上的全屏APP,带有推送通知、徽章等。

在iOS和iPadOS上安装此APP
  1. 在Safari中轻敲分享图标
  2. 滚动菜单并轻敲添加到主屏幕
  3. 轻敲右上角的添加按钮。
在安卓上安装此APP
  1. 轻敲浏览器右上角的三个点菜单 (⋮) 。
  2. 轻敲添加到主屏幕安装APP
  3. 轻敲安装进行确认。
  • 选择语言

Responsive Web Design - Building a Grid View

推荐的帖子

  • 行政经理

Responsive Web Design - Building a Grid View


What is a Grid-View?

Many web pages are based on a grid-view, which means that the page is divided into rows and columns.

A responsive grid-view often has 6 or 12 columns, and will shrink and expand as you resize the browser window.


Building a Grid View

Lets start building a grid-view.

First ensure that all HTML elements have the box-sizing property set to border-box. This makes sure that the padding and border are included in the total width and height of the elements.

Add the following at the top of your CSS:

* {
  box-sizing: border-box;
}

Read more about the box-sizing property in our CSS Box Sizing chapter.


The HTML

We create a grid container with five grid items (header, menu, content, facts, footer):

HTML

Here is the complete HTML:

<div class="grid-container">

<div class="header"><h1>Chania</h1></div>

<div class="menu">
  <ul>
    <li>The Flight</li>
    <li>The City</li>
    <li>The Island</li>
    <li>The Food</li>
  </ul>
</div>

<div class="content">
  <h1>The City</h1>
  <p>Chania is the capital of the Chania region on the island of Crete.</p>
  <p>The city can be divided in two parts, the old town and the modern city. The old town is situated next to the old harbour and is the matrix around which the whole urban area was developed.</p>
  <p>Chania lies along the north west coast of the island Crete.</p>
</div>

<div class="facts">
  <h2>Facts:</h2>
  <ul>
    <li>Chania is a city on the island of Crete</li>
    <li>Crete is a Greek island in the Mediterranean Sea</li>
  </ul>
</div>

<div class="footer"><p>A footer.</p></div>

</div>


The CSS

Add some styles and colors to make it look better:

Note: Look at the next chapter to add mediaqueries and breakpoints for different screen sizes!

Example

Here is the complete CSS:

* {
  box-sizing: border-box;
}

body {
  font-family: "Lucida Sans", sans-serif;
  font-size: 17px;
}

.grid-container {
  display: grid;
  grid-template-areas:
  'header'
  'menu'
  'main'
  'facts'
  'footer';
  background-color: white;
  gap: 10px;
}

.header {
  grid-area: header;
  background-color: purple;
  text-align: center;
  color: #ffffff;
}

.header > h1 {
  font-size: 40px;
}

.menu {
  grid-area: menu;
}

.menu ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

.menu li {
  padding: 8px;
  margin-bottom: 7px;
  background-color: #33b5e5;
  color: #ffffff;
}

.menu li:hover {
  background-color: #0099cc;
}

.content {
  grid-area: main;
}

.content > h1 {
  font-size: 30px;
  margin-bottom: 7px;
}

.content > p {
  margin-bottom: 7px;
}

.facts {
  grid-area: facts;
  border: 1px solid #0099cc;
  background-color: beige;
  padding: 10px;
}

.facts > h2 {
  font-size: 20px;
}

.facts li {
  margin-bottom: 5px;
}

.footer {
  grid-area: footer;
  background-color: #0099cc;
  color: #ffffff;
  text-align: center;
}
Try it Yourself »



参与讨论

你可立刻发布并稍后注册。 如果你有帐户,立刻登录发布帖子。

游客
回帖…

帐户

导航

搜索

搜索

配置浏览器推送通知

Chrome (安卓)
  1. 轻敲地址栏旁的锁形图标。
  2. 轻敲权限 → 通知。
  3. 调整你的偏好。
Chrome (台式电脑)
  1. 点击地址栏中的挂锁图标。
  2. 选择网站设置。
  3. 找到通知选项并调整你的偏好。