如何使用CSS3并排放置HTML元素

安德烈亚

我刚开始编程,正在尝试基于运球设计创建一个简单的网站。

我试图将图像和文本并排放置在一个节中,以便在调整图像和文本的大小时它们彼此位于彼此下方,但我听不懂,您能帮我吗?

目前,我的网站如下所示:

https://imgur.com/d0bEVks

我想像这样的运球设计离开

https://imgur.com/8ZlFaVm

我的HTML代码:

<!DOCTYPE html>
<html lang="en">
<head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link rel="stylesheet" href="./new.css">
      <link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,300;0,400;0,700;1,300&display=swap" rel="stylesheet">
      <title>Document</title>
</head>
<body>
      <header>
            <a href="#" class="brand">MYBRAND</a>
            <ul>
                  <li><a href="#">Home</a></li>
                  <li><a href="#">Tasks</a></li>
                  <li><a href="#">Services</a></li>
                  <li><a href="#">School</a></li>
                  <li><a href="#">Contact</a></li>
            </ul>
      </header>
      <section class="banner">
            <div class="container">
                  <div class="item">
                        <h1>Create, <br>and Collect Data</h1>
                        <div class="text">Change your mind, <br> extract and collect any data for you business.</div>
                        <button href="#" class="btn-contact btn-style-one">Talk to me</button>
                  </div>
                  <div class="item">
                        <figure class="image">
                              <img src="1.png" alt="">
                        </figure>
                  </div>
            </div>
      </section>

      <script type="text/javascript">
            window.addEventListener("scroll", function() {
                  let header = document.querySelector("header");
                  header.classList.toggle("sticky", window.scrollY > 390);
            })

      </script>
</body>
</html>

我的CSS代码:

* {
  outline: none;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Poppins", sans-serif;
}

body {
  min-height: 200vh;
  background-color: black;
}

header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: 0.6s;
  padding: 40px 100px;
  z-index: 100000;
}

header .brand {
  position: relative;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  font-size: 2em;
  text-transform: uppercase;
  letter-spacing: 2px;
  transition: 0.6s;
}

header.sticky {
  padding: 5px 100px;
  background-color: #fff;
}

header.sticky .brand,
header.sticky ul li a {
  color: #000;
}

header ul {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

header ul li {
  position: relative;
  list-style: none;
}

header ul li a {
  position: relative;
  margin: 0 15px;
  text-decoration: none;
  color: #fff;
  letter-spacing: 2px;
  font-weight: 500px;
  transition: 0.5s;
}

.banner {
  position: relative;
  width: 100%;
  height: 100vh;
  background: url(13.png);
  background-size: cover;
  background-repeat: no-repeat;
}

.container {
    display: flex;
    width: 100%;
    margin: 0 auto;
    flex-wrap: wrap;
}

.item {
    flex: 1;
    margin: 5px;
    padding: 0 10px;
    text-align: center;
}

btn-contact {
    display: inline-block;
}

.btn-style-one {
    position: relative;
    text-decoration: none;
    line-height: 24px;
    color: #ffffff;
    font-size: 15px;
    cursor: pointer;
    font-weight: 600;
    border-radius: 50px;
    border-style: none;
    background-color: #ff8048;
    text-transform: capitalize;
    padding: 16px 32px 16px 32px;
    font-family: "Poppins", sans-serif;
    box-shadow: 0px 0px 20px rgba(23, 23, 23, 0.15);
    background-image: -webkit-gradient(
      linear,
      left top,
      right top,
      color-stop(0, #f434a1),
      color-stop(100, #ff8442)
    );
    background-image: -webkit-linear-gradient(left, #f434a1 0%, #ff8442 100%);
    background-image: linear-gradient(to right, #f434a1 0%, #ff8442 100%);
  }

这些是我使用的图像:

背景:https : //imgur.com/mTHpmbP资讯主页:https : //imgur.com/5Zvfdoe

拉菲·谢克(Rafee Shaik)

添加height: 100%.container,改变CSS。

* {
    outline: none;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Poppins", sans-serif;
}

body {
    min-height: 200vh;
    background-color: black;
}

header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: 0.6s;
    padding: 40px 100px;
    z-index: 100000;
}

header .brand {
    position: relative;
    font-weight: 700;
    color: #fff;
    text-decoration: none;
    font-size: 2em;
    text-transform: uppercase;
    letter-spacing: 2px;
    transition: 0.6s;
}

header.sticky {
    padding: 5px 100px;
    background-color: #fff;
}

header.sticky .brand,
header.sticky ul li a {
    color: #000;
}

header ul {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

header ul li {
    position: relative;
    list-style: none;
}

header ul li a {
    position: relative;
    margin: 0 15px;
    text-decoration: none;
    color: #fff;
    letter-spacing: 2px;
    font-weight: 500px;
    transition: 0.5s;
}

.banner {
    position: relative;
    width: 100%;
    height: 100vh;
    background: url('https://i.imgur.com/mTHpmbP.png');
    background-size: cover;
    background-repeat: no-repeat;
}

.container {
    display: flex;
    width: 100%;
    height: 100%;
    margin: 0 auto;
    flex-wrap: wrap;
}

.item {
    flex: 1;
    margin: auto;
    padding: 0 10px;
}

.item-text {
    width: max-content;
    margin: auto;
}

.item-text h1 {
    color: #fff;
    font-size: 40px;
    line-height: 1.2;
}

.item-text .text {
    color: #fff;
    margin: 10px 0;
    font-size: 14px;
}

.btn-contact {
    display: inline-block;
}

.btn-style-one {
    position: relative;
    text-decoration: none;
    line-height: 24px;
    color: #ffffff;
    font-size: 15px;
    cursor: pointer;
    font-weight: 600;
    border-radius: 50px;
    border-style: none;
    background-color: #ff8048;
    text-transform: capitalize;
    padding: 16px 32px 16px 32px;
    font-family: "Poppins", sans-serif;
    box-shadow: 0px 0px 20px rgba(23, 23, 23, 0.15);
    background-image: -webkit-gradient(
        linear,
        left top,
        right top,
        color-stop(0, #f434a1),
        color-stop(100, #ff8442)
        );
    background-image: -webkit-linear-gradient(left, #f434a1 0%, #ff8442 100%);
    background-image: linear-gradient(to right, #f434a1 0%, #ff8442 100%);
}

@media only screen and (max-width: 767px) {
    .banner {
        padding-top: 130px;
    }
    header {
        padding: 20px;
        flex-direction: column;
    }
    header ul li a {
        margin: 0 10px;
        letter-spacing: 0;
    }
    .container {
        flex-direction: column;
        flex-wrap: unset;
    }
    .item {
        margin: 0;
        padding: 0 30px;
    }
    .item img {
        max-width: 100%;
    }
}
<!DOCTYPE html>
<html lang="en">
<head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link rel="stylesheet" href="./new.css">
      <link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,300;0,400;0,700;1,300&display=swap" rel="stylesheet">
      <title>Document</title>
</head>
<body>
      <header>
            <a href="#" class="brand">MYBRAND</a>
            <ul>
                  <li><a href="#">Home</a></li>
                  <li><a href="#">Tasks</a></li>
                  <li><a href="#">Services</a></li>
                  <li><a href="#">School</a></li>
                  <li><a href="#">Contact</a></li>
            </ul>
      </header>
      <section class="banner">
            <div class="container">
                  <div class="item">
                        <div class="item-text">
            <h1>Create, <br>and Collect Data</h1>
                        <div class="text">Change your mind, <br> extract and collect any data for you business.</div>
                        <button class="btn-contact btn-style-one">Talk to me</button>
            </div>
                  </div>
                  <div class="item">
                        <figure class="image">
                              <img src="https://i.imgur.com/5Zvfdoe.png" alt="">
                        </figure>
                  </div>
            </div>
      </section>

      
</body>
</html>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章