【问题标题】:Align multiple headings above multiple iframes在多个 iframe 上方对齐多个标题
【发布时间】:2021-12-29 14:22:14
【问题描述】:

我总共有六个iframes,想在它们上面添加三个标题。

html:

<!DOCTYPE HTML>
<html lang="en">
    
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <title>Title xxx</title>
    
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <meta http-equiv="Content-Language" content="en" />
    
    <meta name="keywords" content="xxxx" />
    <meta name="description" name="description" content="xxxx" />
    
    <meta http-equiv="pragma" content="public" />
    <meta http-equiv="cache-control" content="public" />
    
    <meta http-equiv="identifier-url" name="Identifier-URL" content="" />
    <meta http-equiv="revisit-after" name="Revisit-after" content="7 days" />
    <meta http-equiv="robots" name="Robots" content="all" />
    <meta name="robots" content="INDEX|FOLLOW" />
    
    <meta name="Author" content="xxx xxx, xxx Team" />
    <link rel="stylesheet" type="text/css" href="style/main.css" />
</head>

<body>
    <div id="container">
        <section id="a_logo">
            <img src="images/a_logo.png">
        </section>
        <section id="b_logo">
            <img src="images/b_logo.png">
        </section>
        <!-- content -->
        <section id="content">
            <h1>Linux UF Packages</h1>
                <a href="packages/linux/xxx_PROD_nonDMZ.tgz">xxx Linux non DMZ PROD (x64)</a></br>
                <a href="packages/linux/xxx_PROD_DMZ.tgz">xxx Linux DMZ PROD (x64)</a></br>
                <a href="packages/linux/xxx_AB_nonDMZ.tgz">xxx Linux non DMZ AB (x64)</a></br>
                <a href="packages/linux/xxx_AB_DMZ.tgz">xxx Linux DMZ AB (x64)</a></br>
                <a href="packages/linux/xxx_EW_nonDMZ.tgz">xxx Linux non DMZ EW (x64)</a></br>
                <a href="packages/linux/xxx_EW_DMZ.tgz">xxx Linux DMZ EW (x64)</a></br>
                <a href="packages/linux/xxx.docx">Installation Guide </a>
            <h1>Windows UF Packages</h1>
                <a href="packages/windows/xxx_x64.zip">xxx Windows PROD, AB, EW (x64)</a></br>
                <a href="packages/windows/xxx.docx">Installation Guide for Windows</a>
        </section>
        <section id="stats">
        <div>
            <h2>header</h2>
            <iframe height="160" width="480" frameborder="0" src="https://www.w3schools.com"></iframe>
            <iframe height="160" width="480" frameborder="0" src="https://www.w3schools.com"></iframe>
        </div>
        <div>
            <h2>header2</h2>
            <iframe height="160" width="480" frameborder="0" src="https://www.w3schools.com"></iframe>
            <iframe height="160" width="480" frameborder="0" src="https://www.w3schools.com"></iframe>
        </div>
        <div>
            <h2>header3</h2>
            <iframe height="160" width="480" frameborder="0" src="https://www.w3schools.com"></iframe>
            <iframe height="160" width="480" frameborder="0" src="https://www.w3schools.com"></iframe>
        </div>
        </section>
        <footer>
            <p>Created and managed by <a href="mailto:xxx&subject=xxx">xxx Team</a> 2021 | Last update: 2021-12-28</p>
        </footer>
    </div>
</body>
</html>

css:

* {
  padding: 0;
  margin: 0;
}

html {
  width: 100%;
  height: 100%;
}
body {
  margin: 50px;
  font-family: Trebuchet, Verdana, Arial, Helvetica, Sans-serif;
  font-size: 14px;
  text-decoration: none;
  line-height: 1.5;
  font-weight: 400;
  color: #434343;
  background: #fff;
}

.container {
  margin: 0 auto;
}

#a_logo {
  float: left;
  display: block;
  max-width: 200px;
  max-height: 100px;
  width: auto;
  height: auto;
}
#b_logo {
  float: left;
  display: block;
  padding: 0 0 0 600px;
  max-width: 200px;
  max-height: 100px;
  width: auto;
  height: auto;
}

#content {
  float: left;
  font-size: 20px;
  text-align: left;
  width: 100%;
  margin: 25px 50px 25px;
  padding: 50px 0;
  background-image: url("../images/");
  background-position: left;
  background-repeat: no-repeat;
}
#content h1 {
  clear: both;
  color: #000;
  padding: 10px 0 10px;
  margin-top: 50px;
}
#content a {
  color: #6e6e6e;
}
#content a:hover {
  color: #b18904;
}
#content a:visited {
  color: #848484;
}

#stats iframe {
  display: inline-block;
}

footer {
  clear: both;
  text-align: left;
  color: #000;
  margin: 0 50px;
  padding: 10px 0 10px;
}
footer p a {
  color: #6e6e6e;
}
footer p a:hover {
  color: #b18904;
}
footer p a:visited {
  color: #848484;
}

结果应该是这样的:

header          header2        header3
iframe(prod1)   iframe(uat1)   iframe(dev1)
iframe(prod2)   iframe(uat2)   iframe(dev2)

我已经尝试了几种方法,但要么破坏了 iframe 的垂直结构,要么标题位置不正确。

【问题讨论】:

  • 最后一组&lt;iframe&gt;s 和3 个&lt;header&gt;s 没有发布。
  • 我没有添加标题,因为我没有成功。我总共有 6 个 iframe,显示在我的初始帖子中。

标签: html css iframe


【解决方案1】:

试试这个...

#stats {
  display: flex;
  justify-content: center;
}

#stats iframe {
  margin: 5px
}
<section id="stats">
  <div>
    <h2>header</h2>
    <iframe height="160" width="480" frameborder="0" src="https://www.w3schools.com"></iframe>
    <iframe height="160" width="480" frameborder="0" src="https://www.w3schools.com"></iframe>
  </div>
  <div>
    <h2>header2</h2>
    <iframe height="160" width="480" frameborder="0" src="https://www.w3schools.com"></iframe>
    <iframe height="160" width="480" frameborder="0" src="https://www.w3schools.com"></iframe>
  </div>
  <div>
    <h2>header3</h2>
    <iframe height="160" width="480" frameborder="0" src="https://www.w3schools.com"></iframe>
    <iframe height="160" width="480" frameborder="0" src="https://www.w3schools.com"></iframe>
  </div>
</section>

【讨论】:

  • 对齐内容:居中;如果您不希望它们散布在整个页面上,可以将其删除
  • 我实施了您的建议,iframe 现在垂直对齐,第一个标题位于页面顶部和中心。
  • 你有你尝试过的代码示例吗?当您运行上面的代码 sn-p 时,它可以工作,所以我认为您的 CSS 在某处覆盖了某些东西。
  • 我在最初的帖子中添加了整个 html 文件。
【解决方案2】:

你想要的结构是一个表格——所以你可以使用:

  • &lt;table&gt;     或display: table
  • &lt;thead&gt;     或display: table-header-group
  • &lt;tbody&gt;     或display: table-row-group
  • &lt;tr&gt;           或display: table-row
  • &lt;th&gt;,&lt;td&gt;display: table-cell

下面的例子使用display CSS property

#stats {
  display: table;
  table-layout: fixed;
}

.head {
  display: table-header-group
}

.body {
  display: table-row-group
}

.row {
  display: table-row
}

h2,
.row div {
  display: table-cell
}

iframe {
  border: 0
}

.r1 iframe {
  height: 160px;
  width: 480px;
}

.r2 iframe {
  height: 340px;
  width: 480px;
}

.A {
  outline: 3px dashed tomato;
}

.B {
  outline: 3px dashed lime;
}

.C {
  outline: 3px dashed cyan;
}

.D {
  outline: 3px dashed violet;
}

.E {
  outline: 3px dashed goldenrod;
}

.F {
  outline: 3px dashed navy;
}
<section id="stats">
  <header class='head'>
    <h2>Header1</h2>
    <h2>Header2</h2>
    <h2>Header3</h2>
  </header>
  <section class='body'>
    <div class='row r1'>
      <div>
        <iframe class='A' src="about:blank"></iframe>
      </div>
      <div>
        <iframe class='B' src="about:blank"></iframe>
      </div>
      <div>
        <iframe class='C' src="about:blank"></iframe>
      </div>
    </div>
    <div class='row r2'>
      <div>
        <iframe class='D' src="about:blank"></iframe>
      </div>
      <div>
        <iframe class='E' src="about:blank"></iframe>
      </div>
      <div>
        <iframe class='F' src="about:blank"></iframe>
      </div>
    </div>
  </section>
</section>

【讨论】:

  • 不幸的是,三个标题集中在页面顶部,而 iframe 只是垂直排序。
  • 是否意味着文本居中?这很容易解决......好吧,它已经修复了。
  • 是的,文本居中并位于页面顶部,并且 iframe 是垂直顺序。
猜你喜欢
  • 2021-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多