How do you place two images together, with text, with both at center. I understand that you can change element size to make elements in center

huangapple go评论49阅读模式
英文:

How do you place two images together, with text, with both at center. I understand that you can change element size to make elements in center

问题

我试图将两张图片并排放置,并附上它们的描述。以下是我的代码。

我打算将两张图片并排放置,并伴随它们的文本。我尝试分割div元素,但问题是一个文本在另一个文本下面,而不是在旁边。文本需要在图像的右侧,第二张图像需要在第一个文本的右侧。

<div id="sheets">
  <a href="Spreadsheet.html"><img src="https://upload.wikimedia.org/wikipedia/commons/d/dd/Flag_of_the_Roman_Empire.png" height="200" width="350"></a>
  <h1>古罗马</h1>
  <p>古罗马是一个伟大的文明,与古希腊一起,为现代世界的许多事物做出了贡献,如建筑、数字、字母和政府。</p>
</div><br><br><br><br><br><br><br><br>

<div id="docs">
  <img src="https://upload.wikimedia.org/wikipedia/commons/e/ef/Pantheon_Rom_1_cropped.jpg" height="125" width="125">
  <p>古罗马的一个著名建筑物。由于自7世纪以来一直在活跃使用,所以它保存得很好。万神殿有一个圆顶。</p>
</div>
<div id="docs">
  <img src="https://upload.wikimedia.org/wikipedia/commons/d/d8/Colosseum_in_Rome-April_2007-1-_copie_2B.jpg" height="125" width="125">
  <p>另一个著名的建筑物。用于娱乐大规模人群。大多数人在角斗士比赛中没有丧命。斗兽场有很多拱门。</p>
</div>
英文:

I'm trying to place two images side by side with their descriptions. Here is my code.

I intend to place two images side by side with their text. I tried to split div elements but the problem was that one piece of text was under the other, not next to the other. The text needs to be to the right of the image and the second image needs to be to the right of the first text.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

#sheets {
  width: 50%;
  margin: auto;
}

#docs {
  width: 25%;
  margin: auto;
}

img {
  float: left;
  margin-right: 10px;
}

<!-- language: lang-html -->

&lt;div id=&quot;sheets&quot;&gt;
  &lt;a href=&quot;Spreadsheet.html&quot;&gt;&lt;img src=&quot;https://upload.wikimedia.org/wikipedia/commons/d/dd/Flag_of_the_Roman_Empire.png&quot; height=&quot;200&quot; width=&quot;350&quot;&gt;&lt;/a&gt;
  &lt;h1&gt;Ancient Rome&lt;/h1&gt;
  &lt;p&gt;Ancient Rome was a great civilization, that along with Ancient Greece, contributed to many things in the modern world, like architecture, numbers, letters, and government.&lt;/p&gt;
&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
&lt;div id=&quot;docs&quot;&gt;
  &lt;img src=&quot;https://upload.wikimedia.org/wikipedia/commons/e/ef/Pantheon_Rom_1_cropped.jpg&quot; height=&quot;125&quot; width=&quot;125&quot;&gt;
  &lt;p&gt;One famous building of Ancient Rome. It&#39;s in good condition because the building has been in active use since the 7th century. The Pantheon has a dome.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&quot;docs&quot;&gt;
  &lt;img src=&quot;https://upload.wikimedia.org/wikipedia/commons/d/d8/Colosseum_in_Rome-April_2007-1-_copie_2B.jpg&quot; height=&quot;125&quot; width=&quot;125&quot;&gt;
  &lt;p&gt;Another famous building. Was used for entertainment of huge crowds. Most people did not die in gladiator matches. The Colosseum has a lot of arches.&lt;/p&gt;
&lt;/div&gt;

<!-- end snippet -->

答案1

得分: 1

你的HTML中有一个错误。像 "docs" 这样的id需要是唯一的。我已经将其更改为类(class)。查看flexbox来将你的图像并排排列。

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->
#sheets {
  width: 50%;
  margin: auto;
}

.docs {
  width: 25%;
}

img {
  float: left;
  margin-right: 10px;
}

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

<!-- language: lang-html -->
<html>

<body>
  <div id="sheets">
    <a href="Spreadsheet.html"><img src="https://upload.wikimedia.org/wikipedia/commons/d/dd/Flag_of_the_Roman_Empire.png" height="200" width="350"></a>
    <h1>Ancient Rome</h1>
    <p>Ancient Rome was a great civilization, that along with Ancient Greece, contributed to many things in the modern world, like architecture, numbers, letters, and government.</p>
  </div><br><br><br><br><br><br><br><br><br>
  <div id='container'>
    <div class="docs">
      <img src="https://upload.wikimedia.org/wikipedia/commons/e/ef/Pantheon_Rom_1_cropped.jpg" height="125" width="125">
      <p>One famous building of Ancient Rome. It's in good condition because the building has been in active use since the 7th century. The Pantheon has a dome.</p>
    </div>
    <div class="docs">
      <img src="https://upload.wikimedia.org/wikipedia/commons/d/d8/Colosseum_in_Rome-April_2007-1-_copie_2B.jpg" height="125" width="125">
      <p>Another famous building. Was used for entertainment of huge crowds. Most people did not die in gladiator matches. The Colosseum has a lot of arches.</p>
    </div>
  </div>

</body>

</html>

<!-- end snippet -->
英文:

you have a mistake in your html. id's like "docs" need to be unique. I changed that to a class. Look into flexbox to arrange your images side by side.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

#sheets {
      width: 50%;
      margin: auto;
    }
    
    .docs {
      width: 25%;      
      
    }
    
    img {
      float: left;
      margin-right: 10px;
    }
    
    #container{
    display:flex;
    justify-Content:center;
    }

<!-- language: lang-html -->

&lt;html&gt;

&lt;body&gt;
  &lt;div id=&quot;sheets&quot;&gt;
    &lt;a href=&quot;Spreadsheet.html&quot;&gt;&lt;img src=&quot;https://upload.wikimedia.org/wikipedia/commons/d/dd/Flag_of_the_Roman_Empire.png&quot; height=&quot;200&quot; width=&quot;350&quot;&gt;&lt;/a&gt;
    &lt;h1&gt;Ancient Rome&lt;/h1&gt;
    &lt;p&gt;Ancient Rome was a great civilization, that along with Ancient Greece, contributed to many things in the modern world, like architecture, numbers, letters, and government.&lt;/p&gt;
  &lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
  &lt;div id=&#39;container&#39;&gt;
  &lt;div class=&quot;docs&quot;&gt;
    &lt;img src=&quot;https://upload.wikimedia.org/wikipedia/commons/e/ef/Pantheon_Rom_1_cropped.jpg&quot; height=&quot;125&quot; width=&quot;125&quot;&gt;
    &lt;p&gt;One famous building of Ancient Rome. It&#39;s in good condition because the building has been in active use since the 7th century. The Pantheon has a dome.&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class = &quot;docs&quot;&gt;
    &lt;img src=&quot;https://upload.wikimedia.org/wikipedia/commons/d/d8/Colosseum_in_Rome-April_2007-1-_copie_2B.jpg&quot; height=&quot;125&quot; width=&quot;125&quot;&gt;
    &lt;p&gt;Another famous building. Was used for entertainment of huge crowds. Most people did not die in gladiator matches. The Colosseum has a lot of arches.&lt;/p&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  
&lt;/body&gt;

&lt;/html&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月11日 02:24:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76221558.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定