首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在调整浏览器窗口大小时防止表和图像元素移动[REPOST]

如何在调整浏览器窗口大小时防止表和图像元素移动[REPOST]
EN

Stack Overflow用户
提问于 2017-03-21 14:20:13
回答 3查看 46关注 0票数 0

我之前发布了一个问题并编辑了它,但是编辑的版本没有显示正确的代码,所以我重新发布它。当我调整浏览器窗口的大小时,图像似乎从“框”中消失了,或者是容器。我是一个编码初学者,我知道如果我使用div而不是table更好,但这是为了实践目的(而且,我也需要它用于一个学校项目,我想这就是我想使用table元素的方式)。无论如何,请帮我弄清楚该怎么做/如何修复代码。

编辑:当我调整大小时,看起来像

代码语言:javascript
复制
.post {
  padding: 3em 3em 1em 3em;
  background: #ffffff;
  border: solid 1px rgba(160, 160, 160, 0.3);
  margin: 0 0 3em 0;
  position: relative;
}

.post>header {
  display: flex;
  border-bottom: solid 1px rgba(160, 160, 160, 0.3);
  left: -3em;
  margin: -3em 0 3em 0;
  position: relative;
  width: calc(100% + 6em);
}

.post>header .title {
  flex-grow: 1;
  flex: 1;
  padding: 3.75em 3em 3.3em 3em;
}

.post>header .title h2 {
  font-weight: 900;
  font-size: 1.5em;
  text-align: center;
}

.post>header .title> :last-child {
  margin-bottom: 0;
}

.image {
  width: 200px;
  height: 260px;
}

table {
  margin-left: auto;
  margin-right: auto;
}

td {
  padding: 10px;
}

.group {
  margin-left: auto;
  margin-right: auto;
}
代码语言:javascript
复制
<article class="post">
  <header>
    <div class="title">
      <h2><a href="#">Favorite Books</a></h2>
    </div>
  </header>


  <table>
    <tr>
      <td>
        <a href="#" target="_blank"><img src="#" alt="#" class="image" /> </a>
      </td>
      <td>
        <a href="#" target="_blank"><img src="#" alt="#" class="image" /> </a>
      </td>
      <td>
        <a href="#" target="_blank"><img src="#" alt="#" class="image" /> </a>
      </td>
  </tr>                          
  </table>
  
 </article>

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-03-21 14:30:51

你只需要加上

代码语言:javascript
复制
width: 700px;

去你的邮递班:

代码语言:javascript
复制
.post {
  padding: 3em 3em 1em 3em;
  background: #ffffff;
  border: solid 1px rgba(160, 160, 160, 0.3);
  margin: 0 0 3em 0;
  position: relative;
  width: 700px;
}

.post>header {
  display: flex;
  border-bottom: solid 1px rgba(160, 160, 160, 0.3);
  left: -3em;
  margin: -3em 0 3em 0;
  position: relative;
  width: calc(100% + 6em);
}

.post>header .title {
  flex-grow: 1;
  flex: 1;
  padding: 3.75em 3em 3.3em 3em;
}

.post>header .title h2 {
  font-weight: 900;
  font-size: 1.5em;
  text-align: center;
}

.post>header .title> :last-child {
  margin-bottom: 0;
}

.image {
  width: 200px;
  height: 260px;
}

table {
  margin-left: auto;
  margin-right: auto;
}

td {
  padding: 10px;
}

.group {
  margin-left: auto;
  margin-right: auto;
}
代码语言:javascript
复制
<article class="post">
  <header>
    <div class="title">
      <h2><a href="#">Favorite Books</a></h2>
    </div>
  </header>


  <table>
    <tr>
      <td>
        <a href="#" target="_blank"><img src="#" alt="#" class="image" /> </a>
      </td>
      <td>
        <a href="#" target="_blank"><img src="#" alt="#" class="image" /> </a>
      </td>
      <td>
        <a href="#" target="_blank"><img src="#" alt="#" class="image" /> </a>
      </td>
  </tr>                          
  </table>
  
 </article>

票数 0
EN

Stack Overflow用户

发布于 2017-03-21 14:27:48

只需更新图像css

代码语言:javascript
复制
.image {
  display: block;
height: auto;
max-width: 100%;
}
票数 0
EN

Stack Overflow用户

发布于 2017-03-21 14:37:09

正如您已经承认html结构不好(最好说应该避免),我仍然试图引入一种不同的方法。

css

代码语言:javascript
复制
td{
 /*append this style along yours*/
 height:200px;
 width:200px;
 display:block;
}

html

代码语言:javascript
复制
<td style="background-image: url('YOUR IMAGE URL');background-repeat: no-repeat;background-attachment: fixed;background-position: center;" onclick="javascript:window.location = 'YOUR HREF OF OLD A TAG'">
    &nbsp;
  </td>

您的图像URL是您的图像的绝对url,是旧的A标记,url的位置应该在单击时重定向

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42929745

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档