css - 如何使网格响应?

标签 css html responsive-design grid dreamweaver

我创建了一个网站,但无法使平铺布局响应。我是初学者,我不知道如何让我的网站响应。任何帮助将不胜感激。下面给出了 css 和 html。另外,当我在 css 中没有添加重复属性时,背景重复了 3 次。

HTML

<div class="grid">
  <div class="tile hvr-reveal  " id="tile1">
    <div style="text-align: center;"> 
      <div class="img-with-text ">
        <p>
          <strong>
            <a href="Contact.html" style="text-decoration:none">Contact Us </a>
          </strong>
          <img src="homepage images/file242.png" alt="sometext" width="64" height="64" id="img0"/>
        </p>
      </div>
    </div>
  </div>

  <div class="tile hvr-reveal"  id="tile2">
    <div style="text-align: center;"> 
      <div class="img-with-text">
        <p>
          <strong>
            <a href="products.html" style="text-decoration:none">Products</a>
          </strong>
          <img src="homepage images/shopping145.png" alt="sometext" width="64" height="64" id="img"/>
        </p>
      </div>
    </div>
  </div>

  <div class="tile hvr-reveal " id="tile3">
    <div style="text-align: center;"> 
      <div class="img-with-text">
        <p>
          <strong>
            <a href="partners.html" style="text-decoration:none">Partners</a>
          </strong>
          <img src="homepage images/celebration19.png" alt="sometext" width="64" height="64" id="img2"/>
        </p>
      </div>
    </div>
  </div>

  <div class="tile hvr-reveal" id="tile4">
    <div style="text-align: center;"> 
      <div class="img-with-text">
        <p>
          <strong>
            <a href="ABOUTUS.HTML" style="text-decoration:none">About Us</a>
          </strong>
          <img src="homepage images/men16.png" alt="sometext" width="64" height="64" id="img1"/>
        </p>
      </div>
    </div>
  </div>
</div>

CSS

body { 
  font-family: chewy;   
  color: #ffffff; 
  background-image: url(pictures%20for%20web/bg3.jpg) ;
  background-position: center center;
  background-attachment: fixed;
  background-size: cover;

  **strong text**background-repeat: no-repeat;

  webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
}

.grid { 
  width: 1140px; 
  height: 650px; 
  margin: auto;
}


.tile {
  position: absolute;
  width: 200px;
  left: 451px;
  top: 152px;
  height: 152px;
  box-sizing: border-box;
}

#tile1 {
  top: 407px;
  left: 754px;
  width: 338px;
  height: 196px;
  margin-left: 2px;
  margin-right: 2px;
  background-color: #ff3300;
}

#tile2 {
  margin-left: 2px;
  margin-right: 2px;
  top: 100px;
  left: 980px;
  width: 148px;
  height: 154px;
  background-color: #008000;
}

#tile3 {
  top: 255px;
  left: 523px;
  width: 200px;
  height: 150px;
  background-color: #660066 ;
  margin-left: 2px;
  margin-right: 2px;    
}

#tile4 {
  top: 255px;
  left: 118px;
  width: 200px;
  height: 150px;
  background-color: #990000;
  margin-left: 2px;
  margin-right: 2px;
}

最佳答案

我猜你想要这样的东西:

<div class="container">
  <div class="box"></div>
  <div class="box"></div>
  <div class="box"></div>
  <div class="box"></div>
</div>

.container {
  position: relative;
  top: 0;
  left: 0;
  width: 90%;
  height: auto;
  margin-left: 5%;
  background-color: #444;
  display: block;
  text-align: center;
}

.box {
  border: solid 1px #000;
  height: 200px;
  width: 200px;
  display: inline-block;
  margin: 25px auto;
}

.box:nth-of-type(1){
  background: yellow;
}
.box:nth-of-type(2){
  background: red;
}
.box:nth-of-type(3){
  background: blue;
}
.box:nth-of-type(4){
  background: green;
}

这将使框保持对齐,并根据浏览器的宽度移动它们。

http://codepen.io/DB1500/pen/JGqaBZ

关于css - 如何使网格响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35511807/

相关文章:

php - 在移动设备上排除部分 CSS

html - 如何将文本移动到图像旁边并使文本响应

jquery - 模态窗口问题

css - 更改链接 CSS 颜色而不更改 :hover color

html - 删除并重新添加 CSS 属性会更改元素的位置

javascript - 如何用图像替换单选按钮

html - 如何将 Bootstrap 中的导航与更多元素重叠?

html - 如何在 Bootstrap 中按百分比排列 div 的高度,没有滚动条

html - 如何在 HTML 中的图像顶部添加元素?

CSS - 列表元素宽度为 25%