html - 在标题内部对齐导航项

标签 html css header navigation flexbox

我不想使用 Float 属性。

我想使用这些属性(链接):https://css-tricks.com/snippets/css/a-guide-to-flexbox/

我还评论了背景图像 css3 吗?我也想申请

我的代码:

*{
    margin:0;
    padding: 0;
    box-sizing: border-box;
}


html,
body {
    background-color: #fff;
    color: #555;
    font-family: "Lato", "Arial", "sans-serif";
    font-weight: 300;
    font-size: 20px;
    text-rendering: optimizeLegibility;
    }


.wrapper{
	display: flex;
    display: -webkit-flex;
    display: -ms-flexbox;
    margin: 0 auto;
    flex-direction:column;
    width: 100%;
    max-width: 80%;
    border: solid 1px #000;
}

.header{
    /*background-image: -webkit-linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url("logo.png");
    background-size: cover;
    background-position: center;
    height: 100vh;
    background-attachment:fixed; */
    background-color: rgba(0, 0, 0, 0.8);
    color: rgba(0, 0, 0, 0.7);
    }

.logo{
    height: 100px;
    width:auto;
    border-radius: 50%;
    margin: 10px;
    align-items: center;
}


.main-nav {
    display: flex;
    list-style: none;
    }


.main-nav a{
    text-decoration: none;
    color:rgba(255, 255, 255, 0.8);
}



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

<head>
  <meta charset="utf-8">
  <title>FlexBox: HTML5 and CSS3 Fundamentals</title>

  <link rel="stylesheet" type="text/css" href="styles.css" media="screen" />

  <link href="http://fonts.googleapis.com/css?family=Lato:100,300,400,300italic" rel="stylesheet" type="text/css">
</head>

<body>
  <div class="wrapper">
    <header>
      <div class="header">
        <img src="logo1.png" alt="Logo" class="logo">

        <nav>
          <ul class="main-nav">
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Contact</a></li>
          </ul>
        </nav>
      </div>
    </header>

  </div>
</body>

</html>

最佳答案

哦,那这个呢?

左边是Logo,右边是导航

*{
    margin:0;
    padding: 0;
    box-sizing: border-box;
}


html,
body {
    background-color: #fff;
    color: #555;
    font-family: "Lato", "Arial", "sans-serif";
    font-weight: 300;
    font-size: 20px;
    text-rendering: optimizeLegibility;
    }


.wrapper{
	display: flex;
    display: -webkit-flex;
    display: -ms-flexbox;
    margin: 0 auto;
    flex-direction:column;
    width: 100%;
    max-width: 80%;
    border: solid 1px #000;
}

.header{
    background-image: -webkit-linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url("logo.png");
    background-size: cover;
    background-position: center;
    height: 100vh;
    background-attachment:fixed;
    background-color: rgba(0, 0, 0, 0.8);
    color: rgba(0, 0, 0, 0.7);
    justify-content: space-between;
    display: flex;
    flex-direction: row;
    }

.logo{
    height: 100px;
    width:auto;
    border-radius: 50%;
    margin: 10px;
}


.main-nav {
    display: flex;
    list-style: none;
    }


.main-nav a{
    text-decoration: none;
    color:rgba(255, 255, 255, 0.8);
}



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

<head>
  <meta charset="utf-8">
  <title>FlexBox: HTML5 and CSS3 Fundamentals</title>

  <link rel="stylesheet" type="text/css" href="styles.css" media="screen" />

  <link href="http://fonts.googleapis.com/css?family=Lato:100,300,400,300italic" rel="stylesheet" type="text/css">
</head>

<body>
  <div class="wrapper">
    <header>
      <div class="header">
        <img src="logo1.png" alt="Logo" class="logo">

        <nav>
          <ul class="main-nav">
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Contact</a></li>
          </ul>
        </nav>
      </div>
    </header>

  </div>
</body>

</html>

关于html - 在标题内部对齐导航项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43003140/

相关文章:

html - 复选框大小在 IE7 中有所不同

c++ - CMake:当输入列表的头文件部分更改与正在输出的对象无关时,是否可以重建目标?

email - Delivered-To 标题是查找转发邮件收件人地址的正确位置吗?

c++ - 解析位图文件时,如何替换WORD和DWORD数据类型?

javascript - 为 "scroll to div"分离两个脚本

html - 如何更改文本框的样式? (HTML/CSS)

html - IE 和 Firefox 忽略最大宽度样式

jquery - $(window).scroll() 循环,由于没有变量

javascript - 阿拉伯文本零宽度连接器在元素之间不起作用

html - 一个 div 覆盖另一个而不使用以像素为单位的高度