CSS Tabbed Divs opacity - html

I followed a tutorial online to make this neat little tabbed div content display but I seem to be having an issue when setting the opacity on the background. By doing this it reveals the hidden content. I've tried playing around and setting opacity at differnt layers but I havent had any luck. Here's an example that you can see. Let me know what you guys think
HTML
<div class="tabs">
<div class="tab">
<input type="radio" id="tab-1" name="tab-group-1" checked>
<label for="tab-1">Tab1</label>
<div class="content" id="scrollbar">
<div id="tabcontenttitle"><h1 class="h1titles">title 1</div>
<div id="scrollbar" style="overflow: auto; height: 185px; width: 100%; padding-right: 19px;"> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris vehicula eu ante nec ultrices. Ut fermentum orci sed quam blandit, ut volutpat nunc pharetra. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla massa purus, pellentesque vel tincidunt vitae, adipiscing et dui. Donec imperdiet vestibulum posuere. Sed sed ipsum eget tortor interdum lobortis porta eu nisi. Duis vel purus viverra, congue odio eu, ornare nibh. <br /><br />Vestibulum a congue nisi. Morbi eget magna felis. Donec est nibh, mattis nec faucibus sit amet, dictum at sem. Nulla cursus euismod nunc, scelerisque viverra ligula tempus ac.</p><br />
<p>Nulla facilisi. In nec suscipit quam. In hac habitasse platea dictumst. Phasellus placerat eu augue nec iaculis. Praesent sapien massa, varius nec dolor ac, pulvinar faucibus ipsum. In hac habitasse platea dictumst. Curabitur rhoncus varius leo vel pharetra.</p><br />
<p>Vivamus eget bibendum nulla, vel suscipit arcu. In iaculis, lorem sit amet porta bibendum, mauris purus auctor lorem, in accumsan ipsum massa vel purus. Donec neque justo, posuere sed velit condimentum, tempor elementum arcu. Phasellus rhoncus porta odio et tincidunt. Aliquam facilisis non nisl id molestie. Cras commodo sem ut elementum ultricies. Aliquam gravida, arcu eget vestibulum gravida, leo metus tempor quam, eleifend mollis sapien dui sed justo. </p><br />
<p>Nunc eget odio ac magna facilisis bibendum. Proin eu posuere justo, eu adipiscing arcu. Vivamus et urna accumsan, ultrices diam sed, eleifend odio. Donec consequat lorem nec ipsum scelerisque fermentum.</p></div>
</div>
</div>
<div class="tab">
<input type="radio" id="tab-2" name="tab-group-1">
<label for="tab-2">Tab2</label>
<div class="content">
<div id="tabcontenttitle"><h1 class="h1titles">title 2</div>
<div id="scrollbar" style="overflow: auto; height: 185px; width: 100%; padding-right: 19px;"> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris vehicula eu ante nec ultrices. Ut fermentum orci sed quam blandit, ut volutpat nunc pharetra. Lorem ipsum dolor sit amet, consectetur adipiscing elit. <br /><br />Nulla massa purus, pellentesque vel tincidunt vitae, adipiscing et dui. Donec imperdiet vestibulum posuere. Sed sed ipsum eget tortor interdum lobortis porta eu nisi. Duis vel purus viverra, congue odio eu, ornare nibh. Vestibulum a congue nisi. Morbi eget magna felis. Donec est nibh, mattis nec faucibus sit amet, dictum at sem. Nulla cursus euismod nunc, scelerisque viverra ligula tempus ac.</p><br />
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris vehicula eu ante nec ultrices. Ut fermentum orci sed quam blandit, ut volutpat nunc pharetra. Lorem ipsum dolor sit amet, consectetur adipiscing elit. <br /><br />Nulla massa purus, pellentesque vel tincidunt vitae, adipiscing et dui. Donec imperdiet vestibulum posuere. Sed sed ipsum eget tortor interdum lobortis porta eu nisi. Duis vel purus viverra, congue odio eu, ornare nibh. Vestibulum a congue nisi. Morbi eget magna felis. Donec est nibh, mattis nec faucibus sit amet, dictum at sem. Nulla cursus euismod nunc, scelerisque viverra ligula tempus ac.</p><br />
</div>
</div>
</div>
CSS
#scrollbar::-webkit-scrollbar-track
{
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
background-color: #000;
}
#scrollbar::-webkit-scrollbar
{
width: 12px;
background-color: #F5F5F5;
}
#scrollbar::-webkit-scrollbar-thumb
{
background-color: #cd2429;
}
.tabs {
position: relative;
min-height: 200px; /* This part sucks */
clear: both;
margin-left: 0px;
margin-top: 10px;
}
.tab {
float: left;
}
.tab label {
top: -1px;
font-family: font1;
font-size: 20px;
background: #000;
color: #fff;
padding: 7px;
margin-left: -1px;
position: relative;
left: 1px;
}
.tab [type=radio] {
display: none;
}
.content {
position: absolute;
top: 28px;
left: 0;
right: 0;
bottom: 0;
padding-left: 20px;
padding-right: 20px;
padding-bottom: 20px;
width: 460px; height: 230px;-webkit-border-radius: 5px;
-webkit-border-top-left-radius: 0;
-moz-border-radius: 5px;
-moz-border-radius-topleft: 0;
border-radius: 5px;
border-top-left-radius: 0;color: #fff; background-color: rgba(0,0,0,.6);
line-height: 20px; overflow: hidden; font-family: Tahoma, Geneva, sans-serif; font-size: 12px;
}
[type=radio]:checked ~ label {
background: #cd2429;
z-index: 2;
}
[type=radio]:checked ~ label ~ .content {
z-index: 1;
}
#tabcontenttitle {style="display: block; clear: both; position: relative; padding-bottom: 10px;}
.tabcontenttext {style="overflow: auto; height: 15px; width: 100%; padding-right: 19px;}

In CSS section .content replace background-color: rgba(0,0,0,.6); with background-color: #282828;
The background transparency set to 0.6 reveals the content lying under the displayed layer.
New answer
In section .content replace color: #fff; with color: transparent;.
In section [type=radio]:checked ~ label ~ .content add color: #fff;; after the same section add the following code:
.content * {
visibility: hidden;
}
[type=radio]:checked ~ label ~ .content * {
visibility: visible;
}
This code makes the text color of the underlying layer transparent ( = invisible! ) and hides all the elements inside it.

you can use from background-color: rgba(0,0,0,.5);

Related

Prevent body scrolling when pure CSS menu is open and allow menu to scroll when it spans beyond device height

I have a pure CSS menu that is causing me some issues mostly on small screens/mobile devices.
Issue 1
When the menu is open the background is still scrollable. I would like the focus to be on the menu, and therefore the background would not scroll when the menu is open.
Issue 2
On a small screen the menu items are collapsed by default and expand once clicked on to show submenu. If one or two are expanded and the content goes beyond the devices window there is no way to scroll down to see the content outside of the current window view. If the menu is expanded it needs to be scrollable.
I experimented with the overflow property but can't fix the issue. hoping someone know how. Thanks!
body {
margin: 0;
font-family: serif;
background-color: #f4f4f4;
}
html {
color: #222;
font-size: 1.2em;
line-height: 1;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
/* ==========================================================================
Global Header
========================================================================== */
.global-nav {
/*overflow: hidden;*/
background-color: #FFF;
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 9999;
padding: 28px 0 0 0;
}
.header {
background-color: #fff;
margin: 0 auto;
width: 1170px;
z-index: 3;
clear: both;
}
.header div.menu {
overflow: hidden;
background-color: #fff;
padding: 20px 0 0 0;
-webkit-box-shadow: 0px 3px 3px 0px rgba(136,136,136,1);
-moz-box-shadow: 0px 3px 3px 0px rgba(136,136,136,1);
box-shadow: 0px 3px 3px 0px rgba(136,136,136,1);
z-index: 99999999;
}
.header img {
vertical-align: baseline;
}
.header div.menu ul.menu-links {
margin: 0;
padding: 0;
list-style: none;
}
.menu-col-one {
width: 25%;
float: left;
position: relative;
padding-bottom: 60px;
}
.menu-col-two {
width: 25%;
float: left;
position: relative;
padding-bottom: 60px;
}
.menu-col-three {
width: 25%;
float: left;
position: relative;
padding-bottom: 60px;
}
.menu-col-four {
width: 25%;
float: left;
position: relative;
padding-bottom: 60px;
}
.menu-col-five {
display: none;
}
.header div.menu ul.menu-links li a {
display: block;
padding: 20px 0 0 0;
}
.header .menu {
clear: both;
max-height: 0;
transition: max-height .2s ease-out;
width: 100%;
position: fixed;
left: 0;
}
.header .menu-icon {
cursor: pointer;
display: inline-block;
padding: 31px 32px 25px 0;
position: relative;
}
.header .menu-icon .navicon {
background: #00539D;
display: block;
height: 2px;
position: relative;
transition: background .2s ease-out;
width: 40px;
}
.header .menu-icon .navicon:before, .header .menu-icon .navicon:after {
background: #00539D;
content: '';
display: block;
height: 100%;
position: absolute;
transition: all .2s ease-out;
width: 100%;
}
.header .menu-icon .navicon:before {
top: 12px;
}
.header .menu-icon .navicon:after {
top: -12px;
}
.header .menu-btn {
display: none;
}
.header .menu-btn:checked ~ .menu {
max-height: 100%;
}
.header .menu-btn:checked ~ .menu-icon .navicon {
background: transparent;
}
.header .menu-btn:checked ~ .menu-icon .navicon:before {
transform: rotate(-45deg);
}
.header .menu-btn:checked ~ .menu-icon .navicon:after {
transform: rotate(45deg);
}
.header .menu-btn:checked ~ .menu-icon:not(.steps) .navicon:before, .header .menu-btn:checked ~ .menu-icon:not(.steps) .navicon:after {
top: 0;
}
.ac-container {
width: 1170px;
margin: 40px auto 30px auto;
text-align: left;
}
.ac-container article {
overflow: visible;
padding-right: 30px;
}
.ac-container input {
display: none;
}
.ac-container label {
position: relative;
z-index: 20;
display: block;
cursor: pointer;
font-size: 25px;
}
#media only screen and (max-width: 1169px) {
.header {
margin: 0 2%;
width: 96%;
padding-right: 0;
}
.ac-container {
width: 96%;
padding: 0 2%;
}
}
#media only screen and (max-width: 970px) {
.global-nav {
padding: 14px 0 0 0;
}
.header .menu-icon {
padding: 31px 1% 25px 0;
}
.header-content-right {
display: none;
}
.header div.menu {
margin-top: 0px;
}
.header div.menu ul.menu-links {
margin: 0;
}
.menu-col-one {
width: 100%;
border-bottom: 1px solid #f1f1f1;
margin-left: 0%;
margin-bottom: 30px;
padding-bottom: 25px;
}
.menu-col-two {
width: 100%;
border-bottom: 1px solid #f1f1f1;
margin-bottom: 30px;
padding-bottom: 25px;
}
.menu-col-three {
width: 100%;
border-bottom: 1px solid #f1f1f1;
margin-bottom: 30px;
padding-bottom: 25px;
}
.menu-col-four {
width: 100%;
margin-right: 0%;
margin-bottom: 30px;
padding-bottom: 25px;
}
.menu-col-five {
width: 100%;
margin-right: 0%;
display: block;
}
.header div.menu ul li.list-header {
display: block !important;
}
.header div.menu ul li.list-item {
display: none;
}
.ac-container label {
font-size: 16px;
color: #636c76;
font-weight: bold;
letter-spacing: 0.2px;
}
.ac-container input:checked + label, .ac-container input:checked + label:hover {
color: #454545;
}
.ac-container input + label:after {
content: '';
position: absolute;
width: 24px;
height: 24px;
right: 13px;
top: -6px;
}
.ac-container article {
background: rgba(255, 255, 255, 0.5);
margin-top: -1px;
overflow: hidden;
position: relative;
z-index: 10;
-webkit-transition: max-height 0.3s ease-out, box-shadow 0.6s linear;
-moz-transition: max-height 0.3s ease-out, box-shadow 0.6s linear;
-o-transition: max-height 0.3s ease-out, box-shadow 0.6s linear;
-ms-transition: max-height 0.3s ease-out, box-shadow 0.6s linear;
transition: max-height 0.3s ease-out, box-shadow 0.6s linear;
max-height: 0;
font-size: 14px;
}
.ac-container article a {
color: #636c76;
}
.ac-container article p {
line-height: 23px;
font-size: 14px;
padding: 20px;
}
.ac-container article ul li {
padding: 10px 0;
}
.ac-container article ul li span {
display: none;
}
.ac-container input:checked ~ article {
-webkit-transition: max-height 0.5s ease-in, box-shadow 0.1s linear;
-moz-transition: max-height 0.5s ease-in, box-shadow 0.1s linear;
-o-transition: max-height 0.5s ease-in, box-shadow 0.1s linear;
-ms-transition: max-height 0.5s ease-in, box-shadow 0.1s linear;
transition: max-height 0.5s ease-in, box-shadow 0.1s linear;
max-height: 500px;/*added*/
}
}
<!-- [Start] Header Section-->
<section class="global-nav" role="region" aria-label="globalnav">
<header class="header" role="banner">
<input class="menu-btn" type="checkbox" id="menu-btn" />
<label class="menu-icon" for="menu-btn"><span class="navicon"></span></label>
<div class="menu">
<section class="ac-container">
<div class="menu-col-one">
<input id="ac-1" name="accordion-1" type="checkbox" />
<label for="ac-1">DD 1</label>
<article class="ac-small">
<ul class="menu-links">
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
</ul>
</article>
</div>
<div class="menu-col-two">
<input id="ac-2" name="accordion-1" type="checkbox" />
<label for="ac-2">DD 2</label>
<article class="ac-medium">
<ul class="menu-links">
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
</ul>
</article>
</div>
<div class="menu-col-three">
<input id="ac-3" name="accordion-1" type="checkbox" />
<label for="ac-3">DD 3</label>
<article class="ac-large">
<ul class="menu-links">
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
</ul>
</article>
</div>
<div class="menu-col-four">
<input id="ac-4" name="accordion-1" type="checkbox" />
<label for="ac-4">DD 4</label>
<article class="ac-large">
<ul class="menu-links">
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
</ul>
</article>
</div>
<div class="menu-col-five">
<div class="btn-group">
<button class="btn">Button</button>
<button class="btn">Button</button>
<button class="btn">Button</button>
</div>
</div>
</section>
</div>
</header>
</section>
<!-- [End] Header Section-->
<!-- [Start] Main Content -->
<main role="main">
<p><span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span> Nullam velit nulla, sagittis non massa et, volutpat ullamcorper nunc. Interdum et malesuada fames ac ante ipsum primis in faucibus. Quisque in dui quis justo consectetur feugiat et a dui. Integer eget justo eleifend, mattis lectus dictum, fermentum urna. Integer vitae elit non sem vehicula euismod sed non massa. Sed ac lacus tempus, pharetra lectus vel, vehicula felis. Sed pharetra viverra nisi sed euismod.</p>
<p>Nam sodales, massa non eleifend dignissim, diam felis suscipit eros, at semper diam justo ut arcu. Duis molestie nec nisi a maximus. Vestibulum in congue risus. Suspendisse potenti. Aliquam sodales neque ac pulvinar facilisis. Curabitur a lacinia ante. Mauris tempus risus lorem, vitae fermentum dolor congue in. Fusce at tristique dolor. Etiam pellentesque lectus malesuada risus malesuada luctus. Pellentesque quis quam vulputate, sagittis orci eget, egestas purus. Proin pulvinar felis et risus placerat lacinia.</p>
<p>In condimentum fermentum efficitur. Mauris non eros ac leo aliquam euismod eget ac metus. Aenean nec eros quis orci eleifend scelerisque. Aliquam finibus vestibulum efficitur. Quisque faucibus id tortor ac gravida. Maecenas eros sapien, mollis eu libero id, faucibus viverra velit. Fusce id blandit quam. Nullam vitae mi lorem. Cras vitae tortor placerat, viverra tellus ut, mattis enim. Aenean sit amet ante tortor. Pellentesque et dignissim urna.</p>
<p>Morbi in mollis neque, et elementum libero. Sed luctus, metus a posuere tempor, magna ante tempor leo, tempus ultrices nulla est sit amet ipsum. Curabitur bibendum aliquet erat eget interdum. Duis a egestas mi, et molestie lacus. Quisque in lorem nisi. Nulla vestibulum arcu est. Morbi blandit lacinia eleifend.</p>
<p>Quisque malesuada ex non dui dapibus, vitae pellentesque lacus hendrerit. Pellentesque euismod id elit non auctor. Sed tempus cursus vulputate. Praesent posuere ligula nunc. Fusce libero tellus, semper in justo fringilla, dignissim accumsan nulla. Nunc semper magna metus, sit amet vehicula urna aliquet id. Donec urna sem, pellentesque id justo a, rutrum maximus dui. Fusce vel condimentum purus. Vestibulum ultricies, massa eget aliquet imperdiet, orci quam luctus ante, in ornare tortor dui at lectus. Vivamus eget luctus felis. Sed pretium ornare vulputate. Nam in vulputate nisi. Fusce magna nibh, placerat et nulla eu, vulputate posuere sapien. Suspendisse sagittis enim ut semper efficitur. Fusce dignissim enim sed magna gravida, et pretium erat ultrices. Nulla dui augue, scelerisque vel leo nec, tempor auctor purus. </p>
<p><span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span> Nullam velit nulla, sagittis non massa et, volutpat ullamcorper nunc. Interdum et malesuada fames ac ante ipsum primis in faucibus. Quisque in dui quis justo consectetur feugiat et a dui. Integer eget justo eleifend, mattis lectus dictum, fermentum urna. Integer vitae elit non sem vehicula euismod sed non massa. Sed ac lacus tempus, pharetra lectus vel, vehicula felis. Sed pharetra viverra nisi sed euismod.</p>
<p>Nam sodales, massa non eleifend dignissim, diam felis suscipit eros, at semper diam justo ut arcu. Duis molestie nec nisi a maximus. Vestibulum in congue risus. Suspendisse potenti. Aliquam sodales neque ac pulvinar facilisis. Curabitur a lacinia ante. Mauris tempus risus lorem, vitae fermentum dolor congue in. Fusce at tristique dolor. Etiam pellentesque lectus malesuada risus malesuada luctus. Pellentesque quis quam vulputate, sagittis orci eget, egestas purus. Proin pulvinar felis et risus placerat lacinia.</p>
<p>In condimentum fermentum efficitur. Mauris non eros ac leo aliquam euismod eget ac metus. Aenean nec eros quis orci eleifend scelerisque. Aliquam finibus vestibulum efficitur. Quisque faucibus id tortor ac gravida. Maecenas eros sapien, mollis eu libero id, faucibus viverra velit. Fusce id blandit quam. Nullam vitae mi lorem. Cras vitae tortor placerat, viverra tellus ut, mattis enim. Aenean sit amet ante tortor. Pellentesque et dignissim urna.</p>
<p>Morbi in mollis neque, et elementum libero. Sed luctus, metus a posuere tempor, magna ante tempor leo, tempus ultrices nulla est sit amet ipsum. Curabitur bibendum aliquet erat eget interdum. Duis a egestas mi, et molestie lacus. Quisque in lorem nisi. Nulla vestibulum arcu est. Morbi blandit lacinia eleifend.</p>
<p>Quisque malesuada ex non dui dapibus, vitae pellentesque lacus hendrerit. Pellentesque euismod id elit non auctor. Sed tempus cursus vulputate. Praesent posuere ligula nunc. Fusce libero tellus, semper in justo fringilla, dignissim accumsan nulla. Nunc semper magna metus, sit amet vehicula urna aliquet id. Donec urna sem, pellentesque id justo a, rutrum maximus dui. Fusce vel condimentum purus. Vestibulum ultricies, massa eget aliquet imperdiet, orci quam luctus ante, in ornare tortor dui at lectus. Vivamus eget luctus felis. Sed pretium ornare vulputate. Nam in vulputate nisi. Fusce magna nibh, placerat et nulla eu, vulputate posuere sapien. Suspendisse sagittis enim ut semper efficitur. Fusce dignissim enim sed magna gravida, et pretium erat ultrices. Nulla dui augue, scelerisque vel leo nec, tempor auctor purus. </p>
<p><span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span> Nullam velit nulla, sagittis non massa et, volutpat ullamcorper nunc. Interdum et malesuada fames ac ante ipsum primis in faucibus. Quisque in dui quis justo consectetur feugiat et a dui. Integer eget justo eleifend, mattis lectus dictum, fermentum urna. Integer vitae elit non sem vehicula euismod sed non massa. Sed ac lacus tempus, pharetra lectus vel, vehicula felis. Sed pharetra viverra nisi sed euismod.</p>
<p>Nam sodales, massa non eleifend dignissim, diam felis suscipit eros, at semper diam justo ut arcu. Duis molestie nec nisi a maximus. Vestibulum in congue risus. Suspendisse potenti. Aliquam sodales neque ac pulvinar facilisis. Curabitur a lacinia ante. Mauris tempus risus lorem, vitae fermentum dolor congue in. Fusce at tristique dolor. Etiam pellentesque lectus malesuada risus malesuada luctus. Pellentesque quis quam vulputate, sagittis orci eget, egestas purus. Proin pulvinar felis et risus placerat lacinia.</p>
<p>In condimentum fermentum efficitur. Mauris non eros ac leo aliquam euismod eget ac metus. Aenean nec eros quis orci eleifend scelerisque. Aliquam finibus vestibulum efficitur. Quisque faucibus id tortor ac gravida. Maecenas eros sapien, mollis eu libero id, faucibus viverra velit. Fusce id blandit quam. Nullam vitae mi lorem. Cras vitae tortor placerat, viverra tellus ut, mattis enim. Aenean sit amet ante tortor. Pellentesque et dignissim urna.</p>
<p>Morbi in mollis neque, et elementum libero. Sed luctus, metus a posuere tempor, magna ante tempor leo, tempus ultrices nulla est sit amet ipsum. Curabitur bibendum aliquet erat eget interdum. Duis a egestas mi, et molestie lacus. Quisque in lorem nisi. Nulla vestibulum arcu est. Morbi blandit lacinia eleifend.</p>
<p>Quisque malesuada ex non dui dapibus, vitae pellentesque lacus hendrerit. Pellentesque euismod id elit non auctor. Sed tempus cursus vulputate. Praesent posuere ligula nunc. Fusce libero tellus, semper in justo fringilla, dignissim accumsan nulla. Nunc semper magna metus, sit amet vehicula urna aliquet id. Donec urna sem, pellentesque id justo a, rutrum maximus dui. Fusce vel condimentum purus. Vestibulum ultricies, massa eget aliquet imperdiet, orci quam luctus ante, in ornare tortor dui at lectus. Vivamus eget luctus felis. Sed pretium ornare vulputate. Nam in vulputate nisi. Fusce magna nibh, placerat et nulla eu, vulputate posuere sapien. Suspendisse sagittis enim ut semper efficitur. Fusce dignissim enim sed magna gravida, et pretium erat ultrices. Nulla dui augue, scelerisque vel leo nec, tempor auctor purus. </p>
<!-- [End] Main Content -->
</main>
Quick answer:
Add overflow: auto on the main and .menu
Add height: 100% to html, body, main.
Add max-height: 100% to .menu
Made header smaller by 17px and only displayed box-shadow on the bottom. You'll have to override this for mobile devices where the scrollbar is completely removed, though...
Personally, I would just add a padding at the top of the body, then let the menu slide over the content. It would be the most elegant.
body {
margin: 0;
font-family: serif;
background-color: #f4f4f4;
height: 100%; /* My code */
}
html {
color: #222;
font-size: 1.2em;
line-height: 1;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
height: 100%; /* My code */
overflow: hidden; /* My code */
}
/* My code */
main {
height: 100%;
overflow: auto;
}
/* ==========================================================================
Global Header
========================================================================== */
.global-nav {
/*overflow: hidden;*/
background-color: #FFF;
position: fixed;
top: 0;
left: 0;
width: calc(100% - 17px); /* My code */
z-index: 9999;
padding: 28px 0 0 0;
}
.header {
background-color: #fff;
margin: 0 auto;
width: 1170px;
z-index: 3;
clear: both;
}
.header div.menu {
overflow: hidden;
background-color: #fff;
padding: 20px 0 0 0;
-webkit-box-shadow: 0px 5px 3px -3px rgba(136,136,136,1); /* My code */
-moz-box-shadow: 0px 5px 3px -3px rgba(136,136,136,1); /* My code */
box-shadow: 0px 5px 3px -3px rgba(136,136,136,1); /* My code */
z-index: 99999999;
}
.header img {
vertical-align: baseline;
}
.header div.menu ul.menu-links {
margin: 0;
padding: 0;
list-style: none;
}
.menu-col-one {
width: 25%;
float: left;
position: relative;
padding-bottom: 60px;
}
.menu-col-two {
width: 25%;
float: left;
position: relative;
padding-bottom: 60px;
}
.menu-col-three {
width: 25%;
float: left;
position: relative;
padding-bottom: 60px;
}
.menu-col-four {
width: 25%;
float: left;
position: relative;
padding-bottom: 60px;
}
.menu-col-five {
display: none;
}
.header div.menu ul.menu-links li a {
display: block;
padding: 20px 0 0 0;
}
.header .menu {
clear: both;
max-height: 0;
transition: max-height .2s ease-out;
width: calc(100% - 17px); /* My code */
position: fixed;
left: 0;
}
.header .menu-icon {
cursor: pointer;
display: inline-block;
padding: 31px 32px 25px 0;
position: relative;
}
.header .menu-icon .navicon {
background: #00539D;
display: block;
height: 2px;
position: relative;
transition: background .2s ease-out;
width: 40px;
}
.header .menu-icon .navicon:before, .header .menu-icon .navicon:after {
background: #00539D;
content: '';
display: block;
height: 100%;
position: absolute;
transition: all .2s ease-out;
width: 100%;
}
.header .menu-icon .navicon:before {
top: 12px;
}
.header .menu-icon .navicon:after {
top: -12px;
}
.header .menu-btn {
display: none;
}
.header .menu-btn:checked ~ .menu {
max-height: calc(100% - 20px); /* My code */
overflow: auto; /* My code */
}
.header .menu-btn:checked ~ .menu-icon .navicon {
background: transparent;
}
.header .menu-btn:checked ~ .menu-icon .navicon:before {
transform: rotate(-45deg);
}
.header .menu-btn:checked ~ .menu-icon .navicon:after {
transform: rotate(45deg);
}
.header .menu-btn:checked ~ .menu-icon:not(.steps) .navicon:before, .header .menu-btn:checked ~ .menu-icon:not(.steps) .navicon:after {
top: 0;
}
.ac-container {
width: 1170px;
margin: 40px auto 30px auto;
text-align: left;
}
.ac-container article {
overflow: visible;
padding-right: 30px;
}
.ac-container input {
display: none;
}
.ac-container label {
position: relative;
z-index: 20;
display: block;
cursor: pointer;
font-size: 25px;
}
#media only screen and (max-width: 1169px) {
.header {
margin: 0 2%;
width: 96%;
padding-right: 0;
}
.ac-container {
width: 96%;
padding: 0 2%;
}
}
#media only screen and (max-width: 970px) {
.global-nav {
padding: 14px 0 0 0;
}
.header .menu-icon {
padding: 31px 1% 25px 0;
}
.header-content-right {
display: none;
}
.header div.menu {
margin-top: 0px;
}
.header div.menu ul.menu-links {
margin: 0;
}
.menu-col-one {
width: 100%;
border-bottom: 1px solid #f1f1f1;
margin-left: 0%;
margin-bottom: 30px;
padding-bottom: 25px;
}
.menu-col-two {
width: 100%;
border-bottom: 1px solid #f1f1f1;
margin-bottom: 30px;
padding-bottom: 25px;
}
.menu-col-three {
width: 100%;
border-bottom: 1px solid #f1f1f1;
margin-bottom: 30px;
padding-bottom: 25px;
}
.menu-col-four {
width: 100%;
margin-right: 0%;
margin-bottom: 30px;
padding-bottom: 25px;
}
.menu-col-five {
width: 100%;
margin-right: 0%;
display: block;
}
.header div.menu ul li.list-header {
display: block !important;
}
.header div.menu ul li.list-item {
display: none;
}
.ac-container label {
font-size: 16px;
color: #636c76;
font-weight: bold;
letter-spacing: 0.2px;
}
.ac-container input:checked + label, .ac-container input:checked + label:hover {
color: #454545;
}
.ac-container input + label:after {
content: '';
position: absolute;
width: 24px;
height: 24px;
right: 13px;
top: -6px;
}
.ac-container article {
background: rgba(255, 255, 255, 0.5);
margin-top: -1px;
overflow: hidden;
position: relative;
z-index: 10;
-webkit-transition: max-height 0.3s ease-out, box-shadow 0.6s linear;
-moz-transition: max-height 0.3s ease-out, box-shadow 0.6s linear;
-o-transition: max-height 0.3s ease-out, box-shadow 0.6s linear;
-ms-transition: max-height 0.3s ease-out, box-shadow 0.6s linear;
transition: max-height 0.3s ease-out, box-shadow 0.6s linear;
max-height: 0;
font-size: 14px;
}
.ac-container article a {
color: #636c76;
}
.ac-container article p {
line-height: 23px;
font-size: 14px;
padding: 20px;
}
.ac-container article ul li {
padding: 10px 0;
}
.ac-container article ul li span {
display: none;
}
.ac-container input:checked ~ article {
-webkit-transition: max-height 0.5s ease-in, box-shadow 0.1s linear;
-moz-transition: max-height 0.5s ease-in, box-shadow 0.1s linear;
-o-transition: max-height 0.5s ease-in, box-shadow 0.1s linear;
-ms-transition: max-height 0.5s ease-in, box-shadow 0.1s linear;
transition: max-height 0.5s ease-in, box-shadow 0.1s linear;
max-height: 500px;/*added*/
}
}
<!-- [Start] Header Section-->
<section class="global-nav" role="region" aria-label="globalnav">
<header class="header" role="banner">
<input class="menu-btn" type="checkbox" id="menu-btn" />
<label class="menu-icon" for="menu-btn"><span class="navicon"></span></label>
<div class="menu">
<section class="ac-container">
<div class="menu-col-one">
<input id="ac-1" name="accordion-1" type="checkbox" />
<label for="ac-1">DD 1</label>
<article class="ac-small">
<ul class="menu-links">
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
</ul>
</article>
</div>
<div class="menu-col-two">
<input id="ac-2" name="accordion-1" type="checkbox" />
<label for="ac-2">DD 2</label>
<article class="ac-medium">
<ul class="menu-links">
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
</ul>
</article>
</div>
<div class="menu-col-three">
<input id="ac-3" name="accordion-1" type="checkbox" />
<label for="ac-3">DD 3</label>
<article class="ac-large">
<ul class="menu-links">
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
</ul>
</article>
</div>
<div class="menu-col-four">
<input id="ac-4" name="accordion-1" type="checkbox" />
<label for="ac-4">DD 4</label>
<article class="ac-large">
<ul class="menu-links">
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
<li>Link <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span></li>
</ul>
</article>
</div>
<div class="menu-col-five">
<div class="btn-group">
<button class="btn">Button</button>
<button class="btn">Button</button>
<button class="btn">Button</button>
</div>
</div>
</section>
</div>
</header>
</section>
<!-- [End] Header Section-->
<!-- [Start] Main Content -->
<main role="main">
<p><span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span> Nullam velit nulla, sagittis non massa et, volutpat ullamcorper nunc. Interdum et malesuada fames ac ante ipsum primis in faucibus. Quisque in dui quis justo consectetur feugiat et a dui. Integer eget justo eleifend, mattis lectus dictum, fermentum urna. Integer vitae elit non sem vehicula euismod sed non massa. Sed ac lacus tempus, pharetra lectus vel, vehicula felis. Sed pharetra viverra nisi sed euismod.</p>
<p>Nam sodales, massa non eleifend dignissim, diam felis suscipit eros, at semper diam justo ut arcu. Duis molestie nec nisi a maximus. Vestibulum in congue risus. Suspendisse potenti. Aliquam sodales neque ac pulvinar facilisis. Curabitur a lacinia ante. Mauris tempus risus lorem, vitae fermentum dolor congue in. Fusce at tristique dolor. Etiam pellentesque lectus malesuada risus malesuada luctus. Pellentesque quis quam vulputate, sagittis orci eget, egestas purus. Proin pulvinar felis et risus placerat lacinia.</p>
<p>In condimentum fermentum efficitur. Mauris non eros ac leo aliquam euismod eget ac metus. Aenean nec eros quis orci eleifend scelerisque. Aliquam finibus vestibulum efficitur. Quisque faucibus id tortor ac gravida. Maecenas eros sapien, mollis eu libero id, faucibus viverra velit. Fusce id blandit quam. Nullam vitae mi lorem. Cras vitae tortor placerat, viverra tellus ut, mattis enim. Aenean sit amet ante tortor. Pellentesque et dignissim urna.</p>
<p>Morbi in mollis neque, et elementum libero. Sed luctus, metus a posuere tempor, magna ante tempor leo, tempus ultrices nulla est sit amet ipsum. Curabitur bibendum aliquet erat eget interdum. Duis a egestas mi, et molestie lacus. Quisque in lorem nisi. Nulla vestibulum arcu est. Morbi blandit lacinia eleifend.</p>
<p>Quisque malesuada ex non dui dapibus, vitae pellentesque lacus hendrerit. Pellentesque euismod id elit non auctor. Sed tempus cursus vulputate. Praesent posuere ligula nunc. Fusce libero tellus, semper in justo fringilla, dignissim accumsan nulla. Nunc semper magna metus, sit amet vehicula urna aliquet id. Donec urna sem, pellentesque id justo a, rutrum maximus dui. Fusce vel condimentum purus. Vestibulum ultricies, massa eget aliquet imperdiet, orci quam luctus ante, in ornare tortor dui at lectus. Vivamus eget luctus felis. Sed pretium ornare vulputate. Nam in vulputate nisi. Fusce magna nibh, placerat et nulla eu, vulputate posuere sapien. Suspendisse sagittis enim ut semper efficitur. Fusce dignissim enim sed magna gravida, et pretium erat ultrices. Nulla dui augue, scelerisque vel leo nec, tempor auctor purus. </p>
<p><span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span> Nullam velit nulla, sagittis non massa et, volutpat ullamcorper nunc. Interdum et malesuada fames ac ante ipsum primis in faucibus. Quisque in dui quis justo consectetur feugiat et a dui. Integer eget justo eleifend, mattis lectus dictum, fermentum urna. Integer vitae elit non sem vehicula euismod sed non massa. Sed ac lacus tempus, pharetra lectus vel, vehicula felis. Sed pharetra viverra nisi sed euismod.</p>
<p>Nam sodales, massa non eleifend dignissim, diam felis suscipit eros, at semper diam justo ut arcu. Duis molestie nec nisi a maximus. Vestibulum in congue risus. Suspendisse potenti. Aliquam sodales neque ac pulvinar facilisis. Curabitur a lacinia ante. Mauris tempus risus lorem, vitae fermentum dolor congue in. Fusce at tristique dolor. Etiam pellentesque lectus malesuada risus malesuada luctus. Pellentesque quis quam vulputate, sagittis orci eget, egestas purus. Proin pulvinar felis et risus placerat lacinia.</p>
<p>In condimentum fermentum efficitur. Mauris non eros ac leo aliquam euismod eget ac metus. Aenean nec eros quis orci eleifend scelerisque. Aliquam finibus vestibulum efficitur. Quisque faucibus id tortor ac gravida. Maecenas eros sapien, mollis eu libero id, faucibus viverra velit. Fusce id blandit quam. Nullam vitae mi lorem. Cras vitae tortor placerat, viverra tellus ut, mattis enim. Aenean sit amet ante tortor. Pellentesque et dignissim urna.</p>
<p>Morbi in mollis neque, et elementum libero. Sed luctus, metus a posuere tempor, magna ante tempor leo, tempus ultrices nulla est sit amet ipsum. Curabitur bibendum aliquet erat eget interdum. Duis a egestas mi, et molestie lacus. Quisque in lorem nisi. Nulla vestibulum arcu est. Morbi blandit lacinia eleifend.</p>
<p>Quisque malesuada ex non dui dapibus, vitae pellentesque lacus hendrerit. Pellentesque euismod id elit non auctor. Sed tempus cursus vulputate. Praesent posuere ligula nunc. Fusce libero tellus, semper in justo fringilla, dignissim accumsan nulla. Nunc semper magna metus, sit amet vehicula urna aliquet id. Donec urna sem, pellentesque id justo a, rutrum maximus dui. Fusce vel condimentum purus. Vestibulum ultricies, massa eget aliquet imperdiet, orci quam luctus ante, in ornare tortor dui at lectus. Vivamus eget luctus felis. Sed pretium ornare vulputate. Nam in vulputate nisi. Fusce magna nibh, placerat et nulla eu, vulputate posuere sapien. Suspendisse sagittis enim ut semper efficitur. Fusce dignissim enim sed magna gravida, et pretium erat ultrices. Nulla dui augue, scelerisque vel leo nec, tempor auctor purus. </p>
<p><span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span> Nullam velit nulla, sagittis non massa et, volutpat ullamcorper nunc. Interdum et malesuada fames ac ante ipsum primis in faucibus. Quisque in dui quis justo consectetur feugiat et a dui. Integer eget justo eleifend, mattis lectus dictum, fermentum urna. Integer vitae elit non sem vehicula euismod sed non massa. Sed ac lacus tempus, pharetra lectus vel, vehicula felis. Sed pharetra viverra nisi sed euismod.</p>
<p>Nam sodales, massa non eleifend dignissim, diam felis suscipit eros, at semper diam justo ut arcu. Duis molestie nec nisi a maximus. Vestibulum in congue risus. Suspendisse potenti. Aliquam sodales neque ac pulvinar facilisis. Curabitur a lacinia ante. Mauris tempus risus lorem, vitae fermentum dolor congue in. Fusce at tristique dolor. Etiam pellentesque lectus malesuada risus malesuada luctus. Pellentesque quis quam vulputate, sagittis orci eget, egestas purus. Proin pulvinar felis et risus placerat lacinia.</p>
<p>In condimentum fermentum efficitur. Mauris non eros ac leo aliquam euismod eget ac metus. Aenean nec eros quis orci eleifend scelerisque. Aliquam finibus vestibulum efficitur. Quisque faucibus id tortor ac gravida. Maecenas eros sapien, mollis eu libero id, faucibus viverra velit. Fusce id blandit quam. Nullam vitae mi lorem. Cras vitae tortor placerat, viverra tellus ut, mattis enim. Aenean sit amet ante tortor. Pellentesque et dignissim urna.</p>
<p>Morbi in mollis neque, et elementum libero. Sed luctus, metus a posuere tempor, magna ante tempor leo, tempus ultrices nulla est sit amet ipsum. Curabitur bibendum aliquet erat eget interdum. Duis a egestas mi, et molestie lacus. Quisque in lorem nisi. Nulla vestibulum arcu est. Morbi blandit lacinia eleifend.</p>
<p>Quisque malesuada ex non dui dapibus, vitae pellentesque lacus hendrerit. Pellentesque euismod id elit non auctor. Sed tempus cursus vulputate. Praesent posuere ligula nunc. Fusce libero tellus, semper in justo fringilla, dignissim accumsan nulla. Nunc semper magna metus, sit amet vehicula urna aliquet id. Donec urna sem, pellentesque id justo a, rutrum maximus dui. Fusce vel condimentum purus. Vestibulum ultricies, massa eget aliquet imperdiet, orci quam luctus ante, in ornare tortor dui at lectus. Vivamus eget luctus felis. Sed pretium ornare vulputate. Nam in vulputate nisi. Fusce magna nibh, placerat et nulla eu, vulputate posuere sapien. Suspendisse sagittis enim ut semper efficitur. Fusce dignissim enim sed magna gravida, et pretium erat ultrices. Nulla dui augue, scelerisque vel leo nec, tempor auctor purus. </p>
<!-- [End] Main Content -->
</main>

Border bottom in a horizontal scroll with a white space between them

I have a div with a custom horizontal scroll. I would like to display a border bottom in the horizontal scroll but separated, because I get it without space between them. This is my current code:
div {
overflow-x: auto;
white-space: nowrap;
width: 200px;
}
div::-webkit-scrollbar-track {
border-radius: 10px;
}
div::-webkit-scrollbar {
height: 6px;
border-bottom: 1px solid #ccc;
}
div::-webkit-scrollbar-thumb {
border-radius: 10px;
background-color: #000;
}
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ac dictum ipsum. Vestibulum a ligula magna. Sed id justo eu nibh pharetra hendrerit vel nec ante. Proin ultrices ante quis erat pulvinar maximus. Quisque id arcu odio. Donec sit amet augue
urna. Proin lectus ligula, aliquam a velit eu, molestie tempor ipsum. Ut ac neque aliquet nulla aliquet facilisis. Donec ac ultrices augue. In nec augue ullamcorper, tristique enim a, mollis lectus. Curabitur in sodales erat. Suspendisse at egestas
urna, et elementum arcu. Aliquam dapibus ut neque quis consectetur. Etiam at lectus id odio finibus maximus et a nisi.
</div>
Are you able to edit the HTML?
Can't you just add a wrapper div?
#Wrap{
width:200px;
padding-bottom:6px;
border-bottom: 1px solid #ccc;
}
#Inner {
position:relative;
overflow-x: auto;
white-space: nowrap;
width: 100%;
}
/*Custom Scrollbar*/
#Inner::-webkit-scrollbar-track {
border-radius: 10px;
}
#Inner::-webkit-scrollbar {
height: 6px;
}
#Inner::-webkit-scrollbar-thumb {
border-radius: 10px;
background-color: #000;
}
<div id="Wrap">
<div id="Inner">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ac dictum ipsum. Vestibulum a ligula magna. Sed id justo eu nibh pharetra hendrerit vel nec ante. Proin ultrices ante quis erat pulvinar maximus. Quisque id arcu odio. Donec sit amet augue
urna. Proin lectus ligula, aliquam a velit eu, molestie tempor ipsum. Ut ac neque aliquet nulla aliquet facilisis. Donec ac ultrices augue. In nec augue ullamcorper, tristique enim a, mollis lectus. Curabitur in sodales erat. Suspendisse at egestas
urna, et elementum arcu. Aliquam dapibus ut neque quis consectetur. Etiam at lectus id odio finibus maximus et a nisi.
</div>
</div>
One simple solution: add padding and then the border-bottom
div {
overflow-x: auto;
white-space: nowrap;
width: 200px;
padding: 16px 0px;
border-bottom: 1px solid #000;
}
Another solution consists on adding a wrapper and creating a new div that will be used to have the separated border bottom, something like this:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
div {
overflow-x: auto;
white-space: nowrap;
width: 200px;
}
div::-webkit-scrollbar-track {
border-radius: 10px;
}
div::-webkit-scrollbar {
height: 6px;
border-bottom: 1px solid #ccc;
}
div::-webkit-scrollbar-thumb {
border-radius: 10px;
background-color: #000;
}
.border-bottom{
margin-top: 8px;
border-bottom: 1px solid #000;
}
</style>
</head>
<body>
<div id="content-wrapper">
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ac dictum ipsum. Vestibulum a ligula magna. Sed id justo
eu nibh pharetra hendrerit vel nec ante. Proin ultrices ante quis erat pulvinar maximus. Quisque id arcu odio. Donec
sit amet augue urna. Proin lectus ligula, aliquam a velit eu, molestie tempor ipsum. Ut ac neque aliquet nulla aliquet
facilisis. Donec ac ultrices augue. In nec augue ullamcorper, tristique enim a, mollis lectus. Curabitur in sodales
erat. Suspendisse at egestas urna, et elementum arcu. Aliquam dapibus ut neque quis consectetur. Etiam at lectus
id odio finibus maximus et a nisi.
</div>
<div class="border-bottom"></div>
</div>
</body>
</html>

html css layout zoom drastic change

I have something to ask about html css
I have layout that I want to achieve like picture 1 below
But, if it zoomed in several percentage, it becomes like picture 2 below
what I want is, it stable like picture 1 in any zoom
Here is the code
body {
background-color: #430600;
width: 1280px;
margin: 0 auto;
align-content: center;
padding: 0;
}
header {
position: fixed;
width: 100%;
z-index: 15;
}
main {
float: left;
margin-top: 120px;
}
h1 {
color: white;
text-align: center;
font-style: italic;
z-index: 10;
}
h2 {
color: white;
text-align: center;
}
#section-banner {
}
#section-banner h2 {
position: absolute;
text-align: center;
top: 300px;
left: 0;
width: 100%;
transform: translateY(-50%);
color: white;
font-size: 5em;
font-style: italic;
z-index: 1;
}
#section-aboutus-1 {
color: white;
margin-top: 50px;
text-align: center;
}
#aboutus-1 {
float:left;
}
#aboutus-table {
float:left;
}
#aboutus-image-1 {
float:left;
width: 50%;
}
#aboutus-detail-1 {
float: right;
width: 45%;
text-align: center;
font-size: 1.4em;
margin: 50px 20px 50px 20px;
display: inline-block;
}
#aboutus-detail-2 {
float:left;
width: 45%;
text-align: center;
font-size: 1.4em;
margin: 75px 20px 50px 20px;
display: inline-block;
}
#aboutus-image-2 {
float:right;
width: 49%;
}
#aboutus-detail-3 {
margin: 50px 150px 50px 150px;
float:left;
}
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel='stylesheet' href='index.css?ver=1.0' media='all' />
</head>
<body>
<section id="section-aboutus-1">
<div id="aboutus-image-1">
<img src="https://i.stack.imgur.com/jDg7r.jpg" alt="" />
</div>
<div id="aboutus-detail-1">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean et lectus tincidunt, sollicitudin odio vitae, pretium odio.
<br><br>
Nam tincidunt ornare dolor vitae porttitor. Sed interdum velit sapien, in pharetra velit efficitur sit amet. Aliquam erat volutpat.
<br><br>
Cras in consectetur sem. Curabitur ac velit nibh. Donec ut lectus tellus. Mauris sit amet dignissim eros, imperdiet auctor orci.
<br><br>
In hac habitasse platea dictumst. Nulla finibus nulla ut auctor dapibus. Duis ultricies erat sagittis metus gravida, accumsan laoreet libero tempus. In at semper nisl.
</div>
<div id="aboutus-detail-2">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean et lectus tincidunt, sollicitudin odio vitae, pretium odio.
<br><br>
Nam tincidunt ornare dolor vitae porttitor. Sed interdum velit sapien, in pharetra velit efficitur sit amet. Aliquam erat volutpat.
<br><br>
Cras in consectetur sem. Curabitur ac velit nibh. Donec ut lectus tellus. Mauris sit amet dignissim eros, imperdiet auctor orci.
<br><br>
In hac habitasse platea dictumst. Nulla finibus nulla ut auctor dapibus. Duis ultricies erat sagittis metus gravida, accumsan laoreet libero tempus. In at semper nisl.
</div>
<div id="aboutus-image-2">
<img class="image" src="https://i.stack.imgur.com/6EScx.jpg" alt="" />
</div>
<div id="aboutus-detail-3">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean et lectus tincidunt, sollicitudin odio vitae, pretium odio.
<br><br>
Nam tincidunt ornare dolor vitae porttitor. Sed interdum velit sapien, in pharetra velit efficitur sit amet. Aliquam erat volutpat.
<br><br>
Cras in consectetur sem. Curabitur ac velit nibh. Donec ut lectus tellus. Mauris sit amet dignissim eros, imperdiet auctor orci.
<br><br>
In hac habitasse platea dictumst. Nulla finibus nulla ut auctor dapibus. Duis ultricies erat sagittis metus gravida, accumsan laoreet libero tempus. In at semper nisl.
</div>
</section>
</body>
</html>
Any help appreciated
First, you should improve this HTML code, separating block.
You should put #aboutus-detail-1 and #aboutus-image-1 in a separeted div and in CSS you say:
float: left;
width: 100%;
for those two new divs.
The same for the others #aboutus
would you be interested in using a responsive framework like bootstrap?
https://jsfiddle.net/audetcameron/ggdz2Lnj/ just a quick example
<body style="background:#430600; color:#ffffff">
<div class="container">
<div class="row">
<div class="col-xs-6">
<div id="aboutus-image-1">
<img src="https://i.stack.imgur.com/jDg7r.jpg" alt="" class="img-responsive"/>
</div>
</div>
<div class="col-xs-6">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean et lectus tincidunt, sollicitudin odio vitae, pretium odio.
Nam tincidunt ornare dolor vitae porttitor. Sed interdum velit sapien, in pharetra velit efficitur sit amet. Aliquam erat volutpat.
Cras in consectetur sem. Curabitur ac velit nibh. Donec ut lectus tellus. Mauris sit amet dignissim eros, imperdiet auctor orci.
In hac habitasse platea dictumst. Nulla finibus nulla ut auctor dapibus. Duis ultricies erat sagittis metus gravida, accumsan laoreet libero tempus. In at semper nisl.</p>
</div>
</div>
<div class="row">
<div class="col-xs-6">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean et lectus tincidunt, sollicitudin odio vitae, pretium odio.
Nam tincidunt ornare dolor vitae porttitor. Sed interdum velit sapien, in pharetra velit efficitur sit amet. Aliquam erat volutpat.
Cras in consectetur sem. Curabitur ac velit nibh. Donec ut lectus tellus. Mauris sit amet dignissim eros, imperdiet auctor orci.
In hac habitasse platea dictumst. Nulla finibus nulla ut auctor dapibus. Duis ultricies erat sagittis metus gravida, accumsan laoreet libero tempus. In at semper nisl.</p>
</div>
<div class="col-xs-6">
<div id="aboutus-image-2">
<img class="image" src="https://i.stack.imgur.com/6EScx.jpg" alt="" class="img-responsive"/>
</div>
</div>
</div>
</div>
</body>

Floated image overflows parent div

I'm trying to float:right; image next to paragraph <p>, which are nested together in <div> container. The problem is that the parent <div> resize its height with the size of the text in the paragraph, that's good, but floated right image overflows the div, and same <div> didn't resize itself according to the image height.
.container {
width: 70%;
background-color: #777;
margin: 0 auto;
padding: 25px;
}
.content {
width: 100%;
height: auto;
float: left;
}
.content .container {
width: 70%;
height: auto;
background-color: white;
/*
overflow: hidden; /* Try later without overflow. (autoportrait.jpg overflow .content .container
*/
}
.autoportrait {
width: 20%;
height: 20%;
/*
max-width:205px;
max-height:265px;
margin-bottom: 25px;
*/
padding: 10px 10px 10px 10px;
border: solid;
border-width: 2px;
float: right;
clear: both;
}
<div class="content">
<div class="container">
<!--
<main>
<section>
-->
<img class="autoportrait" src="autoportrait.jpg" alt="Autoportrait of me">
<h2>Post title</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu purus et enim eleifend fringilla. Cras nec tortor elementum, vestibulum orci id, congue nisl. Fusce ornare ac turpis sit amet tincidunt. Phasellus vel magna ut massa tempus ultricies.
Etiam erat libero, molestie vitae scelerisque quis, consequat eget lorem. Nulla finibus felis non mi viverra efficitur. Proin eget lobortis libero. Fusce aliquam eros sed placerat viverra. Nulla venenatis, nulla sit amet suscipit vulputate, sem
mauris rutrum erat, id pharetra dui nunc at dui. Morbi dignissim luctus maximus. Cras vitae ornare risus. Sed accumsan vitae eros ac placerat. Proin commodo non orci nec consectetur. Nunc posuere, enim a lobortis ultrices, augue ex ultrices ante,
nec consectetur elit leo a ligula. Mauris pellentesque massa nisl, non pellentesque ex pulvinar eu.
</p>
<!--
</section>
</main>
-->
</div>
</div>
I tried to use overflow: hidden; , but that works only for a single "post". When I try to put a second one, the same problem appears and length of the images that flows out of the 'content container' doubles.
I'm newbie in HTML/CSS and the code I write it's for my own knowledge. So I'll be grateful if we figure out something.
Greetings from Varna, Bulgaria!
Make the div to clear it's children using :after pseudo class.
.container{
width: 70%;
background-color: #777;
margin: 0 auto;
padding: 25px;
border:1px solid red;
}
.content{
width: 100%;
height: auto;
float: left;
}
.content .container {
width: 70%;
height: auto;
background-color: white;
/*overflow: hidden; /* Try later without overflow. (autoportrait.jpg overflow .content .container) */
}
.autoportrait{
width: 20%;
height: 20%;
/*max-width:205px;
max-height:265px;
margin-bottom: 25px;*/
padding: 10px 10px 10px 10px;
border: solid;
border-width: 2px;
float: right;
clear:both;
}
.container:after {
visibility: hidden;
display:table;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
<div class="content">
<div class="container">
<!--<main>
<section>-->
<img class="autoportrait" src="http://images.financialexpress.com/2015/12/Lead-image.jpg" alt="Autoportrait of me">
<h2>Post title</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu purus et enim eleifend fringilla.
</p>
<!--</section>
</main>-->
</div>
<div class="container">
<!--<main>
<section>-->
<img class="autoportrait" src="http://images.financialexpress.com/2015/12/Lead-image.jpg" alt="Autoportrait of me">
<h2>Post title</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu purus et enim eleifend fringilla.
Cras nec tortor elementum, vestibulum orci id, congue nisl. Fusce ornare ac turpis sit amet tincidunt.
Phasellus vel magna ut massa tempus ultricies. Etiam erat libero, molestie vitae scelerisque quis, consequat eget lorem.
Nulla finibus felis non mi viverra efficitur. Proin eget lobortis libero. Fusce aliquam eros sed placerat viverra.
Nulla venenatis, nulla sit amet suscipit vulputate, sem mauris rutrum erat, id pharetra dui nunc at dui.
Morbi dignissim luctus maximus. Cras vitae ornare risus. Sed accumsan vitae eros ac placerat.
Proin commodo non orci nec consectetur. Nunc posuere, enim a lobortis ultrices, augue ex ultrices ante, nec consectetur elit leo a ligula.
Mauris pellentesque massa nisl, non pellentesque ex pulvinar eu.
</p>
<!--</section>
</main>-->
</div>
</div>
Simplest solution is to use overflow: hidden; on .content .container.
I know you said you attempted it previously and even had it commented out in .content .container but it's working for me. Perhaps the issue was where/how you placed the second article in your markup.
.container {
width: 70%;
background-color: #777;
margin: 0 auto;
padding: 25px;
}
.content {
width: 100%;
height: auto;
float: left;
}
.content .container {
width: 70%;
height: auto;
background-color: white;
overflow: hidden;
border: 1px solid #ccc;
}
.autoportrait {
width: 20%;
height: 20%;
/*
max-width:205px;
max-height:265px;
margin-bottom: 25px;
*/
padding: 10px 10px 10px 10px;
border: solid;
border-width: 2px;
float: right;
clear: both;
}
<div class="content">
<div class="container">
<img class="autoportrait" src="http://placehold.it/300x500/fc0/" alt="Autoportrait of me">
<h2>Post title</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu purus et enim eleifend fringilla. Cras nec tortor elementum, vestibulum orci id, congue nisl. Fusce ornare ac turpis sit amet tincidunt. Phasellus vel magna ut massa tempus ultricies.
Etiam erat libero, molestie vitae scelerisque quis, consequat eget lorem. Nulla finibus felis non mi viverra efficitur. Proin eget lobortis libero. Fusce aliquam eros sed placerat viverra. Nulla venenatis, nulla sit amet suscipit vulputate, sem
mauris rutrum erat, id pharetra dui nunc at dui. Morbi dignissim luctus maximus. Cras vitae ornare risus. Sed accumsan vitae eros ac placerat. Proin commodo non orci nec consectetur. Nunc posuere, enim a lobortis ultrices, augue ex ultrices ante,
nec consectetur elit leo a ligula. Mauris pellentesque massa nisl, non pellentesque ex pulvinar eu.
</p>
</div>
<div class="container">
<img class="autoportrait" src="http://placehold.it/300x500/fc0/" alt="Autoportrait of me">
<h2>Post title</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu purus et enim eleifend fringilla. Cras nec tortor elementum, vestibulum orci id, congue nisl. Fusce ornare ac turpis sit amet tincidunt. Phasellus vel magna ut massa tempus ultricies.
Etiam erat libero, molestie vitae scelerisque quis, consequat eget lorem. Nulla finibus felis non mi viverra efficitur. Proin eget lobortis libero. Fusce aliquam eros sed placerat viverra. Nulla venenatis, nulla sit amet suscipit vulputate, sem
mauris rutrum erat, id pharetra dui nunc at dui. Morbi dignissim luctus maximus. Cras vitae ornare risus. Sed accumsan vitae eros ac placerat. Proin commodo non orci nec consectetur. Nunc posuere, enim a lobortis ultrices, augue ex ultrices ante,
nec consectetur elit leo a ligula. Mauris pellentesque massa nisl, non pellentesque ex pulvinar eu.
</p>
<!--
</section>
</main>
-->
</div>
</div>

Underline next to text keep them apart

I am trying to implement the following:
You will see there is text and then a line to its side. I am trying to make the line remain the same distance from the text as the screen decreases in size. This works OK, but when the screen gets smaller the line goes into the 'Test Border' part.
See code below as to how I have implemented this. Perhaps I should be taking a different approach.
Also, a jsfiddle here for your convenience.
h3 {
font-size: 26px;
color: #000 !important;
max-width: 90px;
display: inline-block;
padding-bottom: 15px;
width: 8%;
}
.underline {
display: inline-block;
border-bottom: 1px solid #c6bcb6;
width: 90%;
}
<h3>Test Border</h3>
<div class="underline"></div>
You can display both blocks as table and specify first block fixed width (as it's only text that does not change).
.wrapper {
display: table;
width: 100%;
vertical-align: bottom;
padding-bottom: 15px;
table-layout: fixed;
}
h3 {
font-size: 26px;
color: #000 !important;
max-width: 90px;
display: table-cell;
width: 85px;
}
.underline {
display: table-cell;
border-bottom: 1px solid #c6bcb6;
width: 100%;
position: relative;
top: -12px;
}
<div class="wrapper">
<h3>Test Border</h3>
<div class="underline"></div>
</div>
I'd probably use flex box like this.
.border {
display: flex;
}
.border .string {
font-weight: bold;
font-size: 26px;
flex: 0 1;
}
.border .line {
border-bottom: 1px solid #c6bcb6;
flex: 1;
margin: 0 5px 0 10px;
transform: translate(0, -6px);
}
<div class="border">
<span class="string">Test String</span>
<div class="line"></div>
</div>
This will make the title as wide as the longest unbroken work, and the border will fill up the rest of the space.
Here's what it looks like with paragraphs between each header (an almost real world example)
.border {
display: flex;
}
.border .string {
font-weight: bold;
font-size: 26px;
flex: 0 1;
}
.border .line {
border-bottom: 1px solid #c6bcb6;
flex: 1;
margin: 0 5px 0 5px;
transform: translate(0, -6px);
}
<div class="border">
<span class="string">Lorem ipsum dolor</span>
<div class="line"></div>
</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In mollis metus at semper laoreet. Vestibulum vitae lectus ut justo consequat dignissim et in eros. Duis aliquam, ipsum et imperdiet venenatis, ipsum augue scelerisque ante, eu lacinia dui metus
sed lectus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aliquam eu risus a nibh vulputate consectetur. Phasellus id lectus tempor, cursus arcu ut, suscipit augue. Etiam aliquam lobortis semper. Vestibulum dui arcu, faucibus vel suscipit
sed, fermentum sed purus. Vivamus pharetra orci aliquam ligula imperdiet elementum a non tortor. Donec nisl enim, condimentum id nulla quis, vulputate interdum felis. Pellentesque molestie congue urna, eget ultricies est aliquet in. Aenean convallis
magna dolor, vitae facilisis nibh euismod et.
</p>
<div class="border">
<span class="string">Etiam quis molestie</span>
<div class="line"></div>
</div>
<p>
Etiam quis molestie libero. In vitae massa cursus, commodo lectus vel, vehicula felis. Nam venenatis tortor et diam faucibus, vel ullamcorper orci placerat. Mauris at aliquet nunc, quis eleifend turpis. Mauris ultricies at mi ac bibendum. Lorem ipsum
dolor sit amet, consectetur adipiscing elit. Nulla metus enim, volutpat ut magna sed, dignissim tincidunt lorem. Nam nec tempor urna. Nam eget quam elit. Pellentesque condimentum turpis consequat turpis rhoncus vestibulum. Curabitur efficitur dapibus
tortor ac bibendum. Donec risus nibh, dignissim vel sapien vel, fermentum scelerisque velit. Ut posuere finibus erat, nec bibendum nunc faucibus at.
</p>
<div class="border">
<span class="string">Phasellus sed orci</span>
<div class="line"></div>
</div>
<p>
Phasellus sed orci eget urna commodo luctus a sed felis. Aliquam erat volutpat. Quisque sit amet volutpat magna. Etiam vestibulum, velit sit amet efficitur consectetur, tortor velit consectetur velit, et facilisis ex dolor sit amet quam. Fusce tristique
lorem eget dapibus malesuada. Suspendisse iaculis est nec urna sollicitudin, tincidunt vehicula justo pellentesque. Morbi nulla lorem, tempus a interdum vel, fringilla ut elit. Vestibulum sed neque sed lorem viverra luctus. Suspendisse sapien ipsum,
ultrices vitae posuere eget, tristique sit amet augue. Nam suscipit, dolor et lacinia vulputate, erat nunc lacinia nibh, vel posuere nisl nunc eget enim. Vestibulum suscipit lorem risus, id feugiat sem molestie ac. Integer consectetur nunc sed lacinia
commodo. Quisque cursus purus nec dui euismod, nec porttitor nibh fermentum. Nunc tellus mauris, accumsan vitae tincidunt sit amet, ultricies in elit. Donec elementum libero ipsum, sit amet aliquam tortor volutpat eget. Pellentesque pretium dictum ligula.
</p>
<div class="border">
<span class="string">Fusce ultricies ante</span>
<div class="line"></div>
</div>
<p>
Fusce ultricies ante ut orci laoreet, in luctus quam eleifend. Integer nisl purus, pharetra sit amet ligula id, porta porta risus. Etiam nec varius risus, eget euismod risus. Vivamus pharetra purus vitae turpis ultrices ullamcorper. Proin vestibulum,
tortor id blandit pharetra, sapien augue dictum elit, a efficitur urna magna at lorem. Donec sollicitudin, purus sed pharetra iaculis, dolor mauris pretium est, in vestibulum massa odio vitae sapien. Curabitur scelerisque felis dui, non molestie nisl
viverra in. Integer tempor nec risus quis vulputate. Nulla facilisi. Pellentesque ipsum elit, lacinia et consectetur id, gravida ut arcu. Maecenas vestibulum faucibus rutrum. Duis at egestas purus. Proin ac congue nisl, id placerat turpis. Aenean ac
nisl at odio efficitur convallis sit amet quis ipsum. Mauris scelerisque aliquet libero, nec dapibus lectus.
</p>
I think the best solution is change the markup, because with your code the text in h3 tag could be bigger than your max-width (in fact, it is). Something like this:
.textline {
display: table;
}
h3 {
font-size: 26px;
color: #000 !important;
display: table-cell;
width: 9%;
margin-right: 1%;
vertical-align: bottom;
}
.underline {
display: table-cell;
border-bottom: 1px solid #c6bcb6;
width: 90%;
position: relative;
top: -7px;
}
<div class="textline">
<h3>Test border</h3>
<div class="underline"></div>
</div>
When you use percentages you have to take into account the fixed measures of the other elements, width, margins, borders... Not the same 90% of a 1000px screen that one of 500px, the remaining space is less.
You can use calc to solve this issues:
h3 {
font-size: 26px;
color: #000 !important;
width: 95px;
display: inline-block;
padding-bottom: 15px;
}
.underline {
display: inline-block;
border-bottom: 1px solid #c6bcb6;
width: calc(100% - 100px);
}
<h3>Test Border</h3>
<div class="underline"></div>
You could try using a table display, with the text and line each having their own cell:
<div class="div-row">
<div class="div-cell"><h3>Test Border</h3></div>
<div class="div-cell underline"></div>
<div>
CSS:
.div-row {
display: table-row;
width: 100%;
}
.div-cell {
display: table-cell;
}
I haven't tested this, but the div containing the line should automatically shrink to the available width as your resize the browser window (or as you go from desktop to mobile).
If you want, you could also set a fixed width to the div containing the text.
You can try calc() property and it will work...
Check this fiddle here
What you have to do,
h3 {
font-size: 26px;
display: inline-block;
max-width:90px;
margin-right:10px;
}
.underline {
display: inline-block;
border-bottom: 1px solid #c6bcb6;
width: calc(100% - 104px);
}
Try the below CSS:
h3 {
font-size: 26px;
color: #000 !important;
display: inline-block;
padding-bottom: 15px;
}
.underline {
border-bottom: 1px solid #C6BCB6;
width: 90%;
}