英文:
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
以下是修正后的内容:
-
你已经给
.container
添加了display: flex
和flex-direction: column
,但它只有一个子元素.col-md-6
,要么移除.col-md-6
,要么将display: flex
添加到它。 -
对于
font-size
,你已经给出了5 em
,移除这里的空格,应该像这样使用5em
。 -
正确关闭
<p>
标签的方式是</p>
。 -
为了保持内容在同一行显示,在
display: flex
中移除flex-direction: column;
,默认的flex-direction
是row
,所以你不需要添加这个。
这是示例代码:
.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:
-
You have given display
flex
withflex-direction: column
to.container
, but it has only one child.col-md-6
, here either remove.col-md-6
or give displayflex
to this. -
For
font-size
, you have given5 em
, remove space here, use like5em
-
close you
<p>
tag correctly with</p>
-
To keep content on same row, in display
flex
removeflex-direction: column;
, defaultflex-direction
isrow
, 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 -->
<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>
<!-- end snippet -->
change font-size
and spacings as per your need.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论