如何水平和垂直对齐图像和形式

发布于 2025-02-06 14:42:16 字数 2576 浏览 1 评论 0原文

我正在尝试复制Google主页,但是我有一些麻烦的中心在对齐图像和表单上,图像在顶部。我已经搜索了很多网站,但我并不真正了解它们。有人可以帮忙,还是给我一些网站或来源。 这是我的代码:

<!DOCTYPE html>
<html lang="en">

<head>
    <title>Search</title>
    <meta charset="utf-8">
    <!-- This link tag is used to link html file with css file -->
    <link rel="stylesheet" href="CSS/styles.css">
</head>

<body>
    <div class="center">
        <img class="item" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png">
        <form class="item" action="https://google.com/search">
            <input class="item" maxlength="2048" name="q" type="text" aria-autocomplete="both" aria-haspopup="false" autocapitalize="off" autocomplete="off" autocorrect="off" autofocus role="combobox" spellcheck="false" class="center">
            <input class="item" type="submit" value="Google Search" hidden>
        </form>
    </div>

    <!-- <h1><span class="googleText">G</span><span class="googleText">o</span><span class="googleText">o</span><span class="googleText">g</span><span class="googleText">a</span><span class="googleText">l</span></h1> -->

</body>

</html>

SCSS:

@font-face {
    font-family: 'Product Sans';
    font-style: normal;
    font-weight: 400;
    src: local('Open Sans'), local('OpenSans'), url(https://fonts.gstatic.com/s/productsans/v5/HYvgU2fE2nRJvZ5JFAumwegdm0LZdjqr5-oayXSOefg.woff2) format('woff2');
}

body {
    margin: 0 auto;
    font-family: Product Sans;
    font-size: 2vw;
}

.center {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.item {
    display: block;
}

$blue: #4285F4;
$red: #EA4335;
$yellow: #FBBC05;
$green: #34A853;
.googleText {
    align-items: center;
    font-size: 5vw;
    display: inline-block;
    text-align: center;
    &:nth-child(7n+1) {
        color: $blue;
    }
    &:nth-child(7n+2) {
        color: $red;
    }
    &:nth-child(7n+3) {
        color: $yellow;
    }
    &:nth-child(7n+4) {
        color: $blue;
    }
    &:nth-child(7n+5) {
        color: $green;
    }
    &:nth-child(7n+6) {
        color: $red;
    }
    &:nth-child(7n+7) {
        color: $yellow;
    }
}

主页:

I am trying to replicate the google homepage but I have some trouble centre aligning an image and a form, the image on the top. I have searched up a lot of websites but I don't really understand them. Can someone please help, or give me some websites or sources to look at.
Here's my code:

<!DOCTYPE html>
<html lang="en">

<head>
    <title>Search</title>
    <meta charset="utf-8">
    <!-- This link tag is used to link html file with css file -->
    <link rel="stylesheet" href="CSS/styles.css">
</head>

<body>
    <div class="center">
        <img class="item" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png">
        <form class="item" action="https://google.com/search">
            <input class="item" maxlength="2048" name="q" type="text" aria-autocomplete="both" aria-haspopup="false" autocapitalize="off" autocomplete="off" autocorrect="off" autofocus role="combobox" spellcheck="false" class="center">
            <input class="item" type="submit" value="Google Search" hidden>
        </form>
    </div>

    <!-- <h1><span class="googleText">G</span><span class="googleText">o</span><span class="googleText">o</span><span class="googleText">g</span><span class="googleText">a</span><span class="googleText">l</span></h1> -->

</body>

</html>

SCSS:

@font-face {
    font-family: 'Product Sans';
    font-style: normal;
    font-weight: 400;
    src: local('Open Sans'), local('OpenSans'), url(https://fonts.gstatic.com/s/productsans/v5/HYvgU2fE2nRJvZ5JFAumwegdm0LZdjqr5-oayXSOefg.woff2) format('woff2');
}

body {
    margin: 0 auto;
    font-family: Product Sans;
    font-size: 2vw;
}

.center {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.item {
    display: block;
}

$blue: #4285F4;
$red: #EA4335;
$yellow: #FBBC05;
$green: #34A853;
.googleText {
    align-items: center;
    font-size: 5vw;
    display: inline-block;
    text-align: center;
    &:nth-child(7n+1) {
        color: $blue;
    }
    &:nth-child(7n+2) {
        color: $red;
    }
    &:nth-child(7n+3) {
        color: $yellow;
    }
    &:nth-child(7n+4) {
        color: $blue;
    }
    &:nth-child(7n+5) {
        color: $green;
    }
    &:nth-child(7n+6) {
        color: $red;
    }
    &:nth-child(7n+7) {
        color: $yellow;
    }
}

The homepage:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白芷 2025-02-13 14:42:16

您好,您可以看到视频,此视频是使Google首页和其他链接在堆栈溢出相同的问题之前发言。希望它能帮助您

视频
[https://www.youtube.com/watch?v=zy1MyWudzSy] [1]

代码源
[https://stackoverflow.com/questions/17536429/re-creating-google-homepage] 1 [1]

Hello you can see the video, This video is make google front page and other link some one say before stack overflow same question. Hope it will help you

Video
[https://www.youtube.com/watch?v=ZY1MYwUDZsY][1]

Code Source
[https://stackoverflow.com/questions/17536429/re-creating-google-homepage][1]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文