放置一个页眉、段落和一张图片并排。

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

put a header, paragraph and an image next to each other

问题

我正在尝试将一个带有H3标题的文本与图像并排放置。我已经成功将图像和文本放在一起,问题是我无法将我的H3放在文本的顶部。

这是我希望它看起来的样子,H3作为标题:
放置一个页眉、段落和一张图片并排。

以下是您提供的HTML和CSS代码片段的翻译部分:

<div id="box">
    <h3>lorem ipsum</h3>
    <p>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
    </p>

    <img width="300" src="https://blog-media.byjusfutureschool.com/bfs-blog/2022/08/18080659/Article-Page-61.png" />
</div>
#box {
    display: flex;
    align-items: center;
    width: 950px;
    margin:auto;
    margin-top: 30px;
}

#box p {
    margin-right: 1em;
}

请注意,这只是代码的翻译部分,没有其他额外内容。

英文:

i am trying to put some text with h3 as a title parallel to an image
i managed to get the image and the text to do that, the problem is i cant get my h3 on top of the text

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

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

#box {
    display: flex;
    align-items: center;
    width: 950px;
    margin:auto;
    margin-top: 30px;
}

#box p {
    margin-right: 1em;
}

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

            &lt;div id=&quot;box&quot;&gt;
                &lt;h3&gt;lorem ipsum&lt;/h3&gt;
                &lt;p&gt;
                    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
                &lt;/p&gt;
        
                &lt;img width=&quot;300&quot; src=&quot;https://blog-media.byjusfutureschool.com/bfs-blog/2022/08/18080659/Article-Page-61.png&quot; /&gt;
            &lt;/div&gt;

<!-- end snippet -->

This is what i want it to essentialy look like with the h3 as title
放置一个页眉、段落和一张图片并排。

答案1

得分: 1

/*仅供演示*/
body{
  margin-left: 22em;
}

.parent-box{
    display: flex;
    flex-direction: column;
    align-items: center;
}

.left {
  text-align: center;
}

.box {
    display: flex;
    align-items: center;
    width: 950px;
    background: black;
    color: white;
}

.box > * {
  margin: 1em;
}
<div class="parent-box">
  <div class="box">
    <div class="left">
      <h3>lorem ipsum</h3>
      <p>
        强大、可扩展和功能丰富的前端工具包。使用Sass构建和自定义,利用预构建的网格系统和组件,使用强大的JavaScript插件将项目带到生活中。
        通过npm、RubyGems、Composer或Meteor安装Bootstrap的源Sass和JavaScript文件。包管理安装不包括文档或完整的构建脚本。您还可以使用我们的npm模板存储库通过npm快速生成Bootstrap项目。当您只需要包含Bootstrap的编译CSS或JS时,可以使用jsDelivr。通过我们的简单快速启动查看它的实际效果,或浏览示例以快速启动下一个项目。您还可以选择单独包含Popper和我们的JS。
      </p>
    </div>
    
    <img width="300" src="https://blog-media.byjusfutureschool.com/bfs-blog/2022/08/18080659/Article-Page-61.png" />
  </div>
</div>
英文:

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

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

/*only for demonstration*/
body{
  margin-left : 22em;
}

.parent-box{
    display : flex;
    flex-direction : column;
    align-items : center;
}

.left {
  text-align:center;
}

.box {
    display: flex;
    align-items: center;
    width: 950px;
    background : black;
    color : white;
}

.box &gt; * {
  margin : 1em;
}

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

&lt;div class=&quot;parent-box&quot;&gt;
  &lt;div class=&quot;box&quot;&gt;
  &lt;div class=&quot;left&quot;&gt;
    &lt;h3&gt;lorem ipsum&lt;/h3&gt;
     &lt;p&gt;
       Powerful, extensible, and feature-packed frontend toolkit. Build and customize with Sass, utilize prebuilt grid system and components, and bring projects to life with powerful JavaScript plugins.
Install Bootstrap’s source Sass and JavaScript files via npm, RubyGems, Composer, or Meteor. Package managed installs don’t include documentation or our full build scripts. You can also use our npm template repo to quickly generate a Bootstrap project via npm.When you only need to include Bootstrap’s compiled CSS or JS, you can use jsDelivr. See it in action with our simple quick start, or browse the examples to jumpstart your next project. You can also choose to include Popper and our JS separately.
      &lt;/p&gt;
      
    &lt;/div&gt;
        
      &lt;img width=&quot;300&quot; src=&quot;https://blog-media.byjusfutureschool.com/bfs-blog/2022/08/18080659/Article-Page-61.png&quot; /&gt;
  &lt;/div&gt;
               
&lt;/div&gt;

<!-- end snippet -->

答案2

得分: 1

以下是翻译好的内容,代码部分未翻译:

这应该可以实现:

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

<!-- language: lang-css -->
body {
  background: black;
  color: white;
}

.box-outer {
  display: flex;
  flex-flow: row nowrap;
  align-items: center;
  width: 950px;
  margin: auto;
  margin-top: 30px;
}

.box-inner {
  display: flex;
  flex-flow: column nowrap;
  align-items: center;
  justify-content: center;
}

.box-inner__body {
  margin-right: 1em;
  text-align: center;
}

<!-- language: lang-html -->
<div class="box-outer">
  <div class="box-inner">
    <h3 class="box-inner__title">lorem ipsum</h3>
    <p class="box-inner__body">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
      in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
    </p>
  </div>
  <img width="300" src="https://blog-media.byjusfutureschool.com/bfs-blog/2022/08/18080659/Article-Page-61.png" />
</div>

<!-- end snippet -->

希望这对你有所帮助。

英文:

This should do the trick:

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

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

body {
  background: black;
  color: white;
}

.box-outer {
  display: flex;
  flex-flow: row nowrap;
  align-items: center;
  width: 950px;
  margin: auto;
  margin-top: 30px;
}

.box-inner {
  display: flex;
  flex-flow: column nowrap;
  align-items: center;
  justify-content: center;
}

.box-inner__body {
  margin-right: 1em;
  text-align: center;
}

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

&lt;div class=&quot;box-outer&quot;&gt;
  &lt;div class=&quot;box-inner&quot;&gt;
    &lt;h3 class=&quot;box-inner__title&quot;&gt;lorem ipsum&lt;/h3&gt;
    &lt;p class=&quot;box-inner__body&quot;&gt;
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
      in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
    &lt;/p&gt;
  &lt;/div&gt;
  &lt;img width=&quot;300&quot; src=&quot;https://blog-media.byjusfutureschool.com/bfs-blog/2022/08/18080659/Article-Page-61.png&quot; /&gt;
&lt;/div&gt;

<!-- end snippet -->

答案3

得分: 0

你可以简单地将你的文本内容包裹在一个额外的div中:

<div id="box">
  <div>
    <h3>lorem ipsum</h3>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
      in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
    </p>
  </div>

  <img width="300" src="https://blog-media.byjusfutureschool.com/bfs-blog/2022/08/18080659/Article-Page-61.png" />
</div>
英文:

You can simply wrap your text content in an additional div:

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

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

#box {
  display: flex;
  align-items: center;
  width: 950px;
  margin: auto;
  margin-top: 30px;
  text-align: center; /* center the inner text */
}

#box p {
  margin-right: 1em;
}

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

&lt;div id=&quot;box&quot;&gt;
  &lt;div&gt;
    &lt;h3&gt;lorem ipsum&lt;/h3&gt;
    &lt;p&gt;
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
      in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
    &lt;/p&gt;
  &lt;/div&gt;

  &lt;img width=&quot;300&quot; src=&quot;https://blog-media.byjusfutureschool.com/bfs-blog/2022/08/18080659/Article-Page-61.png&quot; /&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年3月4日 06:34:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75632401.html
匿名

发表评论

匿名网友

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

确定