Reputation: 23
I am trying to complete a freecodecamp project. I have a sidebar nav
along with a section-container
. When I set min-width: 600px;
to the section-container
, it works as expected, but when I minimize my window below 600px and click on the navbar links, the section-container
goes underneath the navbar despite there being a margin-left
applied to it. This doesn't happen when min-width is not applied.
Why is this happening, and how do I fix it?
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
line-height: 1.4;
font-size: 1.25rem;
}
.container #main-doc #navbar header {
display: flex;
justify-content: center;
align-items: center;
}
.container #main-doc #navbar header h1 {
margin-left: 0.625rem;
margin-right: 0.625rem;
}
.container #main-doc nav {
position: fixed;
border-right: 2px solid black;
height: 100%;
}
.container #main-doc nav ul:first-of-type {
list-style: none;
}
.container #main-doc nav ul:first-of-type li{
margin-bottom: 0.625rem;
padding-right: 0.625rem;
border-bottom: 2px solid black;
}
.container #main-doc nav ul:first-of-type li a {
text-decoration: none;
color: black;
display: block;
margin-left: 1.25rem;
}
.container #main-doc #section-container {
/* padding: 2.5rem 2.5rem; */
margin-left: 370px;
min-width: 600px;
}
.container #main-doc #section-container .main-section header {
font-size: 1.5rem;
font-family: 'Noto Sans', sans-serif;
font-weight: 700;
margin-bottom: 0.625rem;
}
.container #main-doc #section-container .main-section {
margin-bottom: 2.5rem;
}
.container #main-doc #section-container .main-section p {
margin-left: 1.25rem;
}
.container #main-doc #section-container .main-section ul {
margin-left: 5rem;
}
<div class="container">
<main id="main-doc">
<nav id="navbar">
<header>
<h1>Semantic Elements</h1>
</header>
<ul>
<li style="border-top:2px solid black"><a class="nav-link" href="#New_Semantic_Tags_Added_by_HTML5">New Semantic Tags Added by HTML5</a></li>
<li><a class="nav-link" href="#the_header_element">The <code>header</code> element</a></li>
<li><a class="nav-link" href="#the_main_element">The <code>main</code> element</a></li>
<li><a class="nav-link" href="#the_nav_element">The <code>nav</code> element</a></li>
<li><a class="nav-link" href="#the_article_element">The <code>article</code> element</a></li>
<li><a class="nav-link" href="#the_section_element">The <code>section</code> element</a></li>
<li><a class="nav-link" href="#the_aside_element">The <code>aside</code> element</a></li>
<li><a class="nav-link" href="#the_address_element">The <code>address</code> element</a></li>
<li><a class="nav-link" href="#the_footer_element">The <code>footer</code> element</a></li>
</ul>
</nav>
<div id="section-container">
<section class="main-section" id="New_Semantic_Tags_Added_by_HTML5">
<header>New Semantic Tags Added by HTML5</header>
<p>In this brief tutorial we’ll touch on all of the new tags added as part of HTML5 to define the structure and content of a web page. The elements we’re going to cover in this guide include:</p>
<ul>
<li>header</li>
<li>main</li>
<li>nav</li>
<li>article</li>
<li>section</li>
<li>aside</li>
<li>address</li>
<li>footer</li>
</ul>
<p style="margin-top: 15px;">Using these elements isn’t as complicated as it might appear at first glance, and most are fairly self-explanatory. We’ll make a quick pass over each new element, and then draw up an HTML template you can use these new tags to add rich semantic meaning to your markup.</p>
</section>
<section class="main-section" id="the_header_element">
<header>The <code>header</code> element</header>
<p>The header element is used to contain the content that appears at the top of every page of your website: the logo, tagline, search prompt, and possibly a navigational menu. In most cases, the header element is best positioned as a direct descendant of the body element, but it’s also ok to place it inside the main element if you prefer.</p>
</section>
<section class="main-section" id="the_main_element">
<header>The <code>main</code> element</header>
<p>Use the main element between header and footer elements to contain the primary content of your web page. The main element cannot be a descendant of an article, aside, header, footer, or nav element. Instead, it should be a direct descendant of the body element. Think of it as the direct replacement for the div id="main" you’ve used in the past to wrap up your entire page contents.
It’s also ok to use more than one main element on a webpage. For example, if your blog homepage includes your five most recent posts, it would be appropriate to wrap each post in it’s own main element – or you could wrap each in article tags.</p>
</section>
<section class="main-section" id="the_nav_element">
<header>The <code>nav</code> element</header>
<p>Navigational menus are commonly placed at the top of a web page, in a sidebar, or in the page footer. Wherever you happen to place a navigational menu, wrap it in nav tags. Note that you don’t need to use nav tags for every link, just for blocks of links that provide either sitewide navigation or navigation for a specific part of a website.</p>
</section>
<section class="main-section" id="the_article_element">
<header>The <code>article</code> element</header>
<p>If your website includes blog posts, articles, or any other content that could just as well appear on another website as syndicated content, wrap that content in an article post. You can use an article element just about anywhere other than nested within an address element, but in most cases an article element will be a direct descendant of a main element or of a section element that is a direct descendant of a main element..</p>
</section>
<section class="main-section" id="the_section_element">
<header>The <code>section</code> element</header>
<p>Navigational menus are commonly placed at the top of a web page, in a sidebar, or in the page footer. Wherever you happen to place a navigational menu, wrap it in nav tags. Note that you don’t need to use nav tags for every link, just for blocks of links that provide either sitewide navigation or navigation for a specific part of a website.</p>
</section>
<section class="main-section" id="the_aside_element">
<header>The <code>aside</code> element</header>
<p>If your website contains information that isn’t directly related to the main content of the page, it would be appropriate to wrap that information in aside tags. For example, if you write a post that includes some technical terms, and you add definitions for those terms in a sidebar, it would make sense to wrap those definitions in aside tags. It is also common for the entire sidebar of a blog-type website to be wrapped in aside tags to make it clear that the sidebar is not part of the primary content of the page.</p>
</section>
<section class="main-section" id="the_address_element">
<header>The <code>address</code> element</header>
<p>The address element provides contact information for the nearest parent article or body element that contains it. Use the address element inside an article to provide contact information for the article’s author. Use it outside of an article in the main or footer elements, or as a direct descendant of the body element, to provide contact information for the website’s owner.</p>
</section>
<section class="main-section" id="the_footer_element">
<header>The <code>footer</code> element</header>
<p>The footer appears at the bottom of a section of a document. Typically, the footer is a direct descendant of the body element, but it can also be used within a main element, a section, or an article. The most common use of the footer element is to place it at the bottom of an HTML document to contain things like a copyright notice, links to related content, address information about the owner of the website, and links to administrative things like privacy policies and website’s terms of service.
You may also use the footer element within an article to provide metadata about that particular article. For example, if article tags have been used to wrap a forum post, it would be appropriate to wrap copyright information and the date and time the post was made in a footer element and place it at the bottom of the article.</p>
</section>
<i><a href="https://html.com/document/">Source</a></i>
</div>
</main>
</div>
Upvotes: 1
Views: 196
Reputation: 272
Below I put the min-width:70%;
and I put the nav's width:30%;
. Doing this will have a responsive design where it will always be 70%
and 30%
. When you do min-width: 600px;
you're telling CSS that no matter the screen size, always take up 600px
of space.
Also, I put in a overflow-y:scroll;
in the nav section so that the nav bar's content can be scrolled through if the viewport is not tall enough.
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
line-height: 1.4;
font-size: 1.25rem;
}
.container #main-doc #navbar header {
display: flex;
justify-content: center;
align-items: center;
}
.container #main-doc #navbar header h1 {
margin-left: 0.625rem;
margin-right: 0.625rem;
}
.container #main-doc nav {
position: fixed;
border-right: 2px solid black;
height: 100%;
width: 30%;
overflow-y: scroll;
}
.container #main-doc nav ul:first-of-type {
list-style: none;
}
.container #main-doc nav ul:first-of-type li{
margin-bottom: 0.625rem;
padding-right: 0.625rem;
border-bottom: 2px solid black;
}
.container #main-doc nav ul:first-of-type li a {
text-decoration: none;
color: black;
display: block;
margin-left: 1.25rem;
}
.container #main-doc #section-container {
/* padding: 2.5rem 2.5rem; */
margin-left: 30%;
min-width: 70%;
}
.container #main-doc #section-container .main-section header {
font-size: 1.5rem;
font-family: 'Noto Sans', sans-serif;
font-weight: 700;
margin-bottom: 0.625rem;
}
.container #main-doc #section-container .main-section {
margin-bottom: 2.5rem;
}
.container #main-doc #section-container .main-section p {
margin-left: 1.25rem;
}
.container #main-doc #section-container .main-section ul {
margin-left: 5rem;
}
<div class="container">
<main id="main-doc">
<nav id="navbar">
<header>
<h1>Semantic Elements</h1>
</header>
<ul>
<li style="border-top:2px solid black"><a class="nav-link" href="#New_Semantic_Tags_Added_by_HTML5">New Semantic Tags Added by HTML5</a></li>
<li><a class="nav-link" href="#the_header_element">The <code>header</code> element</a></li>
<li><a class="nav-link" href="#the_main_element">The <code>main</code> element</a></li>
<li><a class="nav-link" href="#the_nav_element">The <code>nav</code> element</a></li>
<li><a class="nav-link" href="#the_article_element">The <code>article</code> element</a></li>
<li><a class="nav-link" href="#the_section_element">The <code>section</code> element</a></li>
<li><a class="nav-link" href="#the_aside_element">The <code>aside</code> element</a></li>
<li><a class="nav-link" href="#the_address_element">The <code>address</code> element</a></li>
<li><a class="nav-link" href="#the_footer_element">The <code>footer</code> element</a></li>
</ul>
</nav>
<div id="section-container">
<section class="main-section" id="New_Semantic_Tags_Added_by_HTML5">
<header>New Semantic Tags Added by HTML5</header>
<p>In this brief tutorial we’ll touch on all of the new tags added as part of HTML5 to define the structure and content of a web page. The elements we’re going to cover in this guide include:</p>
<ul>
<li>header</li>
<li>main</li>
<li>nav</li>
<li>article</li>
<li>section</li>
<li>aside</li>
<li>address</li>
<li>footer</li>
</ul>
<p style="margin-top: 15px;">Using these elements isn’t as complicated as it might appear at first glance, and most are fairly self-explanatory. We’ll make a quick pass over each new element, and then draw up an HTML template you can use these new tags to add rich semantic meaning to your markup.</p>
</section>
<section class="main-section" id="the_header_element">
<header>The <code>header</code> element</header>
<p>The header element is used to contain the content that appears at the top of every page of your website: the logo, tagline, search prompt, and possibly a navigational menu. In most cases, the header element is best positioned as a direct descendant of the body element, but it’s also ok to place it inside the main element if you prefer.</p>
</section>
<section class="main-section" id="the_main_element">
<header>The <code>main</code> element</header>
<p>Use the main element between header and footer elements to contain the primary content of your web page. The main element cannot be a descendant of an article, aside, header, footer, or nav element. Instead, it should be a direct descendant of the body element. Think of it as the direct replacement for the div id="main" you’ve used in the past to wrap up your entire page contents.
It’s also ok to use more than one main element on a webpage. For example, if your blog homepage includes your five most recent posts, it would be appropriate to wrap each post in it’s own main element – or you could wrap each in article tags.</p>
</section>
<section class="main-section" id="the_nav_element">
<header>The <code>nav</code> element</header>
<p>Navigational menus are commonly placed at the top of a web page, in a sidebar, or in the page footer. Wherever you happen to place a navigational menu, wrap it in nav tags. Note that you don’t need to use nav tags for every link, just for blocks of links that provide either sitewide navigation or navigation for a specific part of a website.</p>
</section>
<section class="main-section" id="the_article_element">
<header>The <code>article</code> element</header>
<p>If your website includes blog posts, articles, or any other content that could just as well appear on another website as syndicated content, wrap that content in an article post. You can use an article element just about anywhere other than nested within an address element, but in most cases an article element will be a direct descendant of a main element or of a section element that is a direct descendant of a main element..</p>
</section>
<section class="main-section" id="the_section_element">
<header>The <code>section</code> element</header>
<p>Navigational menus are commonly placed at the top of a web page, in a sidebar, or in the page footer. Wherever you happen to place a navigational menu, wrap it in nav tags. Note that you don’t need to use nav tags for every link, just for blocks of links that provide either sitewide navigation or navigation for a specific part of a website.</p>
</section>
<section class="main-section" id="the_aside_element">
<header>The <code>aside</code> element</header>
<p>If your website contains information that isn’t directly related to the main content of the page, it would be appropriate to wrap that information in aside tags. For example, if you write a post that includes some technical terms, and you add definitions for those terms in a sidebar, it would make sense to wrap those definitions in aside tags. It is also common for the entire sidebar of a blog-type website to be wrapped in aside tags to make it clear that the sidebar is not part of the primary content of the page.</p>
</section>
<section class="main-section" id="the_address_element">
<header>The <code>address</code> element</header>
<p>The address element provides contact information for the nearest parent article or body element that contains it. Use the address element inside an article to provide contact information for the article’s author. Use it outside of an article in the main or footer elements, or as a direct descendant of the body element, to provide contact information for the website’s owner.</p>
</section>
<section class="main-section" id="the_footer_element">
<header>The <code>footer</code> element</header>
<p>The footer appears at the bottom of a section of a document. Typically, the footer is a direct descendant of the body element, but it can also be used within a main element, a section, or an article. The most common use of the footer element is to place it at the bottom of an HTML document to contain things like a copyright notice, links to related content, address information about the owner of the website, and links to administrative things like privacy policies and website’s terms of service.
You may also use the footer element within an article to provide metadata about that particular article. For example, if article tags have been used to wrap a forum post, it would be appropriate to wrap copyright information and the date and time the post was made in a footer element and place it at the bottom of the article.</p>
</section>
<i><a href="https://html.com/document/">Source</a></i>
</div>
</main>
</div>
Upvotes: 1