I'm trying to create my own toggleable sidebar. I've done this snippet (press the brown color in screen to toggle):
I'd like that the background had the full width of the screen so when i hit on the brown part, the background is brown,not white.
$(document).ready(function() {
$("#rest-of-the-page").click(
function() {
$("#sidebar").toggleClass("hidden");
}
);
});
html,
body {
height: 100%;
margin: 0;
}
.container {
background-size: cover;
background-repeat: no-repeat;
background-position: center;
height: 100%;
}
#sidebar {
position: absolute;
height: 100%;
width: 15%;
background-color: rgba(27, 26, 26, .8);
transition: all .2s linear 0s;
}
.hidden {
margin-left: -30%;
transition: all .2s linear 0s;
}
#logo-container {
min-height: 150px;
height: 30%;
width: 100%;
border-bottom: 3px solid #1A1A1A;
}
#logo {
width: 100%;
height: 100%;
background: url(Images/logo.png) no-repeat center center;
background-size: 75% auto;
}
.menu-options-container {
height: 50%;
width: 100%;
}
#menu-options-ul {
width: 100%;
list-style-type: none;
padding: 0;
margin: 0;
text-align: center;
height: 70%;
}
#menu-options-ul li {
width: 100%;
border-top: 2px solid #373737;
border-bottom: 2px solid #1A1A1A;
height: 3em;
margin-top: 0;
color: #999;
display: table;
}
#menu-options-ul li:hover {
background: rgba(255, 255, 255, 0.2);
}
#menu-options-ul li p {
vertical-align: middle;
display: table-cell;
width: 100%;
}
#menu-options-ul li p:hover {
color: #fff;
}
#rest-of-the-page {
position: absolute;
top: 0;
left: 15%;
width: 85%;
height: 100%;
transition: all .2s linear 0s;
cursor: pointer;
background-color: antiquewhite
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="container">
<div id="sidebar">
<div id="logo-container">
<div id="logo"></div>
</div>
<div class="menu-options-container">
<ul id="menu-options-ul">
<li>
<p>Hola</p>
</li>
<li>
<p>Adios</p>
</li>
<li>
<p>Buenas</p>
</li>
</ul>
</div>
</div>
<div id="rest-of-the-page"></div>
</div>
just add a class with left:0 name it "fullpage"
make the width 100% for #rest-of-the-page
#rest-of-the-page{
position:absolute;
top:0;
width:100%;
left:15%;
height:100%;
transition: all .2s linear 0s;
cursor:pointer;
background-color:antiquewhite
}
#rest-of-the-page.fullpage{
left:0;
}
UPDATE : Another thing make the margin-left : -15% and not -30% because the width of the sidebar is only 15%
.hidden{
margin-left: -15%;
transition: all .2s linear 0s; //you don't need this
}
add overflow hidden to body
html, body {
height: 100%;
margin:0;
overflow-x:hidden;
}
toggleClass fullpage for #rest-of-the-page
https://jsfiddle.net/yggt4s83/2/
You can add the background color of the #rest-of-the-page element to your body:
$(document).ready(function() {
$("#rest-of-the-page").click(
function() {
$("#sidebar").toggleClass("hidden");
}
);
});
html,
body {
height: 100%;
margin: 0;
background-color: antiquewhite
}
.container {
background-size: cover;
background-repeat: no-repeat;
background-position: center;
height: 100%;
}
#sidebar {
position: absolute;
height: 100%;
width: 15%;
background-color: rgba(27, 26, 26, .8);
transition: all .2s linear 0s;
}
.hidden {
margin-left: -30%;
transition: all .2s linear 0s;
}
#logo-container {
min-height: 150px;
height: 30%;
width: 100%;
border-bottom: 3px solid #1A1A1A;
}
#logo {
width: 100%;
height: 100%;
background: url(Images/logo.png) no-repeat center center;
background-size: 75% auto;
}
.menu-options-container {
height: 50%;
width: 100%;
}
#menu-options-ul {
width: 100%;
list-style-type: none;
padding: 0;
margin: 0;
text-align: center;
height: 70%;
}
#menu-options-ul li {
width: 100%;
border-top: 2px solid #373737;
border-bottom: 2px solid #1A1A1A;
height: 3em;
margin-top: 0;
color: #999;
display: table;
}
#menu-options-ul li:hover {
background: rgba(255, 255, 255, 0.2);
}
#menu-options-ul li p {
vertical-align: middle;
display: table-cell;
width: 100%;
}
#menu-options-ul li p:hover {
color: #fff;
}
#rest-of-the-page {
position: absolute;
top: 0;
left: 15%;
width: 85%;
height: 100%;
transition: all .2s linear 0s;
cursor: pointer;
background-color: antiquewhite
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="container">
<div id="sidebar">
<div id="logo-container">
<div id="logo"></div>
</div>
<div class="menu-options-container">
<ul id="menu-options-ul">
<li>
<p>Hola</p>
</li>
<li>
<p>Adios</p>
</li>
<li>
<p>Buenas</p>
</li>
</ul>
</div>
</div>
<div id="rest-of-the-page"></div>
</div>
Why don't you add or remove a class on your #Rest-of-page when you toggle your menu ? Like that, your content will always stick to right side of the page if you have some. No tricky things using absolute position etc involved.
Just like this, ( exemple here )
HTML :
<div class="container">
<div id="sidebar">
<div id="logo-container">
<div id= "logo"></div>
</div>
<div class="menu-options-container">
<ul id="menu-options-ul">
<li><p>Hola</p></li>
<li><p>Adios</p></li>
<li><p>Buenas</p></li>
</ul>
</div>
</div>
<div id="rest-of-the-page" class="page--sided"><p>Hello</p></div>
</div>
CSS :
html, body {
height: 100%;
margin:0;
}
.container{
background-size: cover;
background-repeat: no-repeat;
background-position: center;
height: 100%;
}
#sidebar {
position:absolute;
height: 100%;
width: 15%;
background-color: rgba(27, 26, 26, .8);
transition: all .2s linear 0s;
}
.hidden{
margin-left: -30%;
transition: all .2s linear 0s;
}
#logo-container {
min-height: 150px;
height: 30%;
width: 100%;
border-bottom: 3px solid #1A1A1A;
}
#logo {
width: 100%;
height: 100%;
background:url(Images/logo.png) no-repeat center center;
background-size: 75% auto;
}
.menu-options-container {
height: 50%;
width: 100%;
}
#menu-options-ul{
width: 100%;
list-style-type: none;
padding:0;
margin:0;
text-align: center;
height:70%;
}
#menu-options-ul li{
width: 100%;
border-top: 2px solid #373737;
border-bottom: 2px solid #1A1A1A;
height:3em;
margin-top:0;
color: #999;
display: table;
}
#menu-options-ul li:hover{
background: rgba(255,255,255,0.2);
}
#menu-options-ul li p{
vertical-align: middle;
display: table-cell;
width: 100%;
}
#menu-options-ul li p:hover{
color: #fff;
}
#rest-of-the-page{
height:100%;
transition: all .2s linear 0s;
cursor:pointer;
background-color:antiquewhite
}
.page--sided{
position:absolute;
top:0;
left:15%;
width: 85%;
}
.page--full{
width:100%;
}
JS :
$(document).ready(function () {
$("#rest-of-the-page").click(
function () {
$("#sidebar").toggleClass("hidden");
if ($("#rest-of-the-page").hasClass("page--sided")){
$("#rest-of-the-page").removeClass("page--sided")
$("#rest-of-the-page").addClass("page--full");
}else{
$("#rest-of-the-page").addClass("page--sided")
$("#rest-of-the-page").removeClass("page--full");
}
}
);
});
var a = true;
function show(sidebar){
if(a==true){
sidebar.style.left = "0px";
sidebar.style.transition = "left 0.6s linear";
a=false;
}
else{
sidebar.style.left = "-200px";
sidebar.style.transition = "left 0.6s linear";
a=true;
}
}
body{
margin: 0px;
padding:0px;
font-family: helvetica;
}
#sidebar{
width: 200px;
height: 100%;
background: #151718;
top:0px;
left:-200px;
position: absolute;
}
#sidebar ul{
margin-top: 10px;
padding: 0px;
}
#sidebar ul li{
list-style: none;
}
#sidebar ul li a{
color:white;
padding:10px;
width: 180px;
margin-bottom: 4px;
display: block;
border-bottom: 1px solid black;
text-decoration:none;
}
#btn{
margin: 20px;
padding:20px;
right: -90px;
position: absolute;
}
#btn span{
background: black;
width: 25px;
height:5px;
margin-bottom: 5px;
display: block;
border-radius:17px;
}
<div id="sidebar">
<div id="btn" onclick="show(sidebar)">
<span></span>
<span></span>
<span></span>
</div>
<ul>
<li>Facebook</li>
<li>Vk</li>
<li>google</li>
<li>ymail</li>
</ul>
</div>
**Html left Sidebar using CSS and Javascript **
Related
I have removed irrelevant stuff to keep the question short, I had an issue with the same code earlier, I asked few more questions after it was resolved but did not hear back, that's why make a new post.
maintext class is not responding to any CSS styling e.g. border, background or other cosmetic properties, but has a major effect on the enclosing elements when commented out or deleted. Even an empty CSS declaration keeps the contents together when maintext class is deleted/commented out h1 spreads out and the effects go wild.
I want to position the maintext class including content elements to the right middle of the landing page. I can position button element and h1 items separately using with maintext class, using left and top properties, but I want the maintext block to position as a single unit.
#import url('https://fonts.googleapis.com/css2?family=Dancing+Script:wght#700&family=Reggae+One&display=swap');
html {
margin: 0;
padding: 0;
background-image: url(main.jpg);
width: 100%;
height: 100%;
background-size: cover;
z-index: 100;
position: relative;
}
html::before {
content: "";
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 100%;
background-color: white;
opacity: .3;
z-index: -10;
}
.menu {
display: inline-block;
margin-left: 52%;
/* border: 2px solid red; */
}
.menu ul {
right: 10px;
top: 10px;
list-style-type: none;
text-align: center;
border-radius: 10px;
background-color: transparent;
display: flex;
justify-content: center;
width: 600px;
padding: 0 10px;
height: 50px;
background-image: url(main.jpg);
background-size: cover;
background-position-x: -650px;
background-repeat: no-repeat;
background-color: tranparent .6;
}
.menu ul a {
text-decoration: none;
color: inherit;
transition-duration: 2s;
box-sizing: border-box;
}
.menu ul li {
border-collapse: collapse;
font-size: 18px;
font-family: 'Reggae One', cursive;
color: black;
box-sizing: border-box;
text-align: center;
margin-top: auto;
margin-bottom: auto;
margin-right: 40px;
display: inline-block;
/* padding: 7px 15px; */
border-radius: 7px;
transition-duration: 1s;
transition-timing-function: ease;
position: static;
font-weight: bolder;
background: transparent;
/* border: 1px solid red; */
text-decoration: underline;
}
.menu ul li:hover {
color: red;
/* box-shadow: 1px 1px 200px 200px rgba(92,137,204,.3); */
box-shadow: 1px 1px 200px 200px rgba(0, 0, 0, .3);
border: 1px solid black;
/* border: 1px solid rgba(0,0,0,.3); */
background: transparent;
}
/* /* .am
{
position:absolute;
}
ul.am{
position: absolute;
/* border: 2px solid red; */
/* list-style-type:none;
list-style-position: inside;
text-decoration: none;
display:none;
*/
*/
/* }
ul.am li{
display:block;
text-align: left;
margin-left:-40px;
padding:5px 0;
}
.menu ul li:hover ul.am{
display:block;
} */
*/
/*Main text on the main page*/
.maintext {
padding: 0;
margin: 0;
width: 100px;
height: 100px;
border: 2px solid red;
}
.maintext h1 {
z-index: 23;
color: transparent;
display: inline-block;
position: relative;
left: 900px;
top: 200px;
font-family: 'Reggae One', cursive;
border: 2px solid red;
margin-top: -10px;
animation: show .5s ease forwards;
animation-delay: 1s;
}
.maintext h1 span {
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 0;
background-color: rgba(0, 0, 0, .2);
animation: overlay 1s ease forwards;
animation-delay: .5s;
}
h1:nth-of-type(1) {
animation-delay: 1s;
}
h1:nth-of-type(2) {
animation-delay: 2s;
}
h1:nth-of-type(3) {
animation-delay: 3s;
}
h1:nth-of-type(1) span {
animation-delay: .5s;
}
h1:nth-of-type(2) span {
animation-delay: 1.5s;
}
h1:nth-of-type(3) span {
animation-delay: 2.5s;
}
.maintext .butt {
z-index: 45;
position: relative;
left: 900px;
top: 200px;
width: 250px;
height: 50px;
padding: 5px 30px;
border-radius: 8px;
background-color: transparent;
font-size: 25px;
font-weight: bolder;
font-family: 'Reggae One', cursive;
letter-spacing: 4px;
transition-duration: 2s;
transition-timing-function: ease;
color: black;
border: 2px solid black;
}
.maintext .butt:hover {
color: white;
box-shadow: 1px 1px 200px 200px rgba(92, 137, 204, .3);
background: transparent;
}
.maintext .align h1 {
display: flex;
justify-content: center;
align-items: center;
}
#keyframes overlay {
50% {
width: 100%;
left: 0;
}
100% {
left: 100%;
width: 0;
}
}
#keyframes show {
100% {
color: rgb(0, 0, 0, .8);
}
}
<section class="hero">
<div class="menu">
<ul>
<li>About Me</li>
<li>Work Experience</li>
<li>Hobbies</li>
<li>Gallery</samp>
</li>
</ul>
</div>
<div class="maintext">
<h1 class="align">Hello, <span></span></h1><br>
<h1 class="align">My Name is <span></span></h1><br>
<h1 class="align">Abc Xyz <span></span></h1><br>
<!-- <button class="butt align">Portfolio</button> -->
</div>
<div style="clear: both"></div>
</section>
I am trying to make a website. I decided to make the navigation bar have a fixed position so when I scroll down I can always see it but, when I add to the nav element the property position:fixed it just disappears. Cant' figure out what's happening. Can someone explain, what I'm doing wrong? Thank you very much!
P.S: I am new to coding.
HTML and CSS
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
html,
body {
width: 100%;
height: 100%;
}
header nav #logo {
width: 140px;
position: absolute;
top: 15px;
}
nav {
position: relative;
background-color: #242628;
height: 70px;
padding-left: 20px;
}
nav ul {
position: absolute;
height: 100%;
margin: auto;
top: 0;
bottom: 0;
width: 600px;
padding-left: 200px;
}
nav ul li {
-moz-transition: all 0.2s linear;
-webkit-transition: all 0.2s linear;
-o-transition: all 0.2s linear;
transition: all 0.2s linear;
display: inline;
float: left;
height: inherit;
width: 100px;
border-right: 1px solid gray;
}
nav ul li:hover {
background-color: rgba(12, 240, 255, 0.3);
}
nav ul li a {
color: white;
text-decoration: none;
position: absolute;
height: inherit;
width: inherit;
text-align: center;
padding-top: 25px;
}
<header>
<nav>
<img id="logo" src="images/logo.png" alt="logo" />
<ul>
<li>Home</li>
<li>Rate it!</li>
<li>Courses</li>
<li>Videos</li>
</ul>
</nav>
</header>
Once you fix the position you have to specify where you want it.
top: 20px;
left: 0px;
Etc....
You have to add a width to fixed elements (100% in this case):
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
html,
body {
width: 100%;
height: 100%;
}
header nav #logo {
width: 140px;
position: absolute;
top: 15px;
}
nav {
position: fixed;
width: 100%;
background-color: #242628;
height: 70px;
padding-left: 20px;
}
nav ul {
position: absolute;
height: 100%;
margin: auto;
top: 0;
bottom: 0;
width: 600px;
padding-left: 200px;
}
nav ul li {
-moz-transition: all 0.2s linear;
-webkit-transition: all 0.2s linear;
-o-transition: all 0.2s linear;
transition: all 0.2s linear;
display: inline;
float: left;
height: inherit;
width: 100px;
border-right: 1px solid gray;
}
nav ul li:hover {
background-color: rgba(12, 240, 255, 0.3);
}
nav ul li a {
color: white;
text-decoration: none;
position: absolute;
height: inherit;
width: inherit;
text-align: center;
padding-top: 25px;
}
<header>
<nav>
<img id="logo" src="images/logo.png" alt="logo" />
<ul>
<li>Home</li>
<li>Rate it!</li>
<li>Courses</li>
<li>Videos</li>
</ul>
</nav>
</header>
I let you here a working version. I only replaced relative with fixed in your code to the nav
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
html,
body {
width: 100%;
height: 300%;
}
header nav #logo {
width: 140px;
position: absolute;
top: 15px;
}
nav {
position: fixed;
background-color: #242628;
height: 70px;
padding-left: 20px;
}
nav ul {
position: absolute;
height: 100%;
margin: auto;
top: 0;
bottom: 0;
width: 600px;
padding-left: 200px;
}
nav ul li {
-moz-transition: all 0.2s linear;
-webkit-transition: all 0.2s linear;
-o-transition: all 0.2s linear;
transition: all 0.2s linear;
display: inline;
float: left;
height: inherit;
width: 100px;
border-right: 1px solid gray;
}
nav ul li:hover {
background-color: rgba(12, 240, 255, 0.3);
}
nav ul li a {
color: white;
text-decoration: none;
position: absolute;
height: inherit;
width: inherit;
text-align: center;
padding-top: 25px;
}
<header>
<nav>
<img id="logo" src="images/logo.png" alt="logo" />
<ul>
<li>Home</li>
<li>Rate it!</li>
<li>Courses</li>
<li>Videos</li>
</ul>
</nav>
</header>
Note that I set height to 300% to have some scroll on the document
I honestly don't see anything wrong:
http://codepen.io/anon/pen/BWpLdd
.scrollTest {
height: 2000px;
background: -moz-linear-gradient(top, #a90329 0%, #8f0222 44%, #6d0019 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(top, #a90329 0%,#8f0222 44%,#6d0019 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, #a90329 0%,#8f0222 44%,#6d0019 100%);
}
* {
box-sizing: border-box;
padding: 0;
margin: 0; }
html, body {
width: 100%;
height: 100%; }
header nav #logo {
width: 140px;
position: absolute;
top: 15px; }
nav {
position: fixed;
background-color: #242628;
height: 70px;
padding-left: 20px;
width: 100%;
}
nav ul {
position: absolute;
height: 100%;
margin: auto;
top: 0;
bottom: 0;
width: 800px;
padding-left: 200px; }
nav ul li {
-moz-transition: all 0.2s linear;
-webkit-transition: all 0.2s linear;
-o-transition: all 0.2s linear;
transition: all 0.2s linear;
display: inline-block;
height: inherit;
width: 100px;
border-right: 1px solid gray; }
nav ul li:hover {
background-color: rgba(12, 240, 255, 0.3); }
nav ul li a {
color: white;
text-decoration: none;
position: absolute;
height: inherit;
width: inherit;
text-align: center;
padding-top: 25px; }
Make sure you're adding it to the nav parent element.
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
html,
body {
width: 100%;
height: 100%;
}
header nav #logo {
width: 140px;
position: absolute;
top: 15px;
}
nav {
position: fixed;
background-color: #242628;
height: 70px;
padding-left: 20px;
width: 100%;
background-color: black;
}
nav ul {
position: relative;
height: 100%;
margin: auto;
top: 0;
bottom: 0;
}
nav ul li {
-moz-transition: all 0.2s linear;
-webkit-transition: all 0.2s linear;
-o-transition: all 0.2s linear;
transition: all 0.2s linear;
display: inline;
float: left;
height: inherit;
width: 200px;
border-right: 1px solid gray;
}
nav ul li:hover {
background-color: rgba(12, 240, 255, 0.3);
}
nav ul li a {
color: white;
text-decoration: none;
position: absolute;
height: inherit;
width: inherit;
text-align: center;
padding-top: 25px;
}
article{
height: 500px;
}
<header>
<nav>
<img id="logo" src="" alt="logo" />
<ul>
<li>Home</li>
<li>Rate it!</li>
<li>Courses</li>
<li>Videos</li>
</ul>
</nav>
</header>
<article></article>
Working code
If your nav is set to realtive and is changed to fixed your absolute elements will be relative to the body and those elements will leave the nav.
Change the position of the absolute elements and the css of the nav to:
nav {
background-color: #242628;
height: 70px;
padding-left: 20px; }
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 999;
}
I have a button that, when pressed, is supposed to expand the element behind it (.nav which contains .work and .contact) out in both directions. However, I can't seem to keep the button in the center.
$(function() {
var nav = $('.nav');
var button = $('.nav button');
button.on('click', function(){
nav.toggleClass('active');
if(nav.hasClass('active'))
button.text('');
else
button.text('');
});
});
html {
background: #f1f1f1;
}
.nav {
display: block;
margin: auto;
margin-top: 80px;
margin-bottom: 200px;
background: #ccc;
color: black;
text-align: center;
width: 350px;
height: 330px;
transition: width 0.5s;
}
.nav.active {
width: 1000px;
transition: width 0.5s;
}
.navigation button {
position: absolute;
width: 350px;
Height: 350px;
margin: 0 auto;
display: block;
background-color: #2e0513!important;
background: url(TransplantAltFontbackgroundvector.png) 12px 15px;
background-repeat: no-repeat;
background-size: 325px 325px;
border: none;
transition: 0.5s ease-in-out;
}
.navigation.active button {
transform: scale(1.1);
transition: 0.5s ease-in-out;
}
.navigation:hover button {
box-shadow: 0px 0px 20px black;
transform: scale(1.01);
transition: 0.1s ease-in-out;
}
.navigation.active:hover button {
box-shadow: none!important;
transform: scale(1.1)!important;
transition: 0.5s ease-in-out;
}
.navigation button img {
position: relative;
right: 30px;
bottom: 40px;
}
.work,
.contact {
position: relative;
visibility: hidden;
}
.work a {
font-family: arapey;
font-size: 30px;
font-style: italic;
text-decoration: none;
}
.contact a {
font-family: arapey;
font-size: 30px;
font-style: italic;
text-decoration: none;
}
.nav.active > .work {
visibility: visible!important;
display: table;
margin: auto;
position: relative;
float: left;
left: 125px;
top: 150px;
}
.nav.active > .contact {
visibility: visible!important;
display: table;
margin: auto;
position: relative;
float: right;
right: 125px;
top: 150px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="navigation">
<div class="nav">
<button>
</button>
<div class="work">
work
</div>
<div class="contact">
contact
</div>
</div>
</div>
Give the nav a style of position: relative. Then, toggle a class (or just add the styling, should work as well) to the button on click that does the following:
button.my-pressed-class {
position: absolute;
left: 50%;
transform: translateX(-50%);
}
This should keep it in the middle.
Edit: Keep in mind you already have a transform set on the button on hover. Just, add the translateX to hover when the button has the aforementioned class, to avoid it from moving around on hover.
add postion relative to .navigation and position absolute to .nav with left value
$(function() {
var nav = $('.nav');
var button = $('.nav button');
button.on('click', function(){
nav.toggleClass('active');
if(nav.hasClass('active'))
button.text('');
else
button.text('');
});
});
html {
background: #f1f1f1;
}
.navigation {
position: relative;
}
.nav {
display: block;
margin: auto;
margin-top: 80px;
margin-bottom: 200px;
background: #ccc;
color: black;
text-align: center;
width: 350px;
height: 330px;
transition: width 0.5s;
position: absolute;
left: 100px;
}
.nav.active {
width: 1000px;
transition: width 0.5s;
}
.navigation button {
position: absolute;
width: 350px;
Height: 350px;
margin: 0 auto;
display: block;
background-color: #2e0513!important;
background: url(TransplantAltFontbackgroundvector.png) 12px 15px;
background-repeat: no-repeat;
background-size: 325px 325px;
border: none;
transition: 0.5s ease-in-out;
}
.navigation.active button {
transform: scale(1.1);
transition: 0.5s ease-in-out;
}
.navigation:hover button {
box-shadow: 0px 0px 20px black;
transform: scale(1.01);
transition: 0.1s ease-in-out;
}
.navigation.active:hover button {
box-shadow: none!important;
transform: scale(1.1)!important;
transition: 0.5s ease-in-out;
}
.navigation button img {
position: relative;
right: 30px;
bottom: 40px;
}
.work,
.contact {
position: relative;
visibility: hidden;
}
.work a {
font-family: arapey;
font-size: 30px;
font-style: italic;
text-decoration: none;
}
.contact a {
font-family: arapey;
font-size: 30px;
font-style: italic;
text-decoration: none;
}
.nav.active > .work {
visibility: visible!important;
display: table;
margin: auto;
position: relative;
float: left;
left: 125px;
top: 150px;
}
.nav.active > .contact {
visibility: visible!important;
display: table;
margin: auto;
position: relative;
float: right;
right: 125px;
top: 150px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="navigation">
<div class="nav">
<button>
</button>
<div class="work">
work
</div>
<div class="contact">
contact
</div>
</div>
</div>
I'm doing a page for someone. I toggled the visibility of a div with a checkbox however, he wants to change the height of the header which comes before the content div which has the onclick event. Could anyone help me out? either css or js/jquery.
What I want:
checkbox off: div hidden & header height 412px.
checkbox checked: div showed & header height 212px.
header {
width:100%;
height:412px;
text-align:center;
background:#1f1f1f;
margin: 0;
padding: 0;
border: 0;
position:relative;
}
#wrapper td {
vertical-align: middle;
text-align: center;
}
#wrapper td img {
position: absolute;
top: 50%;
left: 50%;
width: 736px;
height: 105px;
margin-top: -52px; /* Half the height */
margin-left: -368px; /* Half the width */
}
div.content {
background:#ebebec;
position:relative;
top:100px;
color: white;
width: 100%;
text-align: center;
font-family: BlueHighway, Arial Black, sans-serif;
top:0;
}
div.content label {
display: block;
width:80px;
height:88px;
background:url(http://i.imgur.com/Buvp49A.png) no-repeat;
background-position: center top;
margin:0 auto;
margin-bottom:30px;
}
div.content label:hover {
cursor: pointer; background-position: center bottom;
}
div.button {
display:block;
position:relative;
top:-67px;
padding-top:22px;
background:url(http://i.imgur.com/Gf3QAxt.png) no-repeat;
background-position: center top;
}
input.toggle ~ div.description {
height: 0px;
overflow: hidden;
transition: .6s all cubic-bezier(0.730, -0.485, 0.145, 1.620)
}
input.toggle:checked ~ div.description { height: 530px; }
input.toggle:checked + label { background-position: center bottom; }
input.toggle { display: none; }
<header>
<table id="wrapper">
<tr>
<td><img src="http://i.imgur.com/vE3KBOv.png" alt="Santos#imvu"/></td>
</tr>
</table>
</header>
<div class="content">
<div class="button">
<input type="checkbox" id="punch" class="toggle">
<label for="punch"></label>
<div class="description">
<img src="http://i.imgur.com/8sY0E5c.gif" style="max-width:100%;height:auto" alt="bla">
</div>
</div>
</div>
Demo
Something like this?
I've set the initial height to 212px and added a new class to CSS header.expand where you set the height to 412px. After that you trigger the click() event for the checkbox in jQuery and toggle the expand class with toggleClass(...)
SNIPPET
$('#punch').click(function() {
$('header').toggleClass('expand');
});
html {
background: grey;
font-family: Arial, Helvetica, sans-serif;
font-size: 100%;
}
body {
background: #ebebec;
width: 926px;
margin: 0 auto;
padding: 0;
color: grey;
}
header {
width: 100%;
height: 212px;
text-align: center;
background: #1f1f1f;
margin: 0;
padding: 0;
border: 0;
position: relative;
transition: height .8s ease-out;
}
header.expand {
height: 412px;
}
#wrapper td {
vertical-align: middle;
text-align: center;
}
#wrapper td img {
position: absolute;
top: 50%;
left: 50%;
width: 736px;
height: 105px;
margin-top: -52px;
/* Half the height */
margin-left: -368px;
/* Half the width */
}
.image {
width: 500px;
height: 500px;
margin: 0 auto;
position: relative;
margin-bottom: 94px;
}
footer {
width: 100%;
text-align: center;
padding: 20px 0;
font-size: 12px;
background: #1f1f1f;
margin-top: 28px;
color: #fff;
clear: both;
}
a {
color: #0082ff;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
p {
width: 870px;
margin: 0 auto;
}
div.content {
background: #ebebec;
position: relative;
top: 100px;
color: white;
width: 100%;
text-align: center;
font-family: BlueHighway, Arial Black, sans-serif;
top: 0;
}
div.content label {
display: block;
width: 80px;
height: 88px;
background: url(http://i.imgur.com/Buvp49A.png) no-repeat;
background-position: center top;
margin: 0 auto;
margin-bottom: 30px;
}
div.content label:hover {
cursor: pointer;
background-position: center bottom;
}
div.button {
display: block;
position: relative;
top: -67px;
padding-top: 22px;
background: url(http://i.imgur.com/Gf3QAxt.png) no-repeat;
background-position: center top;
}
input.toggle ~ div.description {
height: 0px;
overflow: hidden;
transition: .6s all cubic-bezier(0.730, -0.485, 0.145, 1.620)
}
input.toggle:checked ~ div.description {
height: 530px;
}
input.toggle:checked + label {
background-position: center bottom;
}
input.toggle {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<header>
<table id="wrapper">
<tr>
<td>
<img src="http://i.imgur.com/vE3KBOv.png" alt="Santos#imvu" />
</td>
</tr>
</table>
</header>
<div class="content">
<div class="button">
<input type="checkbox" id="punch" class="toggle">
<label for="punch"></label>
<div class="description">
<img src="http://i.imgur.com/8sY0E5c.gif" style="max-width:100%;height:auto" alt="bla">
</div>
</div>
</div>
I'm trying to make the text on my navigation bar to show an underline on mouse-over but for some reason it doesn't work. I've used the CSS from the Hover-master collection and just a simple navigation list. What to do?!
Have I used the Hover-master collection wrong?
EDIT: I just inserted my whole code and in the snippet it works but when I run the html file in the browers it doesn't...
EDIT2: The files are hosted # http://fransbergstrom.kaggteknik.se/ and as you can see, the links doesn't work, and the code is an exact copy of the ones pasted below.
HTML & CSS:
#charset "utf-8";
#font-face {
font-family: Fairview;
src: url("fonts/Fairview_Regular.otf");
}
/*PRE-CLASSES:*/
#media screen and (max-width: 1440px) {
html {
-moz-transform: scale(0.75, 0.75);
zoom: 0.75;
zoom: 75%;
}
/*Zooma ut vid mac så websidan anpassar sig*/
}
div {
display: block;
}
* {
margin: 0px;
padding: 0px;
font-weight: normal;
}
body {
background-color: gray;
font-family: 'Fairview';
color: #444444;
}
/* ID's: */
/* NAVIGATION MENU */
#navlist {
margin-top: 35px;
padding: 0;
list-style: none;
}
#navlist li {
display: inline
}
#navlist li a {
font-size: 50px;
text-align: center;
border-right: 3px solid #fff;
text-decoration: none;
width: 200px;
float: left;
color: white;
}
/*FRONT PAGE*/
#container {
width: 70%;
height: 100%;
margin: 0 auto;
}
#menu {
margin-top: 0px;
height: 130px;
width: 100%;
}
#menu-nav {
height: 130px;
width: 80%;
float: left;
}
#menu-logo {
height: 130px;
width: 20%;
background: url("images/menulogo.png") no-repeat;
background-size: contain;
float: left;
}
/* NEWS */
#news {
margin-left: 250px;
margin-top: 140px;
height: 340px;
width: 70%;
float: left;
}
#news-opacity {
position: absolute;
margin-left: 0px;
height: 340px;
width: 49%;
background-color: black;
opacity: 0.5;
float: left;
z-index: -1;
}
#news-right {
height: 100%;
width: 48%;
float: left;
}
#news-right p {
margin-top: 90px;
color: #e04e21;
font-size: 100px;
text-decoration: none;
text-align: center;
}
#news-right b {
margin-top: 90px;
color: white;
font-size: 60px;
text-decoration: none;
text-align: center;
margin-left: 93px;
}
#news-middle {
margin-top: 60px;
height: 70%;
width: 4%;
background: url("images/news-divider.png") no-repeat;
background-size: contain;
float: left;
}
#news-left {
height: 100%;
width: 48%;
float: left;
}
#news-left p {
margin-top: 10px;
margin-left: 50px;
color: white;
font-size: 40px;
text-decoration: none;
text-align: left;
}
#news-left h1 {
margin-top: 70px;
margin-left: 50px;
color: #e04e21;
font-size: 50px;
text-decoration: none;
text-align: left;
}
/* HEADER */
#header {
position: relative;
height: 20px;
width: 100%;
margin: auto;
}
#header-opacity {
position: absolute;
height: 160px;
width: 100%;
margin: auto;
background-color: black;
opacity: 0.6;
z-index: -1;
}
/* CLASSES: */
.background {
position: absolute;
width: 100%;
height: 100%;
z-index: -1;
background: url("images/background.jpg") no-repeat 0px;
}
/* Underline From Center */
.hvr-underline-from-center {
display: inline-block;
vertical-align: middle;
-webkit-transform: translateZ(0);
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
position: relative;
overflow: hidden;
}
.hvr-underline-from-center:before {
content: "";
position: absolute;
z-index: -1;
left: 50%;
right: 50%;
bottom: 0;
background: #2098d1;
height: 4px;
-webkit-transition-property: left, right;
transition-property: left, right;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
}
.hvr-underline-from-center:hover:before,
.hvr-underline-from-center:focus:before,
.hvr-underline-from-center:active:before {
left: 0;
right: 0;
}
<!DOCUTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="standard.css" media="screen">
</head>
<body>
<div class="background">
<div id="header-opacity"></div>
<div id="container">
<div id="header"></div>
<div id="menu">
<div id="menu-logo"></div>
<div id="menu-nav">
<ul id="navlist">
<li>Start
</li>
<li><font color="#e04e21">Kontakt</font>
</li>
<li>Info
</li>
<li><font color="#e04e21">Turneringar</font>
</li>
<li>Biljetter
</li>
</ul>
</div>
</div>
<div id="news">
<div id="news-opacity"></div>
<div id="news-right">
<p>WELCOME</p>
<b>TO MONSTERHACK</b>
</div>
<div id="news-middle">
</div>
<div id="news-left">
<h1>Har kommer det sta nagot</h1>
<b></b>
<p>Som informerar lasaren</p>
<b></b>
<p>Om eventet med mera</p>
<b></b>
<p>Samt dirigerar den till biljetter</p>
</div>
</div>
</div>
</div>
</body>
</html>
Just remove z-index:-1; from .background{}. You dropped the whole page below "sea level", so hover event do not fires. ;)
have you tried adding the font-size attribute to .hvr-underline-from-center:hover ?
add this to the css:
.hvr-underline-from-center:hover {
font-size: 30px;
}
#navlist li a:hover {
font-size: 55px;
}
Add that line to your CSS and put your own pixels value instead of '55px' to play around the text size when hovering
http://jsbin.com/hesisohuse/1/edit
Okey I just figured it out, for some reason my .background class caused the problem. By removing position=absolute; from the class my tags became clickable again.
I don't know why this happends but at least it fixed my problem.