- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图让我的 Logo 和导航菜单底部对齐,并将它们分别左右分开(好像 Logo 向左浮动,导航项向右浮动)但我无法控制垂直方向它们之间的对齐方式,因为子元素在下方不断消失,要看到它,我必须将溢出设置为在其父元素上可见。
我一直在努力处理试图强制高度的父容器,但它们一直在折叠,我找不到让它们包裹子元素的解决方案。
这是在桌面 View 中发生的:请参阅样式末尾的@media(最小宽度:1460px)。
我能得到一些帮助吗?提前致谢。
/*------------------------- reset */
html {
box-sizing: border-box;
font-size: 16px;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body,
h1,
h2,
h3,
h4,
h5,
h6,
p,
ol,
ul {
margin: 0;
padding: 0;
}
ol,
ul {
list-style: none;
}
img {
width: 100%;
height: auto;
}
/*-------------------- general styles */
:root {
--light-bg: rgba(0, 0, 0, .1);
--main-bg-color: rgba(220, 220, 220, 0.8);
--main-font: 'Lato', sans-serif;
--title-bg: #555;
--title-color: #fff;
--title-font: "Poppins", sans-serif;
--secondary-title-color: #444;
--main-text-color: #444;
--shadows: 0px 1px 15px rgba(0, 0, 0, .6);
--hr: 1px solid rgba(0, 0, 0, .2);
}
body {
background-color: var(--main-bg-color);
color: #A1A1A1;
font-family: var(--title-font);
font-weight: 100;
font-size: 0.9rem;
letter-spacing: 1px;
line-height: 1.3;
}
.container {
position: relative;
width: 100%;
margin: 0 auto;
}
a {
outline: none;
text-decoration: none;
padding: 2px 1px 0;
}
a:link {
color: #778899;
}
a:visited {
color: #778899;
}
a:focus {
background: rgba(0, 0, 0, .3);
}
a:hover {
color: #9aa6b1;
}
a:active {
color: #fff;
}
h1,
h2,
h3,
h4,
h5,
h6 {
font-family: var(--title-font);
color: var(--secondary-title-color);
font-weight: 300;
letter-spacing: 2px;
text-transform: uppercase;
margin-bottom: 16px;
margin: 0 auto;
padding: 10px;
text-align: center;
}
h1 {
color: var(--title-color);
background-color: var(--title-bg);
font-weight: 900;
font-size: 1.5rem;
}
h2 {
font-size: 1.5rem;
}
h3 {
font-size: 1rem;
text-align: left;
padding: 20px 0;
}
p::first-letter,
li::first-letter {
text-transform: uppercase;
}
/*---------------------------- HEADER */
header {
display: block;
height: 120px;
background-color: #fff;
box-shadow: var(--shadows);
width: 100%;
position: relative;
z-index: 999999;
}
.flex-container {
overflow: hidden;
}
.logo {
}
.logo img {
width: 250px;
height: 100px;
margin: 10px;
}
/* menu */
nav {
width: 100%;
position: absolute;
z-index: 1;
top: 10px;
right: 10px;
}
nav ul {
margin: 0 -10px 0 0;
padding: 0;
list-style: none;
overflow: hidden;
background-color: rgba(255, 255, 255, 1);
top: 57px;
position: relative;
clear: both;
max-height: 0;
transition: max-height .2s ease-out;
color: white;
font-size: 1.3rem;
}
nav li a {
display: block;
padding: 20px 38px;
border-bottom: var(--hr);
text-decoration: none;
color: darkseagreen;
font-size: 1.3rem;
}
nav li a:hover,
nav .menu-btn:hover {
background-color: #f4f4f4;
}
nav li a:hover {
color: seagreen;
font-size: 1.3rem;
}
/* menu icon */
.menu-icon {
cursor: pointer;
display: inline-block;
float: right;
padding: 25px 17px;
position: relative;
user-select: none;
border: 1px solid #999;
background-color: #b2bdcc;
border-radius: 50%;
}
.menu-icon .navicon {
background: #fff;
display: block;
height: 2px;
position: relative;
transition: background .2s ease-out;
width: 18px;
}
.menu-icon .navicon:before,
.menu-icon .navicon:after {
background: #fff;
content: '';
display: block;
height: 100%;
position: absolute;
transition: all .2s ease-out;
width: 100%;
}
.menu-icon .navicon:before {
top: 5px;
}
.menu-icon .navicon:after {
top: -5px;
}
/* menu btn */
.menu-btn {
display: none;
}
.menu-btn:checked ~ ul {
max-height: 476px;
}
.menu-btn:checked ~ .menu-icon .navicon {
background: transparent;
}
.menu-btn:checked ~ .menu-icon .navicon:before {
transform: rotate(-45deg);
}
.menu-btn:checked ~ .menu-icon .navicon:after {
transform: rotate(45deg);
}
.menu-btn:checked ~ .menu-icon:not(.steps) .navicon:before,
.menu-btn:checked ~ .menu-icon:not(.steps) .navicon:after {
top: 0;
}
@media (min-width: 1460px) {
.container {
width: 80%;
}
.flex-container,
nav ul {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: space-between;
}
.logo img{
margin: 10px 0;
}
.logo {
height: 120px;
}
/* menu */
nav {
display: flex;
position: static;
width: 70%;
}
nav ul {
overflow: visible;
}
nav li{
height: max-content;
}
nav li a {
padding: 10px 20px;
border-bottom: none;
border-right: 1px solid #f4f4f4;
margin: 0;
}
.menu-icon {
display: none;
}
}
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<meta name="title" content="">
<meta name="description" content="">
<meta name="keywords" content="">
<link href="css/responsive-menu.css" rel="stylesheet" type="text/css">
</head>
<body>
<header>
<div class="container">
<div class="flex-container">
<div class="logo">
<img src="https://dummyimage.com/250x100/b2bdcc/fff.png" />
</div>
<nav>
<input class="menu-btn" type="checkbox" id="menu-btn" />
<label class="menu-icon" for="menu-btn"><span class="navicon"></span></label>
<ul>
<li><a href="#">menu 1</a></li>
<li><a href="#">menu 2</a></li>
<li><a href="#">menu 3</a></li>
<li><a href="#">menu 4</a></li>
<li><a href="#">menu 5</a></li>
<li><a href="#">menu 6</a></li>
<li><a href="#">menu 7</a></li>
</ul>
</nav>
</div>
</div>
</header>
<main>
</main>
<footer>
</footer>
</body>
</html>
最佳答案
要在 min-width: 1460px
中分隔和底部对齐 Logo 和菜单,我只在您的媒体查询中进行了这些修改(它们都已注释):
@media (min-width: 1460px) {
.container {
width: 80%;
}
.flex-container,
nav ul {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: space-between;
max-height: none; /*remove max-height:0 */
top: 0; /* remove top:57px; */
align-items: flex-end; /* This rule align your menu on bottom */
}
.logo img{
margin: 10px 0;
}
.logo {
height: 120px;
}
/* menu */
nav {
display: flex;
position: static;
/*width: 70%;*/
width:auto;
margin-left:auto; /* --> this rule put your nav on right */
}
/*nav ul {
overflow: visible; --> Removing max-height:0; this rule is not necessary
}*/
nav li{
height: max-content;
}
nav li a {
padding: 10px 20px;
border-bottom: none;
border-right: 1px solid #f4f4f4;
margin: 0;
}
.menu-icon {
display: none;
}
}
这是结果。希望能帮助到你! :)
/*------------------------- reset */
html {
box-sizing: border-box;
font-size: 16px;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body,
h1,
h2,
h3,
h4,
h5,
h6,
p,
ol,
ul {
margin: 0;
padding: 0;
}
ol,
ul {
list-style: none;
}
img {
width: 100%;
height: auto;
}
/*-------------------- general styles */
:root {
--light-bg: rgba(0, 0, 0, .1);
--main-bg-color: rgba(220, 220, 220, 0.8);
--main-font: 'Lato', sans-serif;
--title-bg: #555;
--title-color: #fff;
--title-font: "Poppins", sans-serif;
--secondary-title-color: #444;
--main-text-color: #444;
--shadows: 0px 1px 15px rgba(0, 0, 0, .6);
--hr: 1px solid rgba(0, 0, 0, .2);
}
body {
background-color: var(--main-bg-color);
color: #A1A1A1;
font-family: var(--title-font);
font-weight: 100;
font-size: 0.9rem;
letter-spacing: 1px;
line-height: 1.3;
}
.container {
position: relative;
width: 100%;
margin: 0 auto;
}
a {
outline: none;
text-decoration: none;
padding: 2px 1px 0;
}
a:link {
color: #778899;
}
a:visited {
color: #778899;
}
a:focus {
background: rgba(0, 0, 0, .3);
}
a:hover {
color: #9aa6b1;
}
a:active {
color: #fff;
}
h1,
h2,
h3,
h4,
h5,
h6 {
font-family: var(--title-font);
color: var(--secondary-title-color);
font-weight: 300;
letter-spacing: 2px;
text-transform: uppercase;
margin-bottom: 16px;
margin: 0 auto;
padding: 10px;
text-align: center;
}
h1 {
color: var(--title-color);
background-color: var(--title-bg);
font-weight: 900;
font-size: 1.5rem;
}
h2 {
font-size: 1.5rem;
}
h3 {
font-size: 1rem;
text-align: left;
padding: 20px 0;
}
p::first-letter,
li::first-letter {
text-transform: uppercase;
}
/*---------------------------- HEADER */
header {
display: block;
height: 120px;
background-color: #fff;
box-shadow: var(--shadows);
width: 100%;
position: relative;
z-index: 999999;
}
.flex-container {
overflow: hidden;
}
.logo {
}
.logo img {
width: 250px;
height: 100px;
margin: 10px;
}
/* menu */
nav {
width: 100%;
position: absolute;
z-index: 1;
top: 10px;
right: 10px;
}
nav ul {
margin: 0 -10px 0 0;
padding: 0;
list-style: none;
overflow: hidden;
background-color: rgba(255, 255, 255, 1);
top: 57px;
position: relative;
clear: both;
max-height: 0;
transition: max-height .2s ease-out;
color: white;
font-size: 1.3rem;
}
nav li a {
display: block;
padding: 20px 38px;
border-bottom: var(--hr);
text-decoration: none;
color: darkseagreen;
font-size: 1.3rem;
}
nav li a:hover,
nav .menu-btn:hover {
background-color: #f4f4f4;
}
nav li a:hover {
color: seagreen;
font-size: 1.3rem;
}
/* menu icon */
.menu-icon {
cursor: pointer;
display: inline-block;
float: right;
padding: 25px 17px;
position: relative;
user-select: none;
border: 1px solid #999;
background-color: #b2bdcc;
border-radius: 50%;
}
.menu-icon .navicon {
background: #fff;
display: block;
height: 2px;
position: relative;
transition: background .2s ease-out;
width: 18px;
}
.menu-icon .navicon:before,
.menu-icon .navicon:after {
background: #fff;
content: '';
display: block;
height: 100%;
position: absolute;
transition: all .2s ease-out;
width: 100%;
}
.menu-icon .navicon:before {
top: 5px;
}
.menu-icon .navicon:after {
top: -5px;
}
/* menu btn */
.menu-btn {
display: none;
}
.menu-btn:checked ~ ul {
max-height: 476px;
}
.menu-btn:checked ~ .menu-icon .navicon {
background: transparent;
}
.menu-btn:checked ~ .menu-icon .navicon:before {
transform: rotate(-45deg);
}
.menu-btn:checked ~ .menu-icon .navicon:after {
transform: rotate(45deg);
}
.menu-btn:checked ~ .menu-icon:not(.steps) .navicon:before,
.menu-btn:checked ~ .menu-icon:not(.steps) .navicon:after {
top: 0;
}
@media (min-width: 1460px) {
.container {
width: 80%;
}
.flex-container,
nav ul {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: space-between;
max-height: none; /*remove max-height:0 */
top: 0; /* remove top:57px; */
align-items: flex-end; /* This rule align your menu on bottom */
}
.logo img{
margin: 10px 0;
}
.logo {
height: 120px;
}
/* menu */
nav {
display: flex;
position: static;
/*width: 70%;*/
width:auto;
margin-left:auto; /* --> this rule put your nav on right */
}
/*nav ul {
overflow: visible; --> Removing max-height:0; this rule is not necessary
}*/
nav li{
height: max-content;
}
nav li a {
padding: 10px 20px;
border-bottom: none;
border-right: 1px solid #f4f4f4;
margin: 0;
}
.menu-icon {
display: none;
}
}
<header>
<div class="container">
<div class="flex-container">
<div class="logo">
<img src="https://dummyimage.com/250x100/b2bdcc/fff.png" />
</div>
<nav>
<input class="menu-btn" type="checkbox" id="menu-btn" />
<label class="menu-icon" for="menu-btn"><span class="navicon"></span></label>
<ul>
<li><a href="#">menu 1</a></li>
<li><a href="#">menu 2</a></li>
<li><a href="#">menu 3</a></li>
<li><a href="#">menu 4</a></li>
<li><a href="#">menu 5</a></li>
<li><a href="#">menu 6</a></li>
<li><a href="#">menu 7</a></li>
</ul>
</nav>
</div>
</div>
</header>
<main>
</main>
<footer>
</footer>
关于css - Flexbox 父元素折叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53204542/
我目前正在寻找一些关于 jQuery 的建议,因为我认为我做错了,即使我得到了我想要的结果。 我想在更改时将输入的值更改为最接近的具有 .milestone 类的输入的值。我想要更改的输入是保持输入,
我已经阅读有关绑定(bind)、调用、申请的文章近一周了,对我来说仍然很复杂。我想我写的这个 jsfiddle 需要它们。然而,我没能做到,因为我仍然很困惑。 我尽力写了一些我上周从遇到这个问题的开发
我有一个项目生成代码。生成时间真的很长,所以我把它分成了多个项目,每个项目产生了整体的 20%。原始 POM 成为“父 POM”,子项依赖于它,仅包含一个单独的 Artifact ID 和一两个更改的
我正在使用局部 View 来创建父 subview 。我最理想的是父 View 上的提交按钮,用于保存子值。 我有以下模型。 public class Course { public int
我刚刚开始学习Rust,并且在理解所有权如何在我的案例中遇到一些麻烦: use std::ops::IndexMut; // =====================================
我是 JavaScript 新手,想了解更多有关它实例化父/子对象的顺序的信息。更具体地说,我想从编译器/浏览器的 Angular 理解以下代码片段。 var parent = { child:
我正在测试 Azure IaaS,并遇到了一个非常基本的问题。我有一个父 VHD 和子 VHD,已使用 csupload 将其作为页面 blob 上传,并且门户中显示图像和磁盘。然后我尝试将 pare
我的应用程序会定期为我坚持使用的对象请求更新 Core Data到网络服务。然后我需要更新我在主要上下文中拥有的对象(默认情况下 AppDelegate 中提供的对象)。编辑对象的不是用户,所以我需要
texT text text text text text 如何直接获取来自.menu ? 里面的 child 不应该采取。
我一直需要影响与其他元素相关的元素,但我的方法有点业余! 即到 // matched item where script is called from LINK 我使用; $(thi
我有两个表: 父子“类别”: id name parent_id 1 Food NULL 2 Pizza 1 3 Pasta
Linux 上的 Python 2.7.6。 我正在使用从父级继承的测试类。父类保存了许多子类共有的许多字段,我需要调用父类的 setUp 方法来初始化这些字段。调用 ParentClass.setU
我有一个处理图像、相册和相册类别的数据库。 一个专辑可以有多个专辑(子专辑),并且只有 1 级深度。 一张专辑仅属于一个专辑类别。 在这里做了一些研究,我相信最合适的数据库模型是这个 album_ca
我有一个关键字表,其中每个关键字都分配有一个 ID,并且是唯一的。我有第二个表,将父关键字的 ID 链接到子关键字的 ID。一个关键字最多可以有大约 800 个 child 或根本没有。 child
我经常使用这个 CSS 选择器 parent>child。我的设计在 Mozilla 和 Opera 中看起来不错。 但在 IE 中,它很糟糕。我知道 > 在 IE 中无法识别,但在 IE 中有什么替
我一直在用一个父对象构建一个系统,它在其中创建各种子对象,每个子对象都需要一个主对象才能运行。现在,到目前为止,我一直在创建 shared_ptr和 Child* ,所以当 Parent 和 所有 C
我从以下两个类中收到序列化兼容性错误。只有父类CommericalCustomer 实现了序列化。当具有如下所示的父/子关系时,使用可序列化接口(interface)的正确方法是什么? public
我正在开发一个程序并学习父/子进程。目前我的子进程是 exit(variable); 在我的 main() 中我有: signal(SIGCHLD, chldHandler); 在我的 main()
考虑以下两个具体类: public class A { protected void foo() { System.out.println("A foo"); bar
所以,我正在尝试建立这样的父/子类关系: class ParentClass where C : ChildClass { public void AddChild(C child)
我是一名优秀的程序员,十分优秀!