将标题居中对齐页面

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

Align titles in center of page

问题

在我的Angular项目中,我想先写title1,然后是第二个title2,旁边有2张图片,如下图所示:

将标题居中对齐页面

HTML:

<div class ="container">
    <div class="col-md-6 ">
        <p class="Title1">title1<p>
            <div class="imageContainer">
                <p class="Title2">title2</p>
                <img class="image2" src="assets/c.png" alt="Your Image">
                <img class="image" src="assets/Loader.gif" alt="Your Image">
            </div>  
    </div>
</div>

<div class ="container">
    <div class="col-md-6 ">
        <p class="Title1">title1<p>
            <div class="imageContainer">
                <p class="Title2">title2</p>
                <img class="image2" src="assets/c.png" alt="Your Image">
                <img class="image" src="assets/Loader.gif" alt="Your Image">
            </div>  
    </div>
</div>

CSS:

.container {
    display: flex;
    font-size: 60px; 
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
  }

.Title1{
    font-family: Lufga;
    color: black;
    font-size: 5 em;
    margin-bottom: 0;
   text-align: center;

}

.image{
  max-width: 25%;
  display: block; 
  margin-left: 10px; 
  margin-top: 0%;
  // margin-bottom: 10%; 
  // margin-left: 5%;
  
}
.image2{
    max-width: 2.5%;
    display: block; 
    //margin-left: 10px; 
    margin-bottom: 23%; 
       
  }

.imageContainer {
   // margin-bottom: 70%;
    margin-top: 0%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 24%;
  }
  
  .Title2 {
    font-family: Lufga;
    color: black;
    font-size: 23 em;
    text-align: center;
  }

问题是两个标题的字体大小相同,但通常情况下title2应该更大,此外,第一行和第二行之间有空白,而第二个图像不在中间,所以我使用了边距来使其居中。

英文:

In my Angular project, I want to write first title1 then a second title2 and next to it there is 2 images as the following image:

将标题居中对齐页面

HTML :

<div class ="container">
    <div class="col-md-6 ">
        <p class="Title1">title1<p>
            <div class="imageContainer">
                <p class="Title2">title2</p>
                <img class="image2" src="assets/c.png" alt="Your Image">
                <img class="image" src="assets/Loader.gif" alt="Your Image">
            </div>  
    </div>
</div>

<div class ="container">
    <div class="col-md-6 ">
        <p class="Title1">title1<p>
            <div class="imageContainer">
                <p class="Title2">title2</p>
                <img class="image2" src="assets/c.png" alt="Your Image">
                <img class="image" src="assets/Loader.gif" alt="Your Image">
            </div>  
    </div>
</div>

CSS :

.container {
    display: flex;
    font-size: 60px; 
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
  }

.Title1{
    font-family: Lufga;
    color: black;
    font-size: 5 em;
    margin-bottom: 0;
   text-align: center;

}

.image{
  max-width: 25%;
  display: block; 
  margin-left: 10px; 
  margin-top: 0%;
  // margin-bottom: 10%; 
  // margin-left: 5%;
  
}
.image2{
    max-width: 2.5%;
    display: block; 
    //margin-left: 10px; 
    margin-bottom: 23%; 
       
  }

.imageContainer {
   // margin-bottom: 70%;
    margin-top: 0%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 24%;
  }
  
  .Title2 {
    font-family: Lufga;
    color: black;
    font-size: 23 em;
    text-align: center;
  }

The problem is font size of two titles are the same but normally title2 should be bigger and also I have a space between the first row and the second one besides the second image is not on center so I used the margin to make it in center.

答案1

得分: 1

以下是修正后的内容:

  1. 你已经给 .container 添加了 display: flexflex-direction: column,但它只有一个子元素 .col-md-6,要么移除 .col-md-6,要么将 display: flex 添加到它。

  2. 对于 font-size,你已经给出了 5 em,移除这里的空格,应该像这样使用 5em

  3. 正确关闭 <p> 标签的方式是 </p>

  4. 为了保持内容在同一行显示,在 display: flex 中移除 flex-direction: column;,默认的 flex-directionrow,所以你不需要添加这个。

这是示例代码:

.container {
  display: flex;
  font-size: 60px;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.Title1 {
  font-family: Lufga;
  color: black;
  font-size: 5em;
  margin-bottom: 0;
  text-align: center;
}

.image {
  max-width: 25%;
  display: block;
  margin-left: 10px;
  margin-top: 0%;
}

.image2 {
  max-width: 2.5%;
  display: block;
  margin-bottom: 23%;
}

.imageContainer {
  margin-top: 0%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 24%;
}

.Title2 {
  font-family: Lufga;
  color: black;
  font-size: 3em;
  text-align: center;
}
<div class="container">
  <p class="Title1">title1</p>
  <div class="imageContainer">
    <p class="Title2">title2</p>
    <img class="image2" src="assets/c.png" alt="Your Image">
    <img class="image" src="assets/Loader.gif" alt="Your Image">
  </div>
</div>

<div class="container">
  <p class="Title1">title1</p>
  <div class="imageContainer">
    <p class="Title2">title2</p>
    <img class="image2" src="assets/c.png" alt="Your Image">
    <img class="image" src="assets/Loader.gif" alt="Your Image">
  </div>
</div>

根据需要修改 font-size 和间距。

英文:

You have some mistakes here:

  1. You have given display flex with flex-direction: column to .container, but it has only one child .col-md-6, here either remove .col-md-6 or give display flex to this.

  2. For font-size, you have given 5 em, remove space here, use like 5em

  3. close you &lt;p&gt; tag correctly with &lt;/p&gt;

  4. To keep content on same row, in display flex remove flex-direction: column;, default flex-direction is row, so you don't need to add this.

Here is the example:

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

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

.container {
  display: flex;
  font-size: 60px;
/*   flex-direction: column;
   */  align-items: center;
  justify-content: center;
  height: 100vh;
}

.Title1 {
  font-family: Lufga;
  color: black;
  font-size: 5em;
  margin-bottom: 0;
  text-align: center;

}

.image {
  max-width: 25%;
  display: block;
  margin-left: 10px;
  margin-top: 0%;
/*   // margin-bottom: 10%; 
  // margin-left: 5%;
   */
}

.image2 {
  max-width: 2.5%;
  display: block;
 /*  //margin-left: 10px;  */
  margin-bottom: 23%;

}

.imageContainer {
/*   // margin-bottom: 70%;
   */  margin-top: 0%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 24%;
}

.Title2 {
  font-family: Lufga;
  color: black;
  font-size: 3em;
  text-align: center;
}

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

&lt;div class=&quot;container&quot;&gt;
  &lt;p class=&quot;Title1&quot;&gt;title1&lt;/p&gt;
  &lt;div class=&quot;imageContainer&quot;&gt;
    &lt;p class=&quot;Title2&quot;&gt;title2&lt;/p&gt;
    &lt;img class=&quot;image2&quot; src=&quot;assets/c.png&quot; alt=&quot;Your Image&quot;&gt;
    &lt;img class=&quot;image&quot; src=&quot;assets/Loader.gif&quot; alt=&quot;Your Image&quot;&gt;
  &lt;/div&gt;

&lt;/div&gt;

&lt;div class=&quot;container&quot;&gt;
  &lt;p class=&quot;Title1&quot;&gt;title1&lt;/p&gt;
  &lt;div class=&quot;imageContainer&quot;&gt;
    &lt;p class=&quot;Title2&quot;&gt;title2&lt;/p&gt;
    &lt;img class=&quot;image2&quot; src=&quot;assets/c.png&quot; alt=&quot;Your Image&quot;&gt;
    &lt;img class=&quot;image&quot; src=&quot;assets/Loader.gif&quot; alt=&quot;Your Image&quot;&gt;
  &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

change font-size and spacings as per your need.

huangapple
  • 本文由 发表于 2023年5月17日 17:43:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76270694.html
匿名

发表评论

匿名网友

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

确定