如何将文本“ Github”移到“ John Doe”文本下?

时间:2019-03-03 16:46:42

标签: html css

Screenshot of my page.我想知道如何将文本“ Github”放置在“ John Doe”下。

    body {
      background-color: #000000;
      height: 700px;
    }
    h1 {
      font-family: 'Arvo', serif;
      font-style: normal;
      font-size: 50px;
      color: #ffffff;
    }
    h3 {
      font-family: 'Arvo', serif;
      font-style: normal;
      font-size: 12px;
      color: #ff384b;
     }
    br {
      font-family: 'Arvo', serif;
      font-style: normal;
      font-size: 12px;
      color: #ff384b;
    }
    .container {
      height: 100%;
      width: 100%;
      display: flex;
      position: sticky;
      align-items: center;
      justify-content: center;
    }
My HTML File:

    <!DOCTYPE html>
    <html>
    <head>
      <link href="https://fonts.googleapis.com/css?family=Arvo" rel="stylesheet">
      <link rel="stylesheet" type="text/css" href="stylesheet.css"> </link>
      <title> John Doe </title>
    </head>

    <body>
      <div class="container">
        <h1>John Doe</h1>
      </div>
      <div class="conatiner2">
        <h3> Github </h3>
      </div>
    </body>
    </html>

我将更详细地描述我的问题。 John Doe这个名字居中。我想在其下方直接输入文字“ Github”。但是我该如何实现呢?当我尝试执行此操作时,“ Github”居中,但在页面末尾。有谁可以帮助我吗?顺便说一句,我以前从未使用过CSS。

3 个答案:

答案 0 :(得分:0)

这是您想要的吗?我已将Github放在文本“ John Doe”下。

body {
      background-color: #000000;
      height: 700px;
    }
    h1 {
      font-family: 'Arvo', serif;
      font-style: normal;
      font-size: 50px;
      color: #ffffff;
      margin: 0;
      line-height: 48px;
    }
    h3 {
      font-family: 'Arvo', serif;
      font-style: normal;
      font-size: 12px;
      color: #ff384b;
      margin: 0;
     }
    br {
      font-family: 'Arvo', serif;
      font-style: normal;
      font-size: 12px;
      color: #ff384b;
    }
    .container {
      height: 100%;
      width: 100%;
      display: flex;
      position: sticky;
      align-items: center;
      justify-content: center;
      flex-direction: column;
    }
<!DOCTYPE html>
    <html>
    <head>
      <link href="https://fonts.googleapis.com/css?family=Arvo" rel="stylesheet">
      <link rel="stylesheet" type="text/css" href="stylesheet.css"> </link>
      <title> John Doe </title>
    </head>

    <body>
      <div class="container">
        <h1>John Doe</h1>
        <h3> Github </h3>
      </div>
    </body>
    </html>

还是类似的东西?

body {
      background-color: #000000;
      height: 700px;
    }
    h1 {
      font-family: 'Arvo', serif;
      font-style: normal;
      font-size: 50px;
      color: #ffffff;
    }
    h3 {
      font-family: 'Arvo', serif;
      font-style: normal;
      font-size: 12px;
      color: #ff384b;
     }
    br {
      font-family: 'Arvo', serif;
      font-style: normal;
      font-size: 12px;
      color: #ff384b;
    }
    .container {
      height: 100%;
      width: 100%;
      display: flex;
      position: sticky;
      align-items: center;
      justify-content: center;
      flex-direction: column;
    }
    .container2 {
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
     }
<!DOCTYPE html>
    <html>
    <head>
      <link href="https://fonts.googleapis.com/css?family=Arvo" rel="stylesheet">
      <link rel="stylesheet" type="text/css" href="stylesheet.css"> </link>
      <title> John Doe </title>
    </head>

    <body>
      <div class="container">
        <h1>John Doe</h1>
      </div>
      <div class="container2">
        <h3> Github </h3>
      </div>
    </body>
    </html>

答案 1 :(得分:0)

为Github使用与{John Doe相同的container类(类不是唯一的,可以在多个元素之间共享)

<div class="container">
  <h3> Github </h3>
</div>

还要从height: 100%;下的CSS文件中删除.container,以使文本更靠近在一起。两者都将基于您当前的设置位于页面的中心。

答案 2 :(得分:0)

一些更改...

1)将“ Github”文本移到与“ John Doe”相同的容器中,以便将它们一起格式化。

2)删除所有这些内容:
      显示:flex;
      位置:粘性;
      align-items:center;
      证明内容:中心;
      flex-direction:列;

3)替换为...
文本对齐中心://(将文本居中)
保证金:0自动; //(将内容居中显示在屏幕中间)

    body {
      background-color: #000000;
      height: 700px;
    }
    h1 {
      font-family: 'Arvo', serif;
      font-style: normal;
      font-size: 50px;
      color: #ffffff;
    }
    h3 {
      font-family: 'Arvo', serif;
      font-style: normal;
      font-size: 12px;
      color: #ff384b;
     }
    br {
      font-family: 'Arvo', serif;
      font-style: normal;
      font-size: 12px;
      color: #ff384b;
    }
    .container {
      height: 100%;
      width: 100%;
      text-align: center;
      margin: 0 auto;
    }
My HTML File:

    <!DOCTYPE html>
    <html>
    <head>
      <link href="https://fonts.googleapis.com/css?family=Arvo" rel="stylesheet">
      <link rel="stylesheet" type="text/css" href="stylesheet.css"> </link>
      <title> John Doe </title>
    </head>

    <body>
      <div class="container">
        <h1>John Doe</h1>
        <h3>Github</h3>
      </div>
    </body>
    </html>