Create Underline Transition CSS - html

I want to make a header appear to have an animated underline when the parent element is hovered. Right now it is very close but I can't seem to position it correctly so that its width grows in both directions from its center, which is what I want it to do. Does someone know what I'm missing or need to add to my code to make this happen? The code below is what I think is relevant to fixing the situation. The entire project can be viewed via this CodePen as well. Thanks in advance! (The underlining is only applied to the first header when hovering).
HTML:
<div class="row flex-row">
<div id="top-image" class="image-block">
<h3>Fish Tail</h3>
<div class="underline"></div>
<img class="flex-image" src="https://source.unsplash.com/KSHq0VSqLMA">
</div>
<div class="image-block">
<h3>Swallow Tail</h3>
<img class="flex-image" src="https://source.unsplash.com/U--hvQ5MKjY">
</div>
<div class="image-block">
<h3>Directional</h3>
<img class="flex-image" src="https://source.unsplash.com/F3ePNdQb_Lg">
</div>
</div>
CSS:
.image-block:hover > h3{
letter-spacing: 8px;
transition: all .3s ease-in-out;
}
.underline {
visibility: hidden;
background-position: center;
background-color: white;
position: absolute;
top: 60%;
margin: 0;
width: 10px;
height: 10px;
border-radius: 5px;
transform: scaleX(0);
webkit-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
}
.image-block:hover .underline {
visibility: visible;
transform: scaleX(1);
width: 100%;
height: 10px;
transition: all .3s ease-in-out;
}
Edit:
I am trying to use the same ideas from someone else's Underlining Effect CodePen. The biggest difference is I don't want to have an <a> inside my header.

If you apply width: 100% to the .underline rule it begins the animation from the center.
.underline {
visibility: hidden;
background-position: center;
background-color: white;
position: absolute;
top: 60%;
margin: 0;
width: 100%; /**** Change this to 100% ****/
height: 10px;
border-radius: 5px;
transform: scaleX(0);
webkit-transition: all .2s ease-in-out;
transition: all .3s ease-in-out;
}
Adjusting the width of the line
To adjust the width of the line you can change the following:
.underline{
margin: 10% /*<== Set to half of 'what's left' in this case half of 20% is 10%*/
width: 80%;
}
.image-block:hover .underline {
width: 80% /*<== Set to match the .underline width */
}
* {
box-sizing: border-box;
}
.row {
min-width: 100%;
}
.flex-row {
display: flex;
flex-wrap: wrap;
}
.image-block {
position: relative;
width: 33.33%;
float: left;
margin-top: 0;
z-index: 5;
}
.image-block:hover {
-webkit-filter: grayscale(100%);
/* Safari 6.0 - 9.0 */
filter: grayscale(100%);
}
.image-block h3 {
position: absolute;
text-align: center;
font-family: 'Roboto', sans-serif;
color: white;
top: 40%;
width: 100%;
font-size: 48px;
letter-spacing: 5px;
margin: 0;
transition: all .3s ease-in-out;
}
.image-block:hover>h3 {
letter-spacing: 8px;
transition: all .3s ease-in-out;
}
.underline {
visibility: hidden;
background-position: center;
background-color: white;
position: absolute;
top: 60%;
margin: 0;
width: 100%;
/**** Change this to 100% ****/
height: 10px;
border-radius: 5px;
transform: scaleX(0);
webkit-transition: all .2s ease-in-out;
transition: all .3s ease-in-out;
}
.image-block:hover .underline {
visibility: visible;
transform: scaleX(1);
width: 100%;
height: 10px;
transition: all .3s ease-in-out;
}
.flex-image {
width: 100%;
height: auto;
display: flex;
}
#media all and (max-width: 1200px) {
.image-block {
width: 33.33%%;
}
}
#media all and (max-width: 1660px) {
.navbar a {
padding: 14px 14%;
}
}
#media all and (max-width: 1035px) {
.navbar a {
padding: 14px 12%;
}
}
#media all and (max-width: 880px) {
#top-image {
margin-top: 150px;
}
.image-block {
width: 100%;
margin: 0;
}
.navbar a:not(:first-child) {
display: none;
}
.navbar a.icon {
float: right;
display: block;
}
.navbar.responsive {
position: relative;
}
.navbar.responsive .icon {
position: fixed;
right: 0;
top: 0;
}
.navbar.responsive a {
float: none;
display: block;
text-align: left;
}
.navbar a:hover {
transform: scale(1);
}
}
<div class="row flex-row">
<div id="top-image" class="image-block">
<h3>Fish Tail</h3>
<div class="underline">
</div>
<img class="flex-image" src="https://source.unsplash.com/KSHq0VSqLMA">
</div>
</div>

Related

Pure CSS Hamburger menu shows up when resizing viewport before disappearing

I have a pure css hamburger menu based on this codepen and I made my hamburger menu only show up on devices with 768px width and below, the hamburger menu also has some transitions when opening and closing to make it look smooth but the problem is that when the page is refreshed, you can see the menu show up for a split second before it transitions under the header. This can also be seen when you're manually resizing the viewport from a width larger than 768px and when it gets to 767px, you can the see the menu appear for a split second before it disappears. Please I need help to make this behaviour stop. Below is the code required to recreate this problem:
*,
*::before,
*::after {
box-sizing: border-box;
}
html,
body {
margin: 0;
padding: 0;
min-width: fit-content;
}
body {
font-family: "Montserrat", sans-serif;
background-color: #eeeeee;
}
header {
width: 100%;
background-color: #eeeeee;
padding: 0 20px;
height: 65px;
position: fixed;
top: 0;
}
.logo {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
margin-top: 15px;
}
#header-img {
width: 100%;
height: 100%;
max-width: 300px;
}
/* Navigation */
nav {
width: 100%;
text-align: center;
}
/* Hamburger menu button */
.menu-btn {
display: none;
}
.menu-icon {
display: inline-block;
position: relative;
top: -42px;
left: -25px;
cursor: pointer;
padding: 24px 14px;
z-index: 1;
}
.navicon {
background-color: #222222;
display: block;
height: 3px;
width: 26px;
position: relative;
transition: 0.3192s ease-in-out;
}
.navicon:before,
.navicon:after {
content: "";
display: block;
height: 100%;
width: 100%;
position: absolute;
background-color: #222222;
transition: 0.3192s ease-in-out;
}
.navicon:before {
top: 9px;
}
.navicon:after {
bottom: 9px;
}
/* Hamburger Menu Animation Start */
.menu-btn:checked~.menu-icon .navicon:before {
transform: rotate(-45deg);
top: 0;
}
.menu-btn:checked~.menu-icon .navicon:after {
transform: rotate(45deg);
bottom: 0;
}
.menu-btn:checked~.menu-icon .navicon {
background: transparent;
transition: 0.3192s ease-in-out;
}
/* Hide blue background on hamburger menu tap on some mobile devices */
.menu-icon,
.menu-btn,
.navicon {
-webkit-tap-highlight-color: transparent;
}
/* Nav items */
.menu {
background-color: #eeeeee;
width: 100%;
height: auto;
list-style-type: none;
position: absolute;
top: 0;
left: 0;
right: 0;
margin-top: 65px;
padding: 0;
visibility: hidden;
opacity: 0;
transition: visibility 0.3192s ease-in-out, opacity 0.3192s ease-in-out;
}
.menu-btn:checked~nav .menu {
visibility: visible;
opacity: 1;
transition: visibility 0.3192s ease-in-out, opacity 0.3192s ease-in-out;
}
.menu li {
border-top: 1px solid #c7c7c7;
padding: 10px 0;
opacity: 0;
transition: 0.5s;
}
.menu a {
color: #222222;
text-decoration: none;
font-weight: 500;
font-size: 0.9rem;
opacity: 0;
transition: 0.5s;
}
.menu-btn:checked~nav .menu a,
.menu-btn:checked~nav .menu li {
opacity: 1;
transition: 0.3192s ease-in-out;
}
/* Medium devices (landscape tablets, 768px and up) */
#media only screen and (min-width: 768px) {
header {
display: flex;
align-items: center;
justify-content: space-around;
}
.logo {
width: 60vw;
margin-top: 0;
justify-content: flex-start;
}
.menu-icon {
display: none;
}
nav {
width: 40vw;
margin-top: 0;
}
.menu {
width: 100%;
transform: none;
transition: none;
position: static;
margin: 0;
visibility: visible;
opacity: 1;
display: flex;
justify-content: space-around;
align-items: center;
}
.menu li {
border: none;
padding: 0;
opacity: 1;
transition: none;
}
.menu a {
opacity: 1;
transition: none;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<title>Product Landing Page</title>
</head>
<body>
<main id="main">
<header id="header">
<div class="logo">
<img id="header-img" src="https://s3.amazonaws.com/freecodecamp/original_trombones.png" alt="original trombones logo">
</div>
<input type="checkbox" class="menu-btn" id="menu-btn">
<label for="menu-btn" class="menu-icon"><span class="navicon"></span></label>
<nav id="nav-bar">
<ul class="menu">
<li>Feautures</li>
<li>How it Works</li>
<li>Pricing</li>
</ul>
</nav>
</header>
</main>
</body>
</html>
I also provided a fiddle you can use to check out the problem.
P.S: The original codepen I got the idea from also has the same issue if you copy the code and preview it in a browser and reload the page.
Using javascript we can add the stop-transition class to the body for some few milliseconds. Then in the css we can add the rule to stop play any transition momentarily. After that, when the resize is done, we can remove the stop-transition class from the body to make sure that everything acts accordingly.
Here's the fiddle.
(function () {
const classes = document.body.classList;
let timer = null;
window.addEventListener('resize', function () {
if (timer){
clearTimeout(timer);
timer = null;
} else {
classes.add('stop-transition');
}
timer = setTimeout(() => {
classes.remove('stop-transition');
timer = null;
}, 100);
});
})();
*,
*::before,
*::after {
box-sizing: border-box;
}
html,
body {
margin: 0;
padding: 0;
min-width: fit-content;
}
body {
font-family: "Montserrat", sans-serif;
background-color: #eeeeee;
}
/* Stop playing transition momentarily on viewport resize. */
body.stop-transition .menu {
transition: none;
}
header {
width: 100%;
background-color: #eeeeee;
padding: 0 20px;
height: 65px;
position: fixed;
top: 0;
}
.logo {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
margin-top: 15px;
}
#header-img {
width: 100%;
height: 100%;
max-width: 300px;
}
/* Navigation */
nav {
width: 100%;
text-align: center;
}
/* Hamburger menu button */
.menu-btn {
display: none;
}
.menu-icon {
display: inline-block;
position: relative;
top: -42px;
left: -25px;
cursor: pointer;
padding: 24px 14px;
z-index: 1;
}
.navicon {
background-color: #222222;
display: block;
height: 3px;
width: 26px;
position: relative;
transition: 0.3192s ease-in-out;
}
.navicon:before,
.navicon:after {
content: "";
display: block;
height: 100%;
width: 100%;
position: absolute;
background-color: #222222;
transition: 0.3192s ease-in-out;
}
.navicon:before {
top: 9px;
}
.navicon:after {
bottom: 9px;
}
/* Hamburger Menu Animation Start */
.menu-btn:checked~.menu-icon .navicon:before {
transform: rotate(-45deg);
top: 0;
}
.menu-btn:checked~.menu-icon .navicon:after {
transform: rotate(45deg);
bottom: 0;
}
.menu-btn:checked~.menu-icon .navicon {
background: transparent;
transition: 0.3192s ease-in-out;
}
/* Hide blue background on hamburger menu tap on some mobile devices */
.menu-icon,
.menu-btn,
.navicon {
-webkit-tap-highlight-color: transparent;
}
/* Nav items */
.menu {
background-color: #eeeeee;
width: 100%;
height: auto;
list-style-type: none;
position: absolute;
top: 0;
left: 0;
right: 0;
margin-top: 65px;
padding: 0;
visibility: hidden;
opacity: 0;
transition: visibility 0.3192s ease-in-out, opacity 0.3192s ease-in-out;
}
.menu-btn:checked~nav .menu {
visibility: visible;
opacity: 1;
transition: visibility 0.3192s ease-in-out, opacity 0.3192s ease-in-out;
}
.menu li {
border-top: 1px solid #c7c7c7;
padding: 10px 0;
opacity: 0;
transition: 0.5s;
}
.menu a {
color: #222222;
text-decoration: none;
font-weight: 500;
font-size: 0.9rem;
opacity: 0;
transition: 0.5s;
}
.menu-btn:checked~nav .menu a,
.menu-btn:checked~nav .menu li {
opacity: 1;
transition: 0.3192s ease-in-out;
}
/* Medium devices (landscape tablets, 768px and up) */
#media only screen and (min-width: 768px) {
header {
display: flex;
align-items: center;
justify-content: space-around;
}
.logo {
width: 60vw;
margin-top: 0;
justify-content: flex-start;
}
.menu-icon {
display: none;
}
nav {
width: 40vw;
margin-top: 0;
}
.menu {
width: 100%;
transform: none;
transition: none;
position: static;
margin: 0;
visibility: visible;
opacity: 1;
display: flex;
justify-content: space-around;
align-items: center;
}
.menu li {
border: none;
padding: 0;
opacity: 1;
transition: none;
}
.menu a {
opacity: 1;
transition: none;
}
}
<main id="main">
<header id="header">
<div class="logo">
<img id="header-img" src="https://s3.amazonaws.com/freecodecamp/original_trombones.png" alt="original trombones logo">
</div>
<input type="checkbox" class="menu-btn" id="menu-btn">
<label for="menu-btn" class="menu-icon"><span class="navicon"></span></label>
<nav id="nav-bar">
<ul class="menu">
<li>Feautures</li>
<li>How it Works</li>
<li>Pricing</li>
</ul>
</nav>
</header>
</main>

How can I get my website to scale properly when resized?

body {
padding: 0;
margin: 0;
font-family: 'Roboto', sans-serif;
font-size: 16px;
box-sizing: border-box !important;
}
a {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
text-decoration: none;
color: inherit;
}
a:hover,
a:link,
a:active {
text-decoration: none;
}
h1, h2, h3, h4, h5, h6, p {
margin: 0;
}
.container {
width: 100%;
height: 100%;
min-height: 100vh;
position: relative;
}
.main-content {
max-width: 800px;
margin: 0 auto;
padding: 50px 100px;
transition: transform .3s ease;
}
.header {
width: 100%;
height: 56px;
background: black;
}
.header-container {
height: 100%;
padding: 0 40px;
margin: 0 auto;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
position: relative;
}
.bottom, .right {
position: fixed;
background: black;
}
.right {
top: 0; bottom: 0;
width: 56px;
right: 0;
}
.bottom {
left: 0; right: 0;
height: 3.5vh;
bottom: 0;
}
.logo {
width: 10%;
}
.nav-bar {
display: flex;
flex-direction: row;
width: 90%;
align-items: center;
align-self: stretch;
}
#media screen and (max-width: 600px) {
.nav-bar {
position: absolute;
top: 56px;
left: 0;
width: 100%;
height: 0;
overflow: hidden;
background-color: black;
flex-direction: column;
justify-content: flex-start;
align-items: center;
z-index: 8888;
transition: height .3s .1s ease;
}
}
.nav-list {
list-style: none;
padding: 100px;
margin: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: row;
justify-content: flex-end;
align-items: center;
}
#media screen and (max-width: 600px) {
.nav-list {
display: flex;
flex-direction: column;
justify-content: flex-end;
align-items: space-evenly;
height: 80%;
/*
Initially list will be hidden and will reappear once the
nav-bar is opened
*/
visibility: hidden;
opacity: 0;
transition: visibility .2s ease, opacity .2s ease;
}
}
.nav-list-item {
align-self: stretch;
display: flex;
align-items: center;
justify-content: center;
position: relative;
right: 75.5vw;
left: -23.5vw;
transition: color .3s ease;
color: #989797;
}
.nav-list-item:not(:last-child) {
margin-right: 99px;
}
#media screen and (max-width: 600px) {
a {
justify-content: flex-start;
}
.nav-list-item {
margin: 0px auto 0px auto !important;
border-bottom: 1px solid #989797;
width: 80%;
justify-content: left;
padding: 15px 0;
}
}
.sub-list-container {
overflow: hidden;
position: absolute;
top: 56px;
left: 10%;
transform: translateX(-50%);
/* If we need show/hide feature */
height: inherit;
visibility: hidden;
opacity: 0;
transition: all .3s ease;
}
#media screen and (max-width: 600px) {
.sub-list-container {
display: none;
}
}
.sub-list {
width: 200px;
margin: 0;
padding: 0;
list-style: none;
display: flex;
flex-direction: column;
align-items: center;
background: black;
}
.sub-item {
color: #989797;
font-size: 16px;
padding: 10px;
position: relative;
align-self: stretch;
text-align: center;
z-index: 2;
transition: color .3s ease;
}
.sub-item:hover {
color: white;
}
.sub-item::before {
z-index: 1;
}
.nav-list-item:hover {
cursor: pointer;
color: white;
}
.nav-list-item:hover .sub-list-container {
/* For show/hide feature */
visibility: visible;
opacity: 1;
}
.toggle-nav {
display: none;
}
.toggle-nav-off {
display: none;
}
#media screen and (max-width: 600px) {
.toggle-nav {
display: block;
}
.toggle-nav-off {
display: block;
background: white;
border-radius: 50%;
height: 30px;
width: 30px;
}
:target {
/* Defining the height of the shutter effect */
height: calc(100vh - 56px);
}
:target .nav-list {
visibility: visible;
opacity: 1;
transition: visibility .2s .2s ease, opacity .2s .2s ease;
}
}
/* Code for the side-bar starts here */
.side-bar {
position: absolute;
top: 56px;
left: 0;
width: 60px;
/* Initial width according to size of image */
height: calc(100% - 56px);
background: black;
color: white;
overflow: hidden;
/* Imp to give as the List is having width larger than the initial width of the side-bar */
transition: all .3s ease;
}
.side-bar {
width: 8vw;
}
.side-bar-left {
position: absolute;
top: 56px;
right: 10px;
width: 60px;
/* Initial width according to size of image */
height: calc(100% - 56px);
background: black;
color: white;
overflow: hidden;
/* Imp to give as the List is having width larger than the initial width of the side-bar */
transition: all .3s ease;
width: 250px;
}
.item-list {
list-style: none;
width: 250px;
left: -3.2vw;
display: flex;
flex-direction: column;
position: relative;
z-index: 10;
}
.item {
display: flex;
justify-content: flex-start;
align-items: center;
align-self: stretch;
padding: 3.85vh .3vw;
transition: all .5s ease;
position: relative;
color: #989797;
}
.item:not(:last-child) {
margin-bottom: 5px;
}
.item:hover {
color: white;
cursor: pointer;
}
.item-img {
margin-right: 10px;
width: 10px;
height: 5px;
padding: 0 10px;
transition: all .3s ease;
}
.item #dribble, .item #behance, .item #flickr {
width: 3.5vw;
height: 7vh;
}
.item #instagram {
width: 3vw;
height: 6vh;
margin-left: .5vw;
}
.item #etsy {
width: 6vw;
height: 7vh;
margin-left: -2.1vw;
}
.item #behance {
margin-left: .3vw;
}
.item #flickr{
margin-left: -.5vw;
}
.item #dribble {
margin-left: .2vw;
}
.item #pinterest {
width: 3.5vw;
height: 7vh;
margin-left: .4vw;
}
/* Code for the HOVER effect on the list items */
.item::before {
transform: scaleY(0);
width: 3px;
transition: transform .2s ease, width .3s .2s ease;
}
.sub-item::before {
width: 0px;
transition: transform .1s ease, width .2s .1s ease;
}
.item::before,
.sub-item::before {
content: "";
position: absolute;
top: 0;
left: 0;
height: 100%;
background: linear-gradient(to bottom right, #ff506e, black);
z-index: -1;
}
.item:hover::before {
transform: scaleY(1);
}
.item:hover::before,
.sub-item:hover::before {
width: 100%;
}
.active {
color: #989797;
/* background: linear-gradient(to bottom right, #ff506e, black); THIS MAKES THE FIRST BUTTON ALWAYS RED AND HIGHLIGHTED, WHICH WE DON'T WANT */
}
.nav-active {
color: 989797;
}
.modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: hsl(200deg, 50%, 92%);
z-index: 9999;
visibility: hidden;
opacity: 0;
transition: all .3s ease;
}
.modal-item {
position: absolute;
width: 500px;
height: 350px;
background: url("https://37.media.tumblr.com/53fc4e7e4096cba63c0133167a4b6168/tumblr_n33ukkyWLN1rwhqloo1_500.gif");
background-position: center;
background-repeat: no-repeat;
border-radius: 2px;
padding: 10px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) scale(0);
transition: transform .3s ease;
}
.toggle-modal {
position: absolute;
top: 2vh;
left: 1.4vw;
}
/* Opening modal using CSS */
:target {
visibility: visible;
opacity: 1;
}
:target .modal-item {
transform: translate(-50%, -50%) scale(1);
}
/* .container {
display: grid;
height: 100%;
overflow: auto;
background: white;
} */
.iframe {
position: relative;
margin-left: -41.98vw;
top:52.09vh;
height: 92.322vh;
width: 90vw;
border: black;
}
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>"Users folio"</title>
<link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css'>
<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Roboto'>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
<header class="header">
<div class="header-container">
<div class="logo">
<!-- COMPANY LOGO GOES HERE -->
</div>
<nav class="nav-bar" id="nav">
<ul class="nav-list">
<li class="nav-list-item nav-active">Home</li>
<li class="nav-list-item">
About
<div class="sub-list-container">
<ul class="sub-list">
<li class="sub-item">About Our Company</li>
<li class="sub-item">Our Mission</li>
<li class="sub-item">Happy Clients</li>
<li class="sub-item">Team</li>
</ul>
</div>
</li>
<li class="nav-list-item">
Instructions
</li>
</ul>
<div class="toggle-nav-off">
<img src="https://icon-icons.com/icons2/1157/PNG/512/1487086345-cross_81577.png" alt="Close Icon" width="30" height="30">
</div>
</nav>
<div class="toggle-nav">
<img src="https://cdn2.iconfinder.com/data/icons/menu-elements/154/menu-round-512.png" alt="Close Icon" width="30" height="30">
</div>
<div class="container">
<!--
Currently just researching which sites are able to have their x-options
bypassed in order to allow viewing within an iframe, so disregard the iframe source.
-->
<iframe class="iframe" name="change-website" src="https://www.etsy.com"></iframe>
</div>
</header>
<div class="side-bar">
<ul class="item-list">
<li class="item active"><img id="behance" src="images/behance.png" width="50" height="50" class="item-img" />Behance</li>
<li class="item"><img id="dribble" src="images/dribble3.png" width="50" height="50" class="item-img" />Dribble</li>
<li class="item"><img id="etsy" src="images/etsy11.png" width="50" height="50" class="item-img"/>Etsy</li>
<li class="item"><img id="flickr" src="images/flick2.png" width="50" height="50" class="item-img" />Flickr</li>
<li class="item"><img id="instagram" src="images/Instagram_AppIcon_Aug2017.png" width="50" height="50" class="item-img" />Instagram</li>
<li class="item"><img id="pinterest" src="images/pinterest3.png" width="50" height="50" class="item-img" />Pinterest</li>
<!-- <li class="item"><img id="flickr" src="images/twitch3.png" width="50" height="50" class="item-img"/>Twitch</li> -->
</ul>
</div>
<div class="left-side-bar">
<p></p>
</div>
<div class="main-content">
<div class="modal" id="modal-item">
<div class="modal-item">
<div class="toggle-modal">
<img src="https://icon-icons.com/icons2/1157/PNG/512/1487086345-cross_81577.png" alt="Close Icon" width="30" height="30">
</div>
</div>
</div>
</div>
<div class="bottom"></div>
<div class="right"></div>
</div>
<link rel="stylesheet" href="scripts.js">
</body>
</html>
So I know that I need to use media queries to properly scale and put the code into different media queries for each max width ect.
Here is the code I have been working with, but when I change the size, even when I have tried to put them into different media queries and code them to that scale when I change the browser size, I still get issues where things like my iframe and the top menu bar moving and not being in the correct place.
I am still pretty new to frontend but I was just curious what I may be able to do to fix this?
When the browser resizes, everything should stay in its correct place.
The Home, About and Instructions should be starting from above the iframe and slightly past the top left of the iframe
Well, taking a look at your code, it's seen that you missed a meta tag to make your website resizable, add it on your head tag
<meta name="viewport" content="width=device-width, initial-scale=1">
This should fix your issue.

Label with IMG for event

So I was trying to make a website where if you click an img, a red block, 100% width, 100% height, covers everything.
body {
margin: 0;
background-color: white;
}
h1 {
font-size: 50px;
text-align: center;
font-family: Raleway;
color: red;
margin-top: 5%;
}
img {
margin-left: auto;
margin-right: auto;
display: block;
}
.redcover {
margin-top: -10%;
position: absolute;
width: 100%;
height: 110%;
background: red;
margin-left: -90%;
transition: all .3s ease-in-out;
-webkit-transition: all .3s ease-in-out;
-moz-transition: all .3s ease-in-out;
-ms-transition: all .3s ease-in-out;
}
#redcovertoggle:checked~.redcover {
margin-left: 0%;
}
<div class="redcover"></div>
<h1>HERZENSSACHE</h1>
<label>
<input type="checkbox" for="redcovertoggle">
<img src="https://image.ibb.co/d2aN15/heart2.png" alt="redcovertoggleheart">
</label>
I already tried for="redcovertoggle" in the label tag, but all it does is make the img stop acting like a label.
To do it with css only you can use :target selector and a link for the image, eg:
body {
margin: 0;
background-color: white;
}
h1 {
font-size: 50px;
text-align: center;
font-family: Raleway;
color: red;
margin-top: 5%;
}
img {
margin-left: auto;
margin-right: auto;
display: block;
}
#redcover {
margin-top: -10%;
position: absolute;
width: 100vw;
height: 100vh;
background: red;
left: -100vw;
z-index: 999;
transition: left 1s;
}
#redcover:target { left:0; }
<body>
<div id="redcover"></div>
<h1>HERZENSSACHE</h1>
<label>
<img src="https://image.ibb.co/d2aN15/heart2.png" alt="redcovertoggleheart">
</label>
</body>

How to stop button from moving

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>

Bootstrap button is not responsive - does not resize properly

I have an image with a button associated it, which launches a pop-up. When I test this on mobile, the button doesn't appropriately re-size with the image. You can see this by looking at the snippet below or on JSFiddle and trying to resize the screen. As you resize, you'll see that the image and button get out of sync, but I'm not sure how to fix it. Can you please provide some guidance?
Thanks!
JSFiddle
OR
/* Isotope Items
---------------------------------- */
.filters {
margin: 0 0 30px 0;
}
.filters .nav-pills > li {
margin-right: 2px;
margin-bottom: 2px;
}
.filters .nav-pills > li + li {
margin-left: 0px;
}
.text-center.filters .nav-pills > li {
margin-right: 2px;
margin-left: 2px;
margin-bottom: 2px;
display: inline-block;
float: none;
}
.isotope-container {
overflow: hidden;
}
.isotope-item {
margin-bottom: 20px;
}
.isotope-item .btn-default {
color: #999999;
}
.isotope-item .btn-default:hover {
color: #ffffff;
}
#media (max-width: 480px) {
.filters .nav-pills > li {
width: 100%;
display: block;
}
}
/* Images Overlay
----------------------------------------------------------------------------- */
.overlay-container {
position: relative;
display: block;
overflow: hidden;
}
.overlay {
position: absolute;
top: 0;
bottom: -1px;
left: 0;
right: -1px;
background-color: rgba(85, 172, 238, 0.9);
cursor: pointer;
overflow: hidden;
opacity: 0;
filter: alpha(opacity=0);
-webkit-transform: scale(0.8);
transform: scale(0.8);
-webkit-transition: all linear 0.2s;
-moz-transition: all linear 0.2s;
-ms-transition: all linear 0.2s;
-o-transition: all linear 0.2s;
transition: all linear 0.2s;
}
.overlay:hover {
text-decoration: none;
}
.overlay span {
position: absolute;
display: block;
bottom: 10px;
text-align: center;
width: 100%;
color: #ffffff;
font-size: 13px;
font-weight: 300;
}
.overlay i {
position: absolute;
left: 50%;
top: 50%;
font-size: 18px;
line-height: 1x;
color: #ffffff;
margin-top: -8px;
margin-left: -8px;
text-align: center;
}
.overlay-container:hover .overlay {
opacity: 1;
filter: alpha(opacity=100);
-webkit-transform: scale(1);
transform: scale(1);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-xs-6 col-sm-6 col-md-3 isotope-item bridesmaid">
<div class="image-box">
<div class="overlay-container">
<img src="http://lorempixel.com/300/200/" alt="">
<a class="overlay" data-toggle="modal" data-target="#project-1">
<i class="fa fa-search-plus"></i>
<span>Hover Info</span>
</a>
</div> <a class="btn btn-default btn-block" data-toggle="modal" data-target="#project-1">Person</a>
</div>
</div>
Please Check this Link it may help in this i just define
img
{
width:100%;
}
Try Demo