我对CSS仍然非常陌生,我只是试图理解Flex的基本概念,所以到目前为止,我的代码可能有很多错误,但我愿意学习!!我现在是自学成才的,所以我来这里:)

就像我说的,我还是个初学者,所以请教我!我正在try 将此内容放在侧边栏旁边? 我知道网格很可能是最好的解决方案,但是在我使用网格之前,我想先用FLEX来做这件事,然后再深入研究这个概念,因为它看起来有点复杂!

以下代码:

html,
body {
  background-color: rgb(65, 75, 113);
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

@font-face {
  font-family: "Corben";
  src: url(Corben/Corben-Regular.ttf);
}

@font-face {
  font-family: "Archivo";
  src: url(Archivo_Black/ArchivoBlack-Regular.ttf);
}

@font-face {
  font-family: "Outfit";
  src: url(Outfit/static/Outfit-Regular.ttf);
}

@font-face {
  font-family: "Outfit-black";
  src: url(Outfit/static/Outfit-Black.ttf);
}

@font-face {
  font-family: "Cormorant-semibold";
  src: url(Cormorant/static/Cormorant-SemiBold.ttf);
}

@font-face {
  font-family: "Cormorant";
  src: url(Cormorant/static/Cormorant-Regular.ttf);
}

.container {
  outline: white 1px solid;
  height: 100vh;
  width: 100vw;
  /* get rid of this... or play around w it */
  display: flex;
  flex-direction: column;
}

.top-header {
  /* outline: 1px rgb(255, 0, 0) solid; */
  background-color: rgb(43, 38, 111);
  width: 100%;
  height: 35lvh;
  /* how to center text within a div */
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

#heading-text {
  font-family: Archivo;
  color: white;
  font-size: 5vh;
  font-weight: 1000;
  letter-spacing: 0.5dvh;
  /* headers come with margin at the top so get rid of that */
  margin-top: 0;
}

#header-pic {
  /* outline: 1px blue solid; */
  height: 100%;
  position: absolute;
  right: 0;
}

.sidebar {
  height: 100lvh;
  width: 150px;
  padding-top: 40px;
  background-color: rgb(255, 255, 255);
  padding: 10px;
  font-size: 3lvh;
}

li {
  list-style: none;
}

a {
  text-decoration: none;
  /* border: 1px red solid; */
  margin: 10px;
}

.main-body {
  outline: 1px deeppink solid;
  background-color: bisque;
  float: right;
}

.main-body article {
  align-items: flex-end;
  justify-content: end;
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title> yyeesss ❀*ੈ✩‧₊ </title>
    <link href="style.css" rel="stylesheet" type="text/css">
  </head>
  <style></style>
  <body>
    <div class="container">
      <section class="top-header">
        <header>
          <h1 id="heading-text"> Braaahhhhhh </h1>
        </header>
        <img id="header-pic" src="cool-pic.jpg" alt="idk some filler i guuueeessss">
      </section>
      <aside class="sidebar">
        <hr>
        <ul>
          <li>
            <a href="#"> Home </a>
          </li>
          <li>
            <a href="#"> About us </a>
          </li>
          <li>
            <a href="#"> Location </a>
          </li>
          <li>
            <a href="#"> Contact us </a>
          </li>
        </ul>
        <hr>
      </aside>
      <article class="main-body">
        <div id="subheader-body">
          <h1> This is an article YEAH BABIIEEEE </h1>
          <p> Lorem, ipsum dolor sit amet consectetur adipisicing elit. Sequi accusamus asperiores, velit nihil incidunt tempore odio totam, vitae aliquam perferendis laborum doloremque excepturi ad deleniti aspernatur laudantium, veniam earum placeat. Lorem ipsum dolor sit amet consectetur adipisicing elit. Debitis quos illum velit ea minima. Perspiciatis blanditiis, magnam assumenda, culpa maxime sed consequuntur adipisci placeat laudantium deserunt nemo, ipsam reprehenderit at? Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolorum asperiores dolore ea vel, corporis nesciunt et autem nobis repellendus consequatur earum ad minima, delectus consectetur voluptatibus voluptate eos, reprehenderit iure. </p>
        </div>
      </article>
    </div>
  </body>
</html>

推荐答案

因此,最好的方法可能是将.sidebar.main-body都包装在容器div中,然后将容器div显示为flex.

所以简单地说,我所做的就是用类.main-continer包装在div中,并将其添加到css

.main-container {
  display: flex;
}

然后我把你的边栏宽度改成了min-width.

在这里,它正在发挥作用

html, body {
    background-color: rgb(65, 75, 113);
    margin:0;
    padding:0;
    box-sizing: border-box;
}

@font-face {
    font-family: 'Corben';
    src: url(Corben/Corben-Regular.ttf);
}

@font-face {
    font-family: 'Archivo';
    src: url(Archivo_Black/ArchivoBlack-Regular.ttf);
}

@font-face {
    font-family: 'Outfit';
    src: url(Outfit/static/Outfit-Regular.ttf);
}

@font-face {
    font-family: 'Outfit-black';
    src: url(Outfit/static/Outfit-Black.ttf);
}

@font-face {
    font-family: 'Cormorant-semibold';
    src: url(Cormorant/static/Cormorant-SemiBold.ttf);
}

@font-face {
    font-family: 'Cormorant';
    src: url(Cormorant/static/Cormorant-Regular.ttf);
}

.container {
    outline: white 1px solid; 
    height: 100vh;
    width: 100vw;
    /* get rid of this... or play around w it */
    display: flex;
    flex-direction: column;
}

.top-header {
    /* outline: 1px rgb(255, 0, 0) solid; */
    background-color: rgb(43, 38, 111);
    width: 100%;
    height: 35lvh;
    /* how to center text within a div */
    display: flex; 
    justify-content: center;
    align-items: center;
    position: relative;
}

#heading-text {
    font-family: Archivo;
    color: white;
    font-size: 5vh;
    font-weight: 1000;
    letter-spacing: .5dvh;
    /* headers come with margin at the top so get rid of that */ 
    margin-top: 0;
}

#header-pic {
    /* outline: 1px blue solid; */
    height: 100%;
    position: absolute;
    right: 0;
}

.sidebar { 
    height: 100lvh;
    min-width: 150px;
    padding-top: 40px;
    background-color: rgb(255, 255, 255);
    padding: 10px;
    font-size: 3lvh;
}

li {
    list-style: none;
}

a {
    text-decoration: none;
    /* border: 1px red solid; */
    margin: 10px;
}

.main-body {
    outline: 1px deeppink solid;
    background-color: bisque;
    float: right;
}

.main-container {
  display: flex;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title> yyeesss ❀*ੈ✩‧₊ </title>
   <link href="style.css" rel="stylesheet" type="text/css">
</head>

<style>
</style>

<body>
<div class="container">

    <section class="top-header">
            <header><h1 id="heading-text">
                Braaahhhhhh
            </h1></header>
        <img id="header-pic" src="cool-pic.jpg" alt="idk some filler i guuueeessss">
    </section>
<div class="main-container">
    <aside class="sidebar">
            <hr>
            <ul>
                <li>
                    <a href="#"> Home </a>
                </li>
                <li>
                    <a href="#"> About us </a>
                </li>
                <li>
                    <a href="#"> Location </a>
                </li>
                <li>
                    <a href="#"> Contact us </a>
                </li>
            </ul>
            <hr>
        </aside>

        <article class="main-body">
            <div id="subheader-body">
                <h1>
                    This is an article YEAH BABIIEEEE
                </h1>
                <p>
                    Lorem, ipsum dolor sit amet consectetur adipisicing elit. Sequi accusamus asperiores, velit nihil incidunt tempore odio totam, vitae aliquam perferendis laborum doloremque excepturi ad deleniti aspernatur laudantium, veniam earum placeat.
                    Lorem ipsum dolor sit amet consectetur adipisicing elit. Debitis quos illum velit ea minima. Perspiciatis blanditiis, magnam assumenda, culpa maxime sed consequuntur adipisci placeat laudantium deserunt nemo, ipsam reprehenderit at?
                    Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolorum asperiores dolore ea vel, corporis nesciunt et autem nobis repellendus consequatur earum ad minima, delectus consectetur voluptatibus voluptate eos, reprehenderit iure.
                </p>
            </div>
        </article>

</div>
</div>

</body>

</html>

Html相关问答推荐

将文本区域标签的内容着色为SON(带有 colored颜色 )

如何使用bslb设置可导航页面侧边栏的样式

背景可点击,而不是文本

如何创建剪切到路径的循环文本字幕?

渐变进度条位置

如何在没有包装元素的情况下在React(Next.js)中呈现HTML注释

如何使元素具有粘性

Web 组件 #shadow-root css 泄漏到文档

HTML 重定向到当前服务器

Sass 混合动画未正确应用

如何更改 Quarto 中标签crossref-def-title的标题 colored颜色 ?

如何在 css 和 html 中创建花状 struct

什么没有 margin-right 和 width:100% 溢出子元素到左边?

如何让 backdrop-filter: blur() 效果在 iOS 上运行?

有没有办法让 textarea 在调整大小时不显示 CSS 转换?

font awesome 的 CDN/CSS 如何工作?

我可以在标签元素中使用标题元素吗?

flex-box 中的图像在 Chrome 和 Firefox 中看起来不同 - 如何使它们在 Firefox 中看起来像?

样式不适用于来自 tailwindcss 的网络

为什么我的动画会向 Moz Firefox 中的微调器添加人工制品?