【问题标题】:Why are my table rows not aligning properly?为什么我的表格行没有正确对齐?
【发布时间】:2016-05-30 15:22:26
【问题描述】:

我正在制作我的第一个网站,但在表格和背景方面遇到了一些问题。这是我用手机拍摄的屏幕图片。如果我在电脑屏幕上预览它,它看起来会更好一些,因为我没有背景问题,但无论如何我无法弄清楚表格有什么问题(特别是第四张图片) 并且我的背景没有反应。顺便说一句,所有图片的大小都是一样的......

HTML

<html>
    <body>
        <head>
            <meta charset="utf-8">
            <title>Projects</title>
            <link href="css2.css" rel="stylesheet" type="text/css">
        </head>
        <head>
            <div class="logo" >
                <img src="lg.png" alt="" width="180" height="178" class="logo"/>
            </div>
            <meta charset="utf-8">
            <title>mt</title>
        </head>
        <body>
            <nav>
                <ul>
                    <li><a href="projects.html">PROJECTS</a></li>
                    <li><a href="About.html">ABOUT</a></li>
                    <li><a href="Contact.html">CONTACT</a></li>
                </ul>
            </nav>
            <div class="box" >
            <div class="table" >
                <table width="900" height="200" border="0" cellspacing="7" cellpadding="9">
                    <tbody>
                        <tr>
                            <td>
                                <div class="row" > 
                                    <li>
                                        <a href="project1.html">
                                            <div class="raste">
                                                <img src="logos.jpg" alt="" width="300"/>
                                            </div>
                                        </a>
                                    </li>
                                </div>
                            </td>
                            <td> 
                                <li>
                                    <a href="project2.html">
                                        <div class="raste"> 
                                            <img src="elite.jpg" alt="" width="300"/>
                                        </div>
                                    </a>
                                </li>
                            </td>
                            <td> 
                                <li>
                                     <a href="project3.html">
                                        <div class="raste"> 
                                            <img src="time.jpg" alt="" width="300"/>
                                        </div>
                                    </a>
                                </li>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <li>
                                    <a href="project4.html">
                                        <div class="raste">  
                                            <img src="booksrie.jpg" alt="" width="300"/>
                                        </div>
                                    </a>
                                </li>
                            </td>
                            <td>
                                <li>
                                    <a href="project5.html">
                                        <div class="raste">
                                            <img src="log.jpg" alt="" width="300"/>
                                        </div>
                                    </a>
                                </li>
                            </td>
                            <td>
                                <li>
                                    <a href="project6.html">
                                        <div class="raste">
                                            <img src="log.jpg" alt=""      width="300"/>
                                        </div>
                                    </a>
                                </li>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
           </div>
        </body>
 </html>

CSS

@charset "utf-8";
.logo {
padding-bottom: 0.5%;
text-align: center;
}
nav {
font-family: "Proxima";
text-align: center;
font-size: 25px;
word-spacing: 80px;
padding-right: 50px;
padding-bottom: 1%;
padding-left: 50px;
color: #000000;
}
li {
display: inline;
color: #000000;
}
a {
text-decoration: none;
color: black;
}
a:hover {
color: lightgray;
}
a:active {
color: black;
}
body {
background-color: #F6F6F6;
}
table {
margin-left: auto;
margin-right: auto; 
}
.raste img {
height: 190px;
width: 300px;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
transition: all 0.5s ease;
display: block;
border: none;
border-radius: 10px;    
}
.raste img:hover {
-webkit-transform: scale(1.079);
transform: scale(1.079);
}
.table {
display: table;
margin: 1em auto;
}
.row {
display: table-row;
}
.raste {
display: table-cell;
}
@font-face {
font-family: Proxima;
src: url(Fonts/Proxima_Regular.otf);
}

ul {
padding: 0;
}
.box {
background:#000000;
width: 100%;
background-size: 0% auto;
margin-bottom: 5%;
border-radius: 10px;
padding-bottom: 1%;
padding-top: 1%; 
}

【问题讨论】:

  • 表格用于表格数据 - 而不是布局。此外,您似乎有一些孤立的 li 标签。但看起来你正试图拥有一个 900px 的表格,但你有 300px 的图像 (x3) 加上每个单元格中的 9px 填充和单元格之间的 7px = 所以我猜你的单元格溢出表格 82px?
  • 首先,你的html代码充满了错误。例如两个结束的正文标签,li 没有ul 的表格中的元素,.. 创建有效的 html,然后你可能有一些东西可以使用。
  • 我修复了正文标签...但我不明白...链接和大小有什么问题?你能说得更具体些吗,因为我在这方面还很新
  • 不要使用表格,因此元素可以换行并分成几行。 img 300px 宽度 + 填充......在小屏幕上肯定很难站起来:)。否则,表格元素上的显示也可以重置。无论如何,明智的做法是使用媒体查询,这样您就可以决定何时以及如何在不同的屏幕尺寸上打破设计

标签: html css responsive-design background html-table


【解决方案1】:

使用引导网格示例fiddle

HTML

<div class="main pull-left">
 <div class="col-sm-6 col-md-4 box">1</div>
 <div class="col-sm-6 col-md-4 box">2</div>
 <div class="col-sm-6 col-md-4 box">3</div>
 <div class="col-sm-6 col-md-4 box">4</div>
 <div class="col-sm-6 col-md-4 box">5</div>
 <div class="col-sm-6 col-md-4 box">6</div>
</div>

CSS

body{padding:0px; margin:0px;}
.main{width:100%; background:#000; border-radius:10px; padding:10px;}
.main .box{background:#fff; color:#000; border:solid 4px #000; padding:20px 0px; text-align:center;}

【讨论】:

    【解决方案2】:

    您可以清理您的 html 删除所有无用的标签,因此更容易设置样式、维护和验证。

    示例:

    @charset "utf-8";
     .logo {
      padding-bottom: 0.5%;
      text-align: center;
    }
    nav {
      font-family: "Proxima";
      text-align: center;
      font-size: 25px;
      word-spacing: 80px;
      padding-right: 50px;
      padding-bottom: 1%;
      padding-left: 50px;
      color: #000000;
    }
    nav:before {
      content: url(http://lorempixel.com/100/100/people/6);
      border-radius: 50%;
      overflow: hidden;
    }
    nav:before,
    .table {
      display: table;
      margin: auto; 
      max-width: 1040px;
    }
    
    a {
      text-decoration: none;
      color: black;
    }
    a:hover {
      color: lightgray;
    }
    a:active {
      color: black;
    }
    body {
      background-color: #F6F6F6;
    }
    
    .raste img {
      -webkit-transition: all 0.5s ease;
      -moz-transition: all 0.5s ease;
      -o-transition: all 0.5s ease;
      -ms-transition: all 0.5s ease;
      transition: all 0.5s ease;
      display: block;
      border: none;
      border-radius: 10px;
    }
    .raste img:hover {
      -webkit-transform: scale(1.079);
      transform: scale(1.079);
    }
    .box {
      display: inline-flex;
      flex-wrap: wrap; 
      justify-content:center;
    }
    .raste {
      padding: 15px;
    }
    @font-face {
      font-family: Proxima;
      src: url(Fonts/Proxima_Regular.otf);
    }
    ul {
      padding: 0;
    }
    .box {
      background: #000000;
      background-size: 0% auto;
      margin-bottom: 5%;
      border-radius: 10px;
      padding: 16px;
    }
    <nav> <a href="projects.html">PROJECTS</a>  <a href="About.html">ABOUT</a>  <a href="Contact.html">CONTACT</a>
    </nav>
    <div class="table">
      <div class="box">
        <a href="project1.html">
          <div class="raste">
            <img src="http://dummyimage.com/300x190/456&text=logo.jpg" alt="" />
          </div>
        </a>
        <a href="project2.html">
          <div class="raste">
            <img src="http://dummyimage.com/300x190/55f&text=elite.jpg" alt="" width="300" />
          </div>
        </a>
        <a href="project3.html">
          <div class="raste">
            <img src="http://dummyimage.com/300x190/fed&text=time.jpg" alt="" width="300" />
          </div>
        </a>
        <a href="project4.html">
          <div class="raste">
            <img src="http://dummyimage.com/300x190/bad&text=booksrie.jpg" alt="" width="300" />
          </div>
        </a>
        <a href="project5.html">
          <div class="raste">
            <img src="http://dummyimage.com/300x190/a55&text=log.jpg" alt="" width="300" />
          </div>
        </a>
        <a href="project6.html">
          <div class="raste">
            <img src="http://dummyimage.com/300x190/ef0&text=log.jpg" alt="" width="300" />
          </div>
        </a>
      </div>
    </div>

    【讨论】:

    • 仍然无法正常工作...图像的尺寸为 7.12 厘米 x 4 厘米...当我在这旁边宫殿时,它使后期的两个图像比其他图像大
    • @MaticToni 我没有在 sn-p 中给图像提供任何尺寸,因为它们都是 190x300 ,你正在使用的那些呢?你正在使用的 html 和 CSS 怎么样?是 sn-p 不工作还是你的新尝试?
    • 可能是我的尝试……我真的不知道还能做什么……只有页面宽度为 1000 时看起来还可以……这怎么可能?
    • @MaticToni 尝试构建codepen.io/penjsfiddle.net,以便我们可以在线查看您的代码和问题:) 我删除了.box 上的宽度:100%,是吗? (我会离线几个小时)
    • codepen.io/anon/pen/ZQNYqa我复制了所有代码,它在codepen上看起来很完美,但在dreamweaver中看起来像这样postimg.org/image/d6gkhads3 ...
    猜你喜欢
    • 1970-01-01
    • 2018-05-24
    • 2021-10-18
    • 2021-09-16
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2022-01-18
    • 2012-01-27
    相关资源
    最近更新 更多