我有一个响应式导航栏,并带有一个下拉菜单。当我调整浏览器大小以使其达到断点并导航到其移动视图时,下面的英雄图像将消失并且部分可见标题标签,我不确定并且看不到是什么原因造成的。任何帮助将不胜感激!
HTML
<section class="navigation">
<div class="nav-container">
<div class="brand">
<a href="#!">image</a>
</div>
<nav>
<div class="nav-mobile"><a id="nav-toggle" href="#!"><span></span></a></div>
<ul class="nav-list">
<li>
<a href="#!">header 10</a>
</li>
<li>
<a href="#!">header 9</a>
<ul class="nav-dropdown">
<li>
<a href="#!">header 8</a>
</li>
<li>
<a href="#!">header 7</a>
</li>
<li>
<a href="#!">header 6</a>
</li>
<li>
<a href="#!">header 5</a>
</li>
<li>
<a href="#!">header 4</a>
</li>
</ul>
</li>
<li>
<a href="#!">header3</a>
</li>
<li>
<a href="#!">header 2</a>
</li>
<li>
<a href="#!">Header 1</a>
</li>
</ul>
</nav>
</div>
</section>
<div class="hero-image">
<div class="hero-text">
<h1>Bring Your Garden And Driveway to life </h1>
<h2>Scroll Down To Learn More</h2>
</div>
</div>
CSS
@charset "UTF-8";
.navigation {
height: 70px;
background: #262626;
}
.brand {
position: absolute;
padding-left: 20px;
float: left;
line-height: 70px;
text-transform: uppercase;
font-size: 1.4em;
}
.brand a,
.brand a:visited {
color: #ffffff;
text-decoration: none;
}
.nav-container {
max-width: 1000px;
margin: 0 auto;
}
nav {
float: right;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
nav ul li {
float: left;
position: relative;
}
nav ul li a,
nav ul li a:visited {
display: block;
padding: 0 20px;
line-height: 70px;
background: #262626;
color: #ffffff;
text-decoration: none;
}
nav ul li a:hover,
nav ul li a:visited:hover {
color: grey;
}
nav ul li a:not(:only-child):after,
nav ul li a:visited:not(:only-child):after {
padding-left: 4px;
content: ' ▾';
}
nav ul li ul li {
min-width: 190px;
}
nav ul li ul li a {
padding: 15px;
line-height: 20px;
}
.nav-dropdown {
position: absolute;
display: none;
z-index: 1;
box-shadow: 0 3px 12px rgba(0, 0, 0, 0.15);
}
/* Mobile navigation */
.nav-mobile {
display: none;
position: absolute;
top: 0;
right: 0;
background: #262626;
height: 70px;
width: 70px;
}
@media only screen and (max-width: 798px) {
.nav-mobile {
display: block;
}
nav {
width: 100%;
padding: 70px 0 15px;
}
nav ul {
display: none;
}
nav ul li {
float: none;
}
nav ul li a {
padding: 15px;
line-height: 20px;
}
nav ul li ul li a {
padding-left: 30px;
}
.nav-dropdown {
position: static;
}
}
@media screen and (min-width: 799px) {
.nav-list {
display: block !important;
}
}
#nav-toggle {
position: absolute;
left: 18px;
top: 22px;
cursor: pointer;
padding: 10px 35px 16px 0px;
}
#nav-toggle span,
#nav-toggle span:before,
#nav-toggle span:after {
cursor: pointer;
border-radius: 1px;
height: 5px;
width: 35px;
background: #ffffff;
position: absolute;
display: block;
content: '';
transition: all 300ms ease-in-out;
}
#nav-toggle span:before {
top: -10px;
}
#nav-toggle span:after {
bottom: -10px;
}
#nav-toggle.active span {
background-color: transparent;
}
#nav-toggle.active span:before, #nav-toggle.active span:after {
top: 0;
}
#nav-toggle.active span:before {
transform: rotate(45deg);
}
#nav-toggle.active span:after {
transform: rotate(-45deg);
}
body, html {
height: 100%;
margin: 0;
font-family: 'Montserrat', sans-serif;
}
body {
height: 1000px;
}
.hero-image {
background-image: url(https://stmed.net/sites/default/files/leaves-wallpapers-25246-1391025.jpg);
height: 50%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
/*==========WELCOME-TEXT==========*/
.hero-text {
text-align: center;
color: white;
font-family: 'Slabo 27px', serif;
font-size: 26px;
}
.hero-text h2 {
font-style: italic;
font-size: 22px;
}
@media only screen and (max-width: 450px) {
.hero-text h1 {
font-size: 20px;
font-family: 'Slabo 20px', serif;
}
.hero-text h2 {
font-size: 18px;
}
}
下面是我的代码的jsfiddle https://jsfiddle.net/wkqph6x4/1/
答案 0 :(得分:1)
只需将Rouzbehs-MacBook-Pro-2:AirSim Rouzbeh$ ./setup.sh
+ set -e
+++ dirname ./setup.sh
++ cd .
++ pwd
+ SCRIPT_DIR=/Users/Rouzbeh/BoxSync/Fall2018/AirSim
+ pushd /Users/Rouzbeh/BoxSync/Fall2018/AirSim
+ downloadHighPolySuv=true
+ [[ '' == \-\-\n\o\-\f\u\l\l\-\p\o\l\y\-\c\a\r ]]
++ uname
+ '[' Darwin == Darwin ']'
+ [[ ! -z '' ]]
+ brew tap llvm-hs/homebrew-llvm
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core, homebrew/cask).
==> Updated Formulae
convox jenkins
brew install llvm-5.0
==> Installing llvm-5.0 from llvm-hs/llvm
==> Downloading http://releases.llvm.org/5.0.1/llvm-5.0.1.src.tar.xz
Already downloaded: /Users/Rouzbeh/Library/Caches/Homebrew/llvm-5.0--5.0.1.tar.xz
==> Downloading http://releases.llvm.org/5.0.1/cfe-5.0.1.src.tar.xz
Already downloaded: /Users/Rouzbeh/Library/Caches/Homebrew/llvm-5.0--clang--5.0.1.tar.xz
==> Downloading http://releases.llvm.org/5.0.1/libcxx-5.0.1.src.tar.xz
Already downloaded: /Users/Rouzbeh/Library/Caches/Homebrew/llvm-5.0--libcxx--5.0.1.tar.xz
==> Downloading http://releases.llvm.org/5.0.1/lld-5.0.1.src.tar.xz
Already downloaded: /Users/Rouzbeh/Library/Caches/Homebrew/llvm-5.0--lld--5.0.1.tar.xz
==> Downloading http://releases.llvm.org/5.0.1/polly-5.0.1.src.tar.xz
Already downloaded: /Users/Rouzbeh/Library/Caches/Homebrew/llvm-5.0--polly--5.0.1.tar.xz
==> Downloading http://releases.llvm.org/5.0.1/clang-tools-extra-5.0.1.src.tar.xz
Already downloaded: /Users/Rouzbeh/Library/Caches/Homebrew/llvm-5.0--clang-tools-extra--5.0.1.tar.xz
==> Downloading http://releases.llvm.org/5.0.1/openmp-5.0.1.src.tar.xz
Already downloaded: /Users/Rouzbeh/Library/Caches/Homebrew/llvm-5.0--openmp--5.0.1.tar.xz
==> Downloading http://releases.llvm.org/5.0.1/libcxx-5.0.1.src.tar.xz
Already downloaded: /Users/Rouzbeh/Library/Caches/Homebrew/llvm-5.0--libcxx--5.0.1.tar.xz
==> Downloading http://releases.llvm.org/5.0.1/libunwind-5.0.1.src.tar.xz
Already downloaded: /Users/Rouzbeh/Library/Caches/Homebrew/llvm-5.0--libunwind--5.0.1.tar.xz
==> Downloading http://releases.llvm.org/5.0.1/compiler-rt-5.0.1.src.tar.xz
Already downloaded: /Users/Rouzbeh/Library/Caches/Homebrew/llvm-5.0--compiler-rt--5.0.1.tar.xz
==> cmake /private/tmp/llvm-5.0-20180826-50196-5rhe1j/llvm-5.0.1.src -DCMAKE_C_FLAGS_RELEASE=-DND
==> cmake --build .
Last 15 lines from /Users/Rouzbeh/Library/Logs/Homebrew/llvm-5.0/02.cmake:
[ 94%] Building CXX object lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoTermination.ios.dir/sanitizer_stacktrace_printer.cc.o
[ 94%] Building CXX object lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoTermination.ios.dir/sanitizer_stoptheworld_mac.cc.o
[ 94%] Building CXX object lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoTermination.ios.dir/sanitizer_suppressions.cc.o
[ 94%] Building CXX object lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoTermination.ios.dir/sanitizer_symbolizer.cc.o
[ 94%] Building CXX object lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoTermination.ios.dir/sanitizer_symbolizer_libbacktrace.cc.o
[ 94%] Building CXX object lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoTermination.ios.dir/sanitizer_symbolizer_mac.cc.o
[ 94%] Building CXX object lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoTermination.ios.dir/sanitizer_symbolizer_win.cc.o
[ 94%] Building CXX object lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoTermination.ios.dir/sanitizer_tls_get_addr.cc.o
[ 94%] Building CXX object lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoTermination.ios.dir/sanitizer_thread_registry.cc.o
[ 95%] Building CXX object lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoTermination.ios.dir/sanitizer_win.cc.o
[ 95%] Built target RTSanitizerCommonNoTermination.ios
make[3]: *** [all] Error 2
make[2]: *** [tools/clang/runtime/compiler-rt-stamps/compiler-rt-build] Error 2
make[1]: *** [tools/clang/runtime/CMakeFiles/compiler-rt.dir/all] Error 2
make: *** [all] Error 2
分配给width: 100%
类。
我认为您的图片宽度大于783px。因此,只要div宽度低于783px,您的图像就会停止显示,.hero-image的宽度变为0px。
答案 1 :(得分:1)
您需要在.hero-image
类上指定宽度。在这种情况下,width: '100%';
就足够了,尽管它可以是您想要的任何形式。
执行此操作后,您会注意到导航和英雄图像之间存在15px
间隙,该间隙来自nav
元素的底部填充。如果这是一种风格/设计选择,则无需担心删除或调整它。只是想抬起头来。
答案 2 :(得分:1)
在媒体查询中触发798px以下的移动菜单
@media only screen and (max-width: 798px) {
两个方块使它消失。
nav { 宽度:100%; 填充:70px 0 15px; } 导航ul { 显示:无; }
答案 3 :(得分:1)
这是正确的工作答案-即使在flex项目上设置宽度也解决了部分问题。我将nav { float: right }
移到了799px以上的媒体查询中,然后在nav
元素下方添加了一些样式(z索引和位置)。
更新的小提琴:https://jsfiddle.net/wkqph6x4/24/
(function($) { // Begin jQuery
$(function() { // DOM ready
// If a link has a dropdown, add sub menu toggle.
$('nav ul li a:not(:only-child)').click(function(e) {
$(this).siblings('.nav-dropdown').toggle();
// Close one dropdown when selecting another
$('.nav-dropdown').not($(this).siblings()).hide();
e.stopPropagation();
});
// Clicking away from dropdown will remove the dropdown class
$('html').click(function() {
$('.nav-dropdown').hide();
});
// Toggle open and close nav styles on click
$('#nav-toggle').click(function() {
$('nav ul').slideToggle();
});
// Hamburger to X toggle
$('#nav-toggle').on('click', function() {
this.classList.toggle('active');
});
}); // end DOM ready
})(jQuery); // end jQuery
@charset "UTF-8";
.navigation {
height: 70px;
background: #262626;
}
.brand {
position: absolute;
padding-left: 20px;
float: left;
line-height: 70px;
text-transform: uppercase;
font-size: 1.4em;
}
.brand a,
.brand a:visited {
color: #ffffff;
text-decoration: none;
}
.nav-container {
max-width: 1000px;
margin: 0 auto;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
nav ul li {
float: left;
position: relative;
}
nav ul li a,
nav ul li a:visited {
display: block;
padding: 0 20px;
line-height: 70px;
background: #262626;
color: #ffffff;
text-decoration: none;
}
nav ul li a:hover,
nav ul li a:visited:hover {
color: grey;
}
nav ul li a:not(:only-child):after,
nav ul li a:visited:not(:only-child):after {
padding-left: 4px;
content: ' ▾';
}
nav ul li ul li {
min-width: 190px;
}
nav ul li ul li a {
padding: 15px;
line-height: 20px;
}
.nav-dropdown {
position: absolute;
display: none;
z-index: 1;
box-shadow: 0 3px 12px rgba(0, 0, 0, 0.15);
}
/* Mobile navigation */
.nav-mobile {
display: none;
position: absolute;
top: 0;
right: 0;
background: #262626;
height: 70px;
width: 70px;
}
@media only screen and (max-width: 798px) {
.nav-mobile {
display: block;
}
nav {
width: 100%;
padding: 70px 0 15px;
z-index: 100;
position: relative;
}
nav ul {
display: none;
}
nav ul li {
float: none;
}
nav ul li a {
padding: 15px;
line-height: 20px;
}
nav ul li ul li a {
padding-left: 30px;
}
.nav-dropdown {
position: static;
}
}
@media screen and (min-width: 799px) {
nav {
float: right;
}
.nav-list {
display: block !important;
}
}
#nav-toggle {
position: absolute;
left: 18px;
top: 22px;
cursor: pointer;
padding: 10px 35px 16px 0px;
}
#nav-toggle span,
#nav-toggle span:before,
#nav-toggle span:after {
cursor: pointer;
border-radius: 1px;
height: 5px;
width: 35px;
background: #ffffff;
position: absolute;
display: block;
content: '';
transition: all 300ms ease-in-out;
}
#nav-toggle span:before {
top: -10px;
}
#nav-toggle span:after {
bottom: -10px;
}
#nav-toggle.active span {
background-color: transparent;
}
#nav-toggle.active span:before, #nav-toggle.active span:after {
top: 0;
}
#nav-toggle.active span:before {
transform: rotate(45deg);
}
#nav-toggle.active span:after {
transform: rotate(-45deg);
}
body, html {
height: 100%;
margin: 0;
font-family: 'Montserrat', sans-serif;
}
body {
height: 1000px;
}
.hero-image {
background-image: url(https://stmed.net/sites/default/files/leaves-wallpapers-25246-1391025.jpg);
height: 50%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
/*==========WELCOME-TEXT==========*/
.hero-text {
text-align: center;
color: white;
font-family: 'Slabo 27px', serif;
font-size: 26px;
}
.hero-text h2 {
font-style: italic;
font-size: 22px;
}
@media only screen and (max-width: 450px) {
.hero-text h1 {
font-size: 20px;
font-family: 'Slabo 20px', serif;
}
.hero-text h2 {
font-size: 18px;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section class="navigation">
<div class="nav-container">
<div class="brand">
<a href="#!">image</a>
</div>
<nav>
<div class="nav-mobile"><a id="nav-toggle" href="#!"><span></span></a></div>
<ul class="nav-list">
<li>
<a href="#!">header 10</a>
</li>
<li>
<a href="#!">header 9</a>
<ul class="nav-dropdown">
<li>
<a href="#!">header 8</a>
</li>
<li>
<a href="#!">header 7</a>
</li>
<li>
<a href="#!">header 6</a>
</li>
<li>
<a href="#!">header 5</a>
</li>
<li>
<a href="#!">header 4</a>
</li>
</ul>
</li>
<li>
<a href="#!">header3</a>
</li>
<li>
<a href="#!">header 2</a>
</li>
<li>
<a href="#!">Header 1</a>
</li>
</ul>
</nav>
</div>
</section>
<div class="hero-image">
<div class="hero-text">
<h1>Bring Your Garden And Driveway to life </h1>
<h2>Scroll Down To Learn More</h2>
</div>
</div>