如何解决HTML和CSS上的display: flex问题?

huangapple go评论70阅读模式
英文:

How can i resolve a problem of display: flex on html & css?

问题

你好朋友,能有人帮助我吗,我对HTML很陌生,这是我的第一段代码,我正在看YouTube视频学习,但我遇到了问题,我想要视频中的效果,但它不起作用,这是HTML代码:

<!DOCTYPE html>
<html lang="es">
    <head>
        <meta charset="UTF-8">
        <title>Tienda Online</title>
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <link rel="stylesheet" href="css/estilos.css">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css">
    </head>
    <body>
        <header class="main-header">
            <div class="container container--flex">
                <div class="main-header__container">
                    <h1 class="main-header__title">GOGGLES</h1>
                    <span class="icon-menu fa-solid fa-bars" id="btn-menu"></span>
                    <nav class="main-nav" id="main-nav">
                        <ul class="menu">
                            <li class="menu__item"><a href="" class="menu__link">HOME</a></li>
                            <li class="menu__item"><a href="" class="menu__link">ABOUT</a></li>
                            <li class="menu__item"><a href="" class="menu__link">FEATURES</a></li>
                            <li class="menu__item"><a href="" class="menu__link">SHOP</a></li>
                            <li class="menu__item"><a href="" class="menu__link">CONTACT</a></li>
                        </ul>
                    </nav>
                </div>
                <div class="main-header__container">
                    <span class="main-header__txt">Need Help</span>
                    <p class="main-header__txt"><i class="fa-solid fa-phone"></i> Call 12345678099</p>
                </div>
                <div class="main-header__container">
                    <i class="fa-solid fa-user"></i>
                    <a href="">My cart<i class="fa-solid fa-cart-shopping"></i></a>
                    <input type="search"><i class="fa-solid fa-magnifying-glass"></i>
                </div>
            </div>
        </header>
    </body>
</html>

这是CSS:

* {
  box-sizing: border-box;
}
body {
  margin: 0;
}
img {
  display: block;
  width: 100%;
}
.main-header__title {
  text-align: center;
  font-size: 2.5em;
  margin: 10px 0px;
  color: #454546;
}
.main-nav {
  display: none;
}
.main-header__title {
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.icon-menu {
  font-size: 1.5em;
  border: 1px solid #454546;
  display: block;
  padding: 10px 20px;
}

应该看起来像这样:链接,但实际上看起来像这样:链接。也许问题出在display: flexjustify-content: space-around。我真正的问题是我不知道如何更改这些。谢谢;D

英文:

Hellow friends, could somebody help me, i'm very noob in html, this is my first code, i'm watching a youtube video to learn, but i have issues with this, i want to do that is on the video, and is not working this is the code in html

&lt;!DOCTYPE html&gt;
&lt;html lang = &quot;es&quot;&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;title&gt;Tienda Online&lt;/title&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width-device-width, user-scalable-no, initial-scale=1.0, maximun-scale=1.0, minimun-scale=1.0&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;css/estilos.css&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;header class=&quot;main-header&quot;&gt;
&lt;div clas=&quot;container container--flex&quot;&gt;
&lt;div clas=&quot;main-header__container&quot;&gt;
&lt;h1 class=&quot;main-header__title&quot;&gt;GOGGLES&lt;/h1&gt;
&lt;span class=&quot;icon-menu fa-solid fa-bars&quot; id=&quot;btn-menu&quot;&gt;&lt;/span&gt;
&lt;nav class=&quot;main-nav&quot; id=&quot;main-nav&quot;&gt;
&lt;ul class=&quot;menu&quot;&gt;
&lt;li class=&quot;menu__item&quot;&gt;&lt;a href=&quot;&quot; class=&quot;menu__link&quot;&gt;HOME&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;menu__item&quot;&gt;&lt;a href=&quot;&quot; class=&quot;menu__link&quot;&gt;ABOUT&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;menu__item&quot;&gt;&lt;a href=&quot;&quot; class=&quot;menu__link&quot;&gt;FEATURES&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;menu__item&quot;&gt;&lt;a href=&quot;&quot; class=&quot;menu__link&quot;&gt;SHOP&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;menu__item&quot;&gt;&lt;a href=&quot;&quot; class=&quot;menu__link&quot;&gt;CONTACT&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/nav&gt;
&lt;/div&gt;
&lt;div clas=&quot;main-header__container&quot;&gt;
&lt;span class=&quot;main-header__txt&quot;&gt;Need Help&lt;/span&gt;
&lt;p class=&quot;main-header__txt&quot;&gt;&lt;i class=&quot;fa-solid fa-phone&quot;&gt;&lt;/i&gt; Call 12345678099&lt;/p&gt;
&lt;/div&gt;   
&lt;div clas=&quot;main-header__container&quot;&gt;
&lt;i class=&quot;fa-solid fa-user&quot;&gt;&lt;/i&gt;
&lt;a href=&quot;&quot;&gt;My cart&lt;i class=&quot;fa-solid fa-cart-shopping&quot;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;input type=&quot;search&quot;&gt;&lt;i class=&quot;fa-solid fa-magnifying-glass&quot;&gt;&lt;/i&gt;
&lt;/div&gt; 
&lt;/div&gt;
&lt;/header&gt;
&lt;/body&gt;
&lt;/html&gt;

an this is in css:

* {
box-sizing: border-box;
}
body{
margin :0;
}
img{
display: block;
width: 100%;
}
.main-header__title{
text-align: center;
font-size: 2.5em;
margin: 10px 0px;
color: #454546;
}
.main-nav{
display: none;
}
.main-header__title{
display: flex;
justify-content: space-around;
align-items: center;
}
.icon-menu{
font-size: 1.5em;
border: 1px solid #454546;
display: block;
padding: 10px 20px;
}

its supposed to watch like this

But, it looks like this

maybe its a problem on the display:flex or in the justify-content: space around. My real problem is that i don't know how to change this

thanks ;D

答案1

得分: 0

错误如下:

  1. 单词 "clas" 中的拼写错误。
  2. 在CSS中使用了错误的类名 - ".main-header__title" 而不是 ".main-header__container"。

以下是解决方案:

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

img {
  display: block;
  width: 100%;
}

.main-header__title {
  text-align: center;
  font-size: 2.5em;
  margin: 10px 0px;
  color: #454546;
}

.main-nav {
  display: none;
}

.main-header__container {
  display: flex;
  justify-content: space around;
  align-items: center;
}

.icon-menu {
  font-size: 1.5em;
  border: 1px solid #454546;
  display: block;
  padding: 10px 20px;
}
<!DOCTYPE html>
<html lang="es">
<head>
  <meta charset="UTF-8">
  <title>Tienda Online</title>
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <link rel="stylesheet" href="css/estilos.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css">
</head>
<body>
  <header class="main-header">
    <div class="container container--flex">
      <div class="main-header__container">
        <h1 class="main-header__title">GOGGLES</h1>
        <span class="icon-menu fa-solid fa-bars" id="btn-menu"></span>
        <nav class="main-nav" id="main-nav">
          <ul class="menu">
            <li class="menu__item"><a href="" class="menu__link">HOME</a></li>
            <li class="menu__item"><a href="" class="menu__link">ABOUT</a></li>
            <li class="menu__item"><a href="" class="menu__link">FEATURES</a></li>
            <li class="menu__item"><a href="" class="menu__link">SHOP</a></li>
            <li class="menu__item"><a href="" class="menu__link">CONTACT</a></li>
          </ul>
        </nav>
      </div>
      <div class="main-header__container">
        <span class="main-header__txt">Need Help</span>
        <p class="main-header__txt"><i class="fa-solid fa-phone"></i> Call 12345678099</p>
      </div>
      <div class="main-header__container">
        <i class="fa-solid fa-user"></i>
        <a href="">My cart<i class="fa-solid fa-cart-shopping"></i></a>
        <input type="search"><i class="fa-solid fa-magnifying-glass"></i>
      </div>
    </div>
  </header>
</body>
</html>
英文:

Errors were:

  1. Typos in word "clas"
  2. Use wrong class in CSS - ".main-header__title" instead of ".main-header__container"

Here is a solution:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

* {
box-sizing: border-box;
}
body {
margin: 0;
}
img {
display: block;
width: 100%;
}
.main-header__title {
text-align: center;
font-size: 2.5em;
margin: 10px 0px;
color: #454546;
}
.main-nav {
display: none;
}
.main-header__container {
display: flex;
justify-content: space-around;
align-items: center;
}
.icon-menu {
font-size: 1.5em;
border: 1px solid #454546;
display: block;
padding: 10px 20px;
}

<!-- language: lang-html -->

&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;es&quot;&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;title&gt;Tienda Online&lt;/title&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width-device-width, user-scalable-no, initial-scale=1.0, maximun-scale=1.0, minimun-scale=1.0&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;css/estilos.css&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;header class=&quot;main-header&quot;&gt;
&lt;div class=&quot;container container--flex&quot;&gt;
&lt;div class=&quot;main-header__container&quot;&gt;
&lt;h1 class=&quot;main-header__title&quot;&gt;GOGGLES&lt;/h1&gt;
&lt;span class=&quot;icon-menu fa-solid fa-bars&quot; id=&quot;btn-menu&quot;&gt;&lt;/span&gt;
&lt;nav class=&quot;main-nav&quot; id=&quot;main-nav&quot;&gt;
&lt;ul class=&quot;menu&quot;&gt;
&lt;li class=&quot;menu__item&quot;&gt;&lt;a href=&quot;&quot; class=&quot;menu__link&quot;&gt;HOME&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;menu__item&quot;&gt;&lt;a href=&quot;&quot; class=&quot;menu__link&quot;&gt;ABOUT&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;menu__item&quot;&gt;&lt;a href=&quot;&quot; class=&quot;menu__link&quot;&gt;FEATURES&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;menu__item&quot;&gt;&lt;a href=&quot;&quot; class=&quot;menu__link&quot;&gt;SHOP&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;menu__item&quot;&gt;&lt;a href=&quot;&quot; class=&quot;menu__link&quot;&gt;CONTACT&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/nav&gt;
&lt;/div&gt;
&lt;div class=&quot;main-header__container&quot;&gt;
&lt;span class=&quot;main-header__txt&quot;&gt;Need Help&lt;/span&gt;
&lt;p class=&quot;main-header__txt&quot;&gt;&lt;i class=&quot;fa-solid fa-phone&quot;&gt;&lt;/i&gt; Call 12345678099&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;main-header__container&quot;&gt;
&lt;i class=&quot;fa-solid fa-user&quot;&gt;&lt;/i&gt;
&lt;a href=&quot;&quot;&gt;My cart&lt;i class=&quot;fa-solid fa-cart-shopping&quot;&gt;&lt;/i&gt;&lt;/a&gt;
&lt;input type=&quot;search&quot;&gt;&lt;i class=&quot;fa-solid fa-magnifying-glass&quot;&gt;&lt;/i&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/header&gt;
&lt;/body&gt;
&lt;/html&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年2月10日 06:14:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75405010.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定