Text no overflow - html

I'm not entirely sure how to phrase this question, but I'll give it a try.
I have a website set up with a side navigation menu. When the menu is opened, the body content is pushed all the way off screen making the text unreadable. I want to know what css property I need to set to make the text overflow onto the next line.
An example of this can be seen in the W3Schools. When the menu is opened, the text does not disappear behind the screen.
CSS
html,
body {
height: 100%;
font-family: 'Ubuntu', sans-serif;
}
body {
padding-top: 70px;
}
body.push {
overflow-x: hidden;
}
p {
color: red;
word-wrap: break-word;
}
.navbar-custom {
border-radius: 0;
transition: margin-left 0.5s;
transition: 0.5s;
padding-bottom: 6px;
background-color: transparent;
border-bottom: 1px solid #e5e5e5;
}
.navbar-custom a {
transition: 0.5s;
color: black;
}
.navbar-custom.color {
background-color: white;
}
.navbar-custom.color a {
color: black;
}
.navbar-custom.push {
margin-left: 300px;
background-color: white;
border-bottom: 1px solid #e5e5e5;
}
.navbar-custom.push a {
color: black;
}
.row {
text-align: center;
}
#main {
padding-top: 50px;
transition: margin-left 0.5s;
}
#main.push {
margin-left: 300px;
}
#sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
overflow-x: hidden;
overflow-y: auto;
padding-top: 40px;
transition: 0.5s;
font-size: 15px;
background-color: white;
}
#sidenav li {
border-bottom: 1px solid #e5e5e5;
}
#sidenav a {
padding: 15px 8px 20px 32px;
text-decoration: none;
color: #818181;
display: block;
transition: 0.3s;
}
#sidenav i {
padding: 15px 8px 20px 10px;
text-decoration: none;
display: inline;
overflow-x: hidden;
}
#sidenav a:hover,
#sidenav .offcanvas a:focus {
text-decoration: none;
color: #ffcc00;
}
#sidenav .social {
text-align: center;
padding: 15px 8px 20px 32px;
}
#sidenav .social i:hover {
transition: 0.3s;
color: #ffcc00;
}
#sidenav #nav {
position: absolute;
top: 0;
width: 300px;
margin: 0;
padding: 0;
list-style: none;
}
#sidenav.toggled {
width: 300px;
border-right: 1px solid #e5e5e5;
}
#media screen and (max-height: 450px) {
#sidenav {
padding-top: 15px;
}
#sidenav a {
font-size: 18px;
}
}
#media screen and (max-width: 500px) {
#main.push {
margin-left: 200px;
}
#sidenav .social {
text-align: left;
}
#sidenav.toggled {
width: 200px;
}
.navbar-custom.push {
margin-left: 200px;
}
}
HTML
<section id="sidenav">
<ul id="nav">
<li class="social">
<i class="fa fa-envelope"><a href="#" class="hidden-sm hidden-md hidden-lg"><span
class="fa fa-envelope"></span></a></i>
<i class="fa fa-github"><a target="_blank" href="#" class="hidden-sm hidden-md hidden-lg"><span
class="fa fa-github"></span></a></i>
<i class="fa fa-linkedin"><a target="_blank" href="#"
class="hidden-sm hidden-md hidden-lg"><span class="fa fa-linkedin"></span></a></i>
</li>
<li>Home <span class="glyphicon glyphicon-home"></span></li>
<li>Portfolio <span class="fa fa-folder-open"></span></li>
<li><a target="_blank" href="#">Resume <span class="fa fa-file"></span> </a>
</li>
</ul>
</section>
<nav class="navbar navbar-custom navbar-fixed-top">
<section class="container">
<section class="navbar-header">
<a onclick="toggleMenu()" class="navbar-brand">Menu <i class="fa fa-bars" aria-hidden="true"></i></a>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</section>
</section>
</nav>
<section id="main">
<section class="container">
<p>
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
</p>
</section>
</section>
JS
var main = $("#main");
var sidenav = $("#sidenav");
var body = $("body");
var navbarFixed = $(".navbar-fixed-top");
var navbar = $(".navbar-custom");
function toggleMenu() {
main.toggleClass("push");
sidenav.toggleClass("toggled");
body.toggleClass("push");
navbarFixed.toggleClass("push");
};

Related

Flex navigation hamburger pushing Flex content when expanded

I have created a web page using flexbox and have included a responsive flex-navigation bar. However, when the hamburger is expanded it pushes the rest of the page down with it. I have tried positioning the .active class to absolute on the "display block" and z-index of 10000, but these do not help.I have also tried wrapping the nav inside the row flex container but that ruined the rest of the layout.
Have considered the the js fiddle found at this link:http://jsfiddle.net/hRKgV/ but it does not have a flex box layout and I am wondering if floats are true to the concept of flexbox as it also removes that element from the normal flow of the document?
Any suggestions would be greatful!
Here is the code for the index page:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Flex</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style type="text/css">
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: Arial;
background-color: #faf6bf;
}
.header {
background-image: url("images/index.jpg");
max-width: 100%;
height: auto;
background-color: #cccccc;
height: 500px;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
box-shadow: 2px 2px 5px purple;
}
.hero-text {
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
font-size: 30px;
}
#media screen and (max-width: 700px) {
h1 {
font-size: 40px;
}
h3 {
font-size: 26px;
}
}
.navbar {
position: relative;
font-size: 18px;
background-color: navy;
border: 1px solid rgba(0, 0, 0, 0.2);
padding-bottom: 10px;
clear: both;
}
.main-nav {
list-style-type: none;
display: none;
}
.nav-links,
.logo {
text-decoration: none;
color: rgba(255, 255, 255, 0.7);
}
.main-nav li {
text-align: center;
margin: 15px auto;
position:
}
.logo {
display: inline-block;
font-size: 22px;
margin-top: 10px;
margin-left: 20px;
}
.navbar-toggle {
position: absolute;
top: 10px;
right: 20px;
cursor: pointer;
color: rgba(255, 255, 255, 0.8);
font-size: 24px;
}
.active {
display: block;
}
#media screen and (min-width: 768px) {
.navbar {
display: flex;
justify-content: space-between;
padding-bottom: 0;
height: 70px;
align-items: center;
}
.main-nav {
display: flex;
margin-right: 30px;
flex-direction: row;
justify-content: flex-end;
}
.nav-links {
margin-left: 40px;
}
.logo {
margin-top: 0;
}
.navbar-toggle {
display: none;
}
.logo:hover,
.nav-links:hover {
color: rgba(255, 255, 255, 1);
}
}
.row {
display: flex;
margin-left: 80px;
margin-right: 80px;
flex-wrap: wrap;
}
.fakeimg {
background-color: #faf6bf;
width: 100%;
padding: 20px;
}
.side {
-webkit-flex: 20%;
-ms-flex: 20%;
flex: 20%;
background-color: orange;
color: white;
padding: 20px;
}
.side2 {
-webkit-flex: 20%;
-ms-flex: 20%;
flex: 20%;
background-color: orange;
color: white;
padding: 50px;
}
.main {
flex: 60%;
background-color: #fffcc7;
padding: 20px;
}
.footer {
background-color: brown;
text-align: center;
color: white;
padding: 20px;
}
#media (max-width: 700px) {
.row {
flex-direction: column;
}
}
</style>
</head>
<body>
<nav class="navbar">
<span class="navbar-toggle" id="js-navbar-toggle">
<i class="fa fa-bars"></i> </span>
logo
<ul class="main-nav" id="js-menu">
<li>
Home
</li>
<li>
Products
</li>
<li>
About Us
</li>
<li>
Contact Us
</li>
<li>
Blog
</li>
</ul>
</nav>
<script type="text/javascript">
let mainNav = document.getElementById('js-menu');
let navBarToggle = document.getElementById('js-navbar-toggle');
navBarToggle.addEventListener('click', function() {
mainNav.classList.toggle('active');
});
</script>
<div class="header">
<div class="hero-text">
<h1>I am Jane Doe</h1>
<h3>And I'm a Photographer</h3>
<button>Hire me</button>
</div>
</div>
<div class="row">
<div class="side">
<h2>About Me</h2>
<h5>Photo of me:</h5>
<div class="fakeimg" style="height:200px;">Image</div>
<p>Some text about me in culpa qui officia deserunt mollit anim..</p>
<h3>More Text</h3>
<p>Lorem ipsum dolor sit ame.</p>
<div class="fakeimg" style="height:60px;">Image</div><br>
<div class="fakeimg" style="height:60px;">Image</div><br>
<div class="fakeimg" style="height:60px;">Image</div>
</div>
<div class="main">
<h2>TITLE HEADING</h2>
<h5>Title description, Dec 7, 2017</h5>
<div class="fakeimg" style="height:200px;">Image</div>
<p>Some text..</p>
<p>Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.</p>
<br>
<h2>TITLE HEADING</h2>
<h5>Title description, Sep 2, 2017</h5>
<div class="fakeimg" style="height:200px;">Image</div>
<p>Some text..</p>
<p>Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.</p>
</div>
<div class="side2">
<h4>follow me on socila media:</h4><br />
<ul>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</div>
<script type="text/javascript">
let mainNav = document.getElementById('js-menu');
let navBarToggle = document.getElementById('js-navbar-toggle');
navBarToggle.addEventListener('click', function() {
mainNav.classList.toggle('active');
});
</script>
<!-- Footer -->
<div class="footer">
<h2>Footer</h2>
</div>
</body>
</html>
Is it something like this you're looking for:
const nav = document.getElementById('navbar');
const navBarToggle = document.getElementById('js-navbar-toggle');
navBarToggle.addEventListener('click', () => {
nav.classList.toggle('active');
});
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: Arial;
background-color: #faf6bf;
position: relative;
}
.header {
background-image: url("images/index.jpg");
max-width: 100%;
height: auto;
background-color: #cccccc;
height: 500px;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
box-shadow: 2px 2px 5px purple;
}
.hero-text {
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
font-size: 30px;
}
#media screen and (max-width: 700px) {
h1 {
font-size: 40px;
}
h3 {
font-size: 26px;
}
}
.navbar {
position: absolute;
z-index: 10;
width: 100%;
height: 3rem;
font-size: 18px;
background-color: navy;
border: 1px solid rgba(0, 0, 0, 0.2);
padding-bottom: 10px;
clear: both;
overflow: hidden;
transition: height 250ms ease-in;
}
.main-nav {
display: block;
list-style-type: none;
width: 100%;
}
.nav-links,
.logo {
text-decoration: none;
color: rgba(255, 255, 255, 0.7);
}
.main-nav li {
text-align: center;
margin: 15px auto;
}
.logo {
display: inline-block;
font-size: 22px;
margin-top: 10px;
margin-left: 20px;
}
.navbar-toggle {
position: absolute;
top: 10px;
right: 20px;
cursor: pointer;
color: rgba(255, 255, 255, 0.8);
font-size: 24px;
}
.active {
height: 18rem;
}
#media screen and (min-width: 768px) {
.navbar {
display: flex;
justify-content: space-between;
padding-bottom: 0;
height: 60px;
align-items: center;
}
.main-nav {
display: flex;
margin-right: 30px;
flex-direction: row;
justify-content: flex-end;
}
.nav-links {
margin-left: 40px;
}
.logo {
margin-top: 0;
}
.navbar-toggle {
display: none;
}
.logo:hover,
.nav-links:hover {
color: rgba(255, 255, 255, 1);
}
}
.row {
display: flex;
margin-left: 80px;
margin-right: 80px;
flex-wrap: wrap;
}
.fakeimg {
background-color: #faf6bf;
width: 100%;
padding: 20px;
}
.side {
-webkit-flex: 20%;
-ms-flex: 20%;
flex: 20%;
background-color: orange;
color: white;
padding: 20px;
}
.side2 {
-webkit-flex: 20%;
-ms-flex: 20%;
flex: 20%;
background-color: orange;
color: white;
padding: 50px;
}
.main {
flex: 60%;
background-color: #fffcc7;
padding: 20px;
}
.footer {
background-color: brown;
text-align: center;
color: white;
padding: 20px;
}
#media (max-width: 700px) {
.row {
flex-direction: column;
}
}
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<nav class="navbar" id="navbar">
<span class="navbar-toggle" id="js-navbar-toggle">
<i class="fa fa-bars"></i> </span>
logo
<ul class="main-nav" id="js-menu">
<li>
Home
</li>
<li>
Products
</li>
<li>
About Us
</li>
<li>
Contact Us
</li>
<li>
Blog
</li>
</ul>
</nav>
<div class="header">
<div class="hero-text">
<h1>I am Jane Doe</h1>
<h3>And I'm a Photographer</h3>
<button>Hire me</button>
</div>
</div>
<div class="row">
<div class="side">
<h2>About Me</h2>
<h5>Photo of me:</h5>
<div class="fakeimg" style="height:200px;">Image</div>
<p>Some text about me in culpa qui officia deserunt mollit anim..</p>
<h3>More Text</h3>
<p>Lorem ipsum dolor sit ame.</p>
<div class="fakeimg" style="height:60px;">Image</div><br>
<div class="fakeimg" style="height:60px;">Image</div><br>
<div class="fakeimg" style="height:60px;">Image</div>
</div>
<div class="main">
<h2>TITLE HEADING</h2>
<h5>Title description, Dec 7, 2017</h5>
<div class="fakeimg" style="height:200px;">Image</div>
<p>Some text..</p>
<p>Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.</p>
<br>
<h2>TITLE HEADING</h2>
<h5>Title description, Sep 2, 2017</h5>
<div class="fakeimg" style="height:200px;">Image</div>
<p>Some text..</p>
<p>Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.</p>
</div>
<div class="side2">
<h4>follow me on socila media:</h4><br />
<ul>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</div>
<!-- Footer -->
<div class="footer">
<h2>Footer</h2>
</div>
</body>
I added a position: absolute; z-index: 10; to the .navbar class (probably a couple other minor changes too to get the snippet running correctly).
Edit
I also added in a transition effect. To do this, I changed how your toggle was working. Now, instead of changing the display attribute of .main-nav it just changes the height of the .navbar. The .active class is now applied to the navbar element.
Let me know if this works for you.

Padding affects container size?

See the following Codepen sample:
https://codepen.io/anon/pen/yWXRvR
Concerning the tourplaces container at the bottom of the page (see CSS section commented as Article: tour dates: tourplaces at the bottom of the CSS):
Why is it that when I arbitrarily change the left or right padding of a .place (e.g. the first .place : padding-left: 0), the .place images as well as their container suddenly become different sizes?
The .place containers then become inconsistent, having different heights. This is not what I want - I want them to stay horizontally bottom-aligned like they initially were.
Is it because the padding makes the image's width more narrow and then the height automatically adjusts along with it, making the .place content box longer?
/* General styles */
* {
box-sizing: border-box;
font-family: Arial;
}
body {
margin: 0;
}
a {
text-decoration: none;
}
/* Specific styles */
/* nav */
nav {
position: sticky;
top: 0;
z-index: 1;
}
nav ul {
list-style-type: none;
margin: 0;
padding: 0;
background-color: #000;
overflow: hidden;
}
nav ul li {
float: left;
}
nav ul li a{
padding: 16px 24px;
color: white;
display: block;
text-transform: uppercase;
}
nav ul li a:hover {
background-color: #ccc;
}
nav ul li:nth-of-type(5) {
/*position: relative;*/
}
nav ul li:nth-of-type(5) div a {
display: block;
color: black;
text-transform: capitalize;
}
nav ul li:nth-of-type(5) div a:hover a {
background-color: #ccc;
}
nav ul li:nth-of-type(5) div {
display: none;
position: absolute;
z-index: 1;
box-shadow: 0 0 5px #aaa;
background: white;
}
nav ul li:nth-of-type(5):hover div {
display: block;
}
#search {
float: right;
}
#search i {
color: white;
padding: 16px 24px;
font-size: 18px;
transition: 0.5s ease;
}
#search i:hover {
color: #aaa;
}
.fa-sort-down {
vertical-align: text-top;
font-size: 18px;
transform: translateY(-25%);
}
/* Animation */
#bandpics {
overflow: hidden;
}
img#chicago,
img#la,
img#ny {
width: 100%;
display: block;
position: absolute;
animation-name: slide;
animation-duration: 18s;
animation-iteration-count: infinite;
}
img#chicago {
animation-delay: 6s;
}
img#la {
animation-delay: 4s;
}
img#ny {
animation-delay: 2s;
}
#keyframes slide {
0% { opacity: 1; }
22% { opacity: 1; }
33% { opacity: 0; }
88% { opacity: 1; }
100% { opacity: 1; }
}
/* Article: the band */
#band {
width: 100%;
position: relative;
margin-top: 50%;
text-align: center;
padding: 10% 30%;
background-color: white;
}
#band h2 {
text-transform: uppercase;
font-weight: 500;
letter-spacing: 0.25em;
}
#band > h4 {
font-style: italic;
font-weight: 500;
color: #888;
}
#band h4::first-letter {
text-transform: capitalize;
}
#band p {
text-align: justify;
margin-bottom: 7%;
line-height: 1.3em;
}
#bandmembers {
overflow: hidden;
}
.bandmember img {
max-width: 50%;
}
.bandmember h4 {
font-weight: 100;
}
/* Article: tour dates */
/* Article: tour dates: sales lines */
#tourdates , #tourplaces {
background-color: black;
padding: 1% 30%;
}
#tourdates h2 {
text-transform: uppercase;
font-weight: 500;
letter-spacing: 0.25em;
color: white;
text-align: center;
}
#tourdates h4 {
text-align: center;
color: #888;
font-style: italic;
}
#tourdates h4:first-letter {
text-transform: uppercase;
}
.month {
color: #888;
background-color: white;
padding: 3%;
border-bottom: 1px solid #ccc;
}
.month span:first-of-type {
text-transform: capitalize;
margin-right: 15px;
}
.month span {
display: inline-block;
}
div.month:nth-of-type(1) span:nth-of-type(2),
div.month:nth-of-type(2) span:nth-of-type(2) {
background-color: #f44336;
color: white;
padding: 5px 10px;
}
div.month:nth-of-type(1) span:nth-of-type(2)::first-letter,
div.month:nth-of-type(2) span:nth-of-type(2)::first-letter {
text-transform: uppercase;
}
div.month:last-of-type {
position: relative;
}
div.month:last-of-type span:nth-of-type(2) {
background-color: black;
color: white;
border-radius: 50%;
padding: 4px 10px;
position: absolute;
top: 50%;
right: 5%;
transform: translateY(-50%);
}
/* Article: tour dates: tourplaces */
#tourplaces {
overflow: hidden;
margin: -8px;
}
.place {
float: left;
width: 33.33333%;
background-clip: content-box;
background-color: white;
padding-left: 8px;
padding-right: 8px;
}
.place img {
width: 100%;
}
.place img:hover {
opacity: 0.60;
}
.place-info {
padding-left: 8px;
padding-right: 8px;
padding-bottom: 8px;
}
.place-info > *:not(p) {
text-transform: capitalize;
}
.place-info h4 {
white-space: nowrap;
}
.place-info h4:nth-of-type(2) {
color: #888;
font-weight: 400;
}
.place button {
background-color: black;
color: white;
padding: 10px;
}
#media only screen and (min-width: 1000px) {
#band {
padding: 5% 30%;
}
.bandmember {
float: left;
width: 33.33333%
}
.bandmember img {
max-width: 60%;
}
}
<!-- from:
https://www.w3schools.com/w3css/tryw3css_templates_band.htm#
-->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css" integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">
<nav>
<ul>
<li>home</li>
<li>band</li>
<li>tour</li>
<li>contact</li>
<li>more <i class="fas fa-sort-down"></i>
<div>
merchandise
extras
media
</div>
</li>
<li id="search">
<i class="fas fa-search"></i>
</li>
</ul>
</nav>
<div id="container">
<div id="bandpics">
<img id="chicago" src="https://www.w3schools.com/w3images/chicago.jpg" alt="Chicago">
<img id="la" src="https://www.w3schools.com/w3images/la.jpg" alt="LA">
<img id="ny" src="https://www.w3schools.com/w3images/ny.jpg" alt="NY">
</div>
<article id="band">
<h2>the band</h2>
<h4>we love music</h4>
<p>We have created a fictional band website. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
<div id="bandmembers">
<div class="bandmember">
<h4>name</h4>
<img src="https://www.w3schools.com/w3images/bandmember.jpg" alt="bandmember">
</div>
<div class="bandmember">
<h4>name</h4>
<img src="https://www.w3schools.com/w3images/bandmember.jpg" alt="bandmember">
</div>
<div class="bandmember">
<h4>name</h4>
<img src="https://www.w3schools.com/w3images/bandmember.jpg" alt="bandmember">
</div>
</div>
</article>
<article id="tourdates">
<h2>tour dates</h2>
<h4>remember to book your tickets!</h4>
<div class="month">
<span>september</span><span>sold out</span>
</div>
<div class="month">
<span>october</span><span>sold out</span>
</div>
<div class="month">
<span>november</span><span>3</span>
</div>
</article>
<article id="tourplaces">
<div class="place">
<img src="https://www.w3schools.com/w3images/newyork.jpg" alt="NY">
<div class="place-info">
<h4>new york</h4>
<h4>fri 27 nov 2016</h4>
<p>Praesent tincidunt sed tellus ut rutrum sed vitae justo.
</p>
<button>buy tickets</button>
</div>
</div>
<div class="place">
<img src="https://www.w3schools.com/w3images/paris.jpg" alt="Paris">
<div class="place-info">
<h4>paris</h4>
<h4>sat 28 nov 2016</h4>
<p>Praesent tincidunt sed tellus ut rutrum sed vitae justo.
</p>
<button>buy tickets</button>
</div>
</div>
<div class="place">
<img src="https://www.w3schools.com/w3images/sanfran.jpg" alt="San Francisco">
<div class="place-info">
<h4>san francisco</h4>
<h4>sun 29 nov 2016</h4>
<p>Praesent tincidunt sed tellus ut rutrum sed vitae justo.
</p>
<button>buy tickets</button>
</div>
</article>
</div>
Padding affects container size?
It depends, in this case it does, but only the height, not the width, since the width is defined.
Is it because the padding makes the image's width more narrow and then
the height automatically adjusts along with it, making the .place
content box longer?
That is partially correct, it does affect the size of the image and also affects the text inside, making the height bigger or smaller depending on the value of the padding.
It is difficult to see how the width of the container is not changing because you have background-clip: content-box; this makes the background clipping on the limits of the content, then there is a part of the container that you are not able to see, if you put a border, lets say border: 1px solid red; within your .place class you would be able to see left and right paddings.
For this case I would use flex or grid, a grid example: (notice that I defined the height of the first container to 500px and the others are stretching itself to fill all the remaining space)
/* General styles */
* {
box-sizing: border-box;
font-family: Arial;
}
body {
margin: 0;
}
a {
text-decoration: none;
}
#tourdates , #tourplaces {
background-color: black;
padding: 1% 10%;
}
/* Article: tour dates: tourplaces */
#tourplaces {
overflow: hidden;
margin: -8px;
display: grid;
grid-template-columns: repeat(3, 1fr)
}
.place {
background-clip: content-box;
background-color: white;
padding-left: 8px;
padding-right: 8px;
border: 1px solid red;
}
.place.first-place{
padding-left: 25px;
height: 500px
}
.place.second-place{
padding-left: 0px
}
.place img {
width: 100%;
}
.place img:hover {
opacity: 0.60;
}
.place-info {
padding-left: 8px;
padding-right: 8px;
padding-bottom: 8px;
}
.place-info > *:not(p) {
text-transform: capitalize;
}
.place-info h4 {
white-space: nowrap;
}
.place-info h4:nth-of-type(2) {
color: #888;
font-weight: 400;
}
.place button {
background-color: black;
color: white;
padding: 10px;
}
<article id="tourplaces">
<div class="place first-place">
<img src="https://www.w3schools.com/w3images/newyork.jpg" alt="NY">
<div class="place-info">
<h4>new york</h4>
<h4>fri 27 nov 2016</h4>
<p>Praesent tincidunt sed tellus ut rutrum sed vitae justo.
</p>
<button>buy tickets</button>
</div>
</div>
<div class="place second-place">
<img src="https://www.w3schools.com/w3images/paris.jpg" alt="Paris">
<div class="place-info">
<h4>paris</h4>
<h4>sat 28 nov 2016</h4>
<p>Praesent tincidunt sed tellus ut rutrum sed vitae justo.
</p>
<button>buy tickets</button>
</div>
</div>
<div class="place">
<img src="https://www.w3schools.com/w3images/sanfran.jpg" alt="San Francisco">
<div class="place-info">
<h4>san francisco</h4>
<h4>sun 29 nov 2016</h4>
<p>Praesent tincidunt sed tellus ut rutrum sed vitae justo.
</p>
<button>buy tickets</button>
</div>
</article>

Trying to create fixed transparent menu but want h1 to be centered for responsive design and .intro to be moved down without making a gap

I am trying to create a fixed nav. For the most part, it works. But I want to center the h1 for responsive design. I could just push it away from the burger menu but then it wouldn't be responsive and bang in the middle.
Also I would like to push the .intro paragraph down away from the top. But every time I do a margin gap appears at the top, and I can't for the life of me remember how to get rid of this.
Thank you to anyone who takes a look. Means a lot! Hopefully one day I can repay the favor!
Below is my HTML and CSS. I also used a standard normalize.css, and some Js but I don't think you will need that. If you do, let me know:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>The Code Review</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/styles.css">
<link href="https://fonts.googleapis.com/css?family=Lato:100,100i,300,300i,400,400i,700,700i,900,900i" rel="stylesheet">
</head>
<body>
<header>
<!-- Introduction -->
<div class="background">
<nav class="navbar">
<span class="open-slide" onclick="openSideMenu()">
<!-- <a href="#" onclick="openSideMenu()">-->
<svg width="30" height="30">
<path d="M0,5 30,5" stroke="#000" stroke-width="4"/>
<path d="M0,14 30,14" stroke="#000" stroke-width="4"/>
<path d="M0,23 30,23" stroke="#000" stroke-width="4"/>
</svg>
<!-- </a>-->
</span>
<div id="main">
<h1>Luke Bennett</h1>
</div>
<!--
<ul class="navbar-nav">
<li>Home</li>
<li>About</li>
<li>Portfolio</li>
<li>Resume</li>
<li>Contact</li>
</ul>
-->
</nav>
<!-- Side Navigation Bar -->
<div id="side-menu" class="side-nav">
<span class="btn-close exit" onclick="closeSideMenu()">×</span>
Home
<a onclick="closeSideMenu()" href="#about">About</a>
<a onclick="closeSideMenu()" href="#portfolio-link">Portfolio</a>
<a onclick="closeSideMenu()" href="#resume-link">Resume</a>
<a onclick="closeSideMenu()" href="#contact">Contact</a>
</div>
<p class="intro">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
</header>
<main>
<!-- About Me -->
<div class="about-me"><a id="about"></a>
<h2>About Me</h2>
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
<p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
</div>
<!-- Portfolio -->
<div class="portfolio"><a id="portfolio-link"></a>
<h2>Portfolio</h2>
<!-- Front Page -->
<img src="img/well-being/well-being.png" alt="Donjas-Well-Being-For-Kids"/>
</div>
<!-- Resume -->
<div class="resume">
Download Resume
</div>
<!-- Contact Form -->
<div class="contact-form"><a id="contact"></a>
<form>
<fieldset>
<legend>Contact Form</legend>
<ul>
<li>
<label for="name">Name</label>
<input required type="text" id="name" name="full_name" placeholder="Required">
</li>
<li>
<label for="email">Email</label>
<input required type="text" id="email" name="email_address" placeholder="Required">
</li>
<li>
<label for="message">Message</label>
<textarea id="message" name="other_topics"></textarea>
</li>
<button type="submit">Hello!</button>
</ul>
</fieldset>
</form>
</div>
</main>
<footer>
<p>My name is Luke Bennett and I am a Human - Luke Bennett</p>
</footer>
<script src="javascript/menu.js"></script>
*,
input,
textarea,
button {
font-family: 'Lato', sans-serif;
}
h1 {
font-size: 1.7rem;
font-weight: 300;
letter-spacing: 3px;
}
h2 {
font-size: 1.4rem;
font-weight: 700;
letter-spacing: 2px;
}
p {
letter-spacing: 1px;
}
ul {
list-style: none;
padding: 0;
}
a {
text-decoration: none;
}
/************************************************************
HEADER
*************************************************************/
.navbar {
display: flex;
position: fixed;
overflow: hidden;
height: 40px;
padding: 16px 16px;
align-items: center;
}
#main {
margin: 0 auto;
}
#main a {
color: black;
}
.background {
background: linear-gradient(0deg, #fff, transparent 40%),
#333333 url('../img/sophie.jpg') no-repeat center;
background-size: cover;
padding-bottom: 50%;
margin-bottom: 30px;
}
.intro {
background: white;
opacity: 0.65;
line-height: 40px;
letter-spacing: 4px;
padding: 20px;
margin: 0 15% 15%;
}
/************************************************************
SIDE NAV
*************************************************************/
svg {
padding-top: 3px;
transition: 1s;
/*
border: 1px solid black;
border-radius: 50%;
*/
}
svg:hover {
opacity: 0.3;
}
.side-nav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #333333;
opacity: 0.9;
overflow-x: hidden;
text-align: center;
transition: 0.5s;
padding-top: 90px;
}
.side-nav a,
.btn-close {
display: block;
font-weight: 400;
color: white;
padding: 15px;
transition: 1s;
}
.side-nav a:hover,
.btn-close:hover {
background: white;
color: black;
font-weight: 400;
cursor: pointer;
}
.side-nav .btn-close {
position: absolute;
top: 0;
right: 22px;
font-size: 36px;
margin-left: 50px;
}
/************************************************************
MAIN
*************************************************************/
main {
margin-bottom: 0
}
.about-me {
margin-bottom: 40px;
}
.about-me h2 {
margin-bottom: 30px;
}
.about-me h2,
.about-me p {
text-align: center;
margin-left: 10%;
margin-right: 10%;
}
.about-me p {
font-weight: 300;
margin-bottom: 0px;
}
/************************************************************
PORTFOLIO
*************************************************************/
.portfolio {
background: #DCEAF5;
text-align: center;
padding: 20px 20px 50px;
}
.portfolio h2 {
color: black;
margin-bottom: 40px;
}
.portfolio img {
width: 80%;
padding: 3px;
transition: 1s;
margin-bottom: 10px;
border: 2px solid grey;
}
.portfolio img:hover {
opacity: 0.6;
}
/************************************************************
RESUME
*************************************************************/
/* #DCEAF5 #659EB8 */
.resume {
display: flex;
background: #969DA3;
padding: 10%;
}
.resume a {
display: block;
background: #DCEAF5;
color: black;
font-size: 1.2rem;
text-align: center;
margin: auto;
padding: 7%;
border-radius: 5px;
transition: 0.5s;
}
.resume a:hover {
opacity: 0.6;
}
/************************************************************
CONTACT
*************************************************************/
.contact-form {
background: #cc8c33;
height: 500px;
padding: 20% 10%;
}
fieldset {
border: 0;
}
legend {
font-size: 1.5rem;
font-weight: 400;
text-align: center;
color: white;
}
label {
display: block;
color: white;
margin-bottom: 10px;
}
input,
textarea {
box-sizing: border-box;
border-radius: 5px;
padding: 10px;
}
input:focus,
textarea:focus {
border: 2px solid #969DA3;
outline: none;
}
input {
border-style: none;
width: 100%;
border: 2px solid #cc8c33;
margin-bottom: 10px;
transition: 0.5s;
}
::placeholder {
text-align: right;
font-style: italic;
font-size: 0.7rem;
padding-right: 1px;
}
/* Textarea styling */
textarea {
height: 110px;
resize: none;
width: 100%;
margin-bottom: 30px;
border: 2px solid #cc8c33;
}
/* Button styling */
button {
border: none;
background: lightblue;
color: white;
font-weight: 700;
font-size: 1.1rem;
letter-spacing: 1px;
width: 100%;
border-radius: 5px;
padding: 20px;
transition: 0.5s;
}
button:hover {
background: #DCEAF5;
color: black;
}
/************************************************************
SOCIAL
*************************************************************/
footer {
background: lightblue;
height: 500px;
}

image positioning inside a box for slideshow

I've created a box containing images, but what I am trying to do is:
either display the images inline or position them on top of each other, then navigate among them using JQuery.
I've tried absolute positioning on both .box and .box img as well as display: inline but they mess up the code.
here it is so far:
.box {
position: absolute;
left: 10%;
width: 80%;
border: 10px solid white;
border-radius: 10px;
box-shadow: 0 0 4px black;
}
.box img {
width: 100%;
}
.prev, .next {
border: 1px solid black;
padding: 5px;
}
.prev:Hover, .next:Hover {
background-color: red;
color: white;
text-decoration: none;
}
<div class="container-fluid">
<h1>Welcome Within</h1>
<div class="box">
<img src="http://www.dan-dare.org/FreeFun/Images/PrinceOfPersiaWallpaper21024.jpg" />
<img src="https://www.gamewallpapers.com/img_script/mobile_dir2/img.php?src=wallpaper_prince_of_persia_warrior_within_18_ipad.jpg&height=755&width=850&crop-to-fit" />
<img src="https://r.mprd.se/media/images/66295-Prince_Of_Persia_Warrior_Within_READNFO-4.jpg" />
<br /></br />
PREVIOUS
NEXT
</div>
</div>
Try this:
.box {
position: absolute;
left: 10%;
width: 80%;
border: 10px solid white;
border-radius: 10px;
box-shadow: 0 0 4px black;
height: 300px;
overflow: hidden;
margin-bottom: 10px;
}
.caption {
position: absolute;
top: 10px;
color: red;
font-size: 20px;
background: #fff;
left: 30%;
}
.box img {
width: 100%;
}
.prev,
.next {
border: 1px solid black;
padding: 5px;
}
.prev:Hover,
.next:Hover {
background-color: red;
color: white;
text-decoration: none;
}
<div class="container-fluid">
<h1>Welcome Within</h1>
<div class="slider">
PREVIOUS
NEXT
<div class="box">
<img src="http://www.dan-dare.org/FreeFun/Images/PrinceOfPersiaWallpaper21024.jpg" />
<p class="caption">Caption1</p>
</div>
<div class="box">
<img src="https://www.gamewallpapers.com/img_script/mobile_dir2/img.php?src=wallpaper_prince_of_persia_warrior_within_18_ipad.jpg&height=755&width=850&crop-to-fit" />
<p class="caption">Caption2</p>
</div>
<div class="box">
<img src="https://r.mprd.se/media/images/66295-Prince_Of_Persia_Warrior_Within_READNFO-4.jpg" />
<p class="caption">Caption3</p>
</div>
</div>
</div>
I've tried this:
$(document).ready(function() {
$('.lightbox').click(function() {
$('.backdrop, .box').animate({
'opacity': '.50'
}, 300, 'linear');
$('.box').animate({
'opacity': '1.00'
}, 300, 'linear');
$('.backdrop, .box').css('display', 'block');
});
$('.close').click(function() {
close_box();
});
$('.backdrop').click(function() {
close_box();
});
//SlideShow
$('.next').click(function(){
clickNext();
});
$('.prev').click(function(){
clickPrev();
});
});
function close_box() {
$('.backdrop, .box').animate({
'opacity': '0'
}, 300, 'linear', function() {
$('.backdrop, .box').css('display', 'none');
});
}
//PREVIOUS
function clickPrev() {
$('.img_1').css('display', 'block');
//Move to the prev Image
$('.img_2').css('display', 'none');
}
//NEXT
function clickNext() {
$('.img_1').css('display', 'none');
//Move to the next Image
$('.img_2').css('display', 'block');
}
body {
font-family: Helvetica, Arial;
}
.backdrop {
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background: #000;
opacity: .0;
filter: alpha(opacity=0);
z-index: 50;
display: none;
}
.box {
position: absolute;
top: 50%;
transform: translate(-50%,-50%);
left: 50%;
background: white;
text-align: left;
z-index: 51;
padding: 0;
margin: 0;
display: none;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 0px 0px 5px #444444;
-webkit-box-shadow: 0px 0px 5px #444444;
box-shadow: 0px 0px 5px #444444;
border: 10px solid #fff;
width: 44%;
}
.box img {
width: 100%;
}
.box img:nth-child(2) {
display: none;
}
.caption {
padding-top: 10px;
font-size: 15px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-fluid">
<h1>Welcome Within</h1>
Open Lightbox
<div class="backdrop"></div>
<div class="box">
<img class="img_1" src="http://www.dan-dare.org/FreeFun/Images/PrinceOfPersiaWallpaper21024.jpg" />
<img class="img_2" src="https://www.gamewallpapers.com/img_script/mobile_dir2/img.php?src=wallpaper_prince_of_persia_warrior_within_18_ipad.jpg&height=755&width=850&crop-to-fit" />
<div class="caption">
<p>This thing is called 'Caption'...Feels nice. Let me tell you:</p>
<hr />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
PREVIOUS
NEXT
</div>
</div>

There is no scroll bar on my website, I cannot scroll with the scroll wheel [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
i am making a website and i have noticed that i cannot scroll using the scroll wheel on a mouse. I can use two-finger scrolling on my chromebook but not the scroll wheel on my pc. The issue is with both of the browsers i use; firefox and chrome.
Thanks in advance, Liam
css:
header {
width: 100%;
}
body {
margin: 0;
overflow: hidden;
}
footer {
clear: both;
height: 100px;
width: 100%;
background-color: #3d3d3d;
position: relative;
}
.nav {
width: 100%;
height: 50px;
background-color: #3D3D3D;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-webkit-transform: translateZ(0);
-moz-transform: translateZ(0)
}
.navwrap{
position: fixed;
width: 100%;
}
.name-logo {
width: 100%;
height: 350px;
background-color: #4BD150;
overflow: hidden;
}
.content {
float: left;
background-color: #f5fafa;
padding-left: 3%;
padding-right: 2%;
border-right: 4px solid #F5f5f5;
width: calc(65% - 4px);
z-index: 1;
height: 300px;
}
.sidebar {
width: 30%;
float: right;
background-color: #f5fafa;
height: 300px;
}
.social {
width: 30%;
float: right;
}
.social-icon {
float: right;
padding-left: 10px;
padding-top: 15px;
width: 35px;
}
#facebook {
padding-right: 15px;
}
.coppyright {
color: #fff;
padding-left: 25px;
width: 40%;
float: left;
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
}
.name {
width: 60%;
height: 100%;
padding-left: 100px;
}
.helper {
display: inline-block;
height: 100%;
vertical-align: middle;
}
.logo {
width: 60%;
height: 100%;
float: right;
white-space:nowrap;
margin-top: 20px;
margin-right: 20%;
margin-left: 20%;
}
.logo-img {
width: 100%;
vertical-align: middle;
}
#nav {
width: 100%;
float: left;
margin: 0;
padding: 0;
list-style: none;
height: 50px;
}
#nav li {
float: left;
font-family: Ubuntu, sans-serif;
font-size: 20px;
}
#nav li a {
display: block;
padding-left: 15px ;
padding-right: 15px;
padding-top: 11px;
text-decoration: none;
font-weight: bold;
color: #fff;
height: 50px;
width: auto;
}
#nav li a:hover {
color: #fff;
background-color: #333333;
height: 39px;
}
#home {
margin-left: 20px;
}
html:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css"
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Ubuntu:regular,bold&subset=Latin">
<title>Hackapi Mockup</title>
</head>
<!--This is where the navbar and splash title goes-->
<body><header>
<div class="navwrap">
<div class="nav">
<ul id="nav">
<li id="home">Home</li>
<li>News</li>
<li>Contact</li>
<li>About</li>
</ul>
</div>
</div>
<div class="name-logo">
<div class="logo">
<span class="helper"></span>
<img class="logo-img" src="https://imagizer.imageshack.us/v2/821x224q90/674/hloZoz.png">
</div>
</div>
</header>
<!--Main content and sidebar-->
<div class="content">
<h1>Lorem Ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div class="sidebar">
</div>
<!--Here is where all extra links, coppyrights and social media links go-->
<footer>
<div class="coppyright">
<h4>Coppyright Hackapi 2014</h4>
</div>
<div calss="social">
<img id="facebook" class="social-icon" src="https://imagizer.imageshack.us/v2/128x128q90/538/Kk3S3f.png">
<img id="twitter" class="social-icon" src="https://imagizer.imageshack.us/v2/128x128q90/913/xP6ctI.png">
<img id="gplus" class="social-icon" src="https://imagizer.imageshack.us/v2/128x128q90/536/nkHuql.png">
<img id="ytube" class="social-icon" src="https://imagizer.imageshack.us/v2/128x128q90/906/Sct7fy.png">
</div>
</footer>
</body>
I believe it is due to this style:
body {
overflow: hidden;
margin: 0;
}
You have to remove overflow:hidden as it is preventing the scrollbars from showing.
CSS:
overflow: auto;
OR
overflow-y: auto;
on body {}