I am trying to create a effect when you hover over my abbrivated name it expands to its full size however,I've run into a problem that detracts from the visual appeal of the website I'm trying to achieve and makes it appear tacky.What I want is for the element to expand in a isolated manner and does not affect anything else on the website.
Here is the link:https://jsfiddle.net/dkpsgo73/
<nav>
<header>
<h1 >
[
<span id="zk-trigger"><span > S</span><span id="hide1" ><span >eid</span></span>
J<span id="hide2" >ama</span>
</span>
]
</h1>
</header>
<!-- Navigational Bar -->
<div >
<ul>
<li><a href="#Home">Home</a></li>
<li><a href="#About">About</a></li>
<li><a href="#Projects">Projects</a></li>
<li><a href="#Skills">Skills</a></li>
<li><a href="#Contact">Contact</a></li>
</ul>
</div>
<!-- Navigational Bar -->
</nav>
I read a lot of different advise on the subject, including position absolute and z-index, but I was unable to find a solution because I am still very new to learning how to code.
CodePudding user response:
Add the following CSS:
header {
min-width: 200px;
}
See the snippet below.
html,
body {
margin: 0;
font-family: "Rubik", sans-serif;
background-color: #333333ff;
}
/* Font Config */
h1 {
font-weight: normal;
font-size: 25px;
text-transform: uppercase;
letter-spacing: 1px;
margin: 0 0 0 0;
color: #f6f2f0;
}
/* Navigation Bar */
nav {
/*Keeps the nav fixed*/
position: fixed;
/*Size of the nav bar*/
height: 70px;
width: 100%;
/*Spaces out the nav elements*/
display: flex;
justify-content: space-around;
align-items: center;
padding: 0 10px;
/*Blur property*/
backdrop-filter: blur(5px);
background-color: #262626ff;
opacity: 0.9;
border-bottom: 5px solid #6527a7ff;
}
/* Navigation Bar */
.Name {
display: inline;
font-style: italic;
}
#hide1,
#hide2 {
display: inline-block;
max-width: 0;
opacity: 0;
transition: max-width 0.2s, opacity 0.2s;
}
#zk-trigger:hover #hide1,
#zk-trigger:hover #hide2 {
max-width: 100px;
opacity: 1;
transition: max-width 0.5s, opacity 0.2s;
}
.Fname {
color: #ffc000;
}
li {
display: inline;
padding: 8px;
font-size: 20px;
}
/* My Nav List Position */
.nav-menu {
display: flex;
justify-content: flex-end;
}
/* My Nav List Position */
/* Navigation Link Interaction */
.nav-menu li a {
color: #f6f2f0;
}
.nav-menu li a:link {
text-decoration: none;
}
.nav-menu li a:hover {
color: #ffc000;
text-decoration: none;
}
/* Navigation Link Interaction */
/* Added */
header {
min-width: 200px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Portfolio</title>
<link href="Styles.css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css2?family=Rubik:wght@300;400&display=swap" rel="stylesheet" />
</head>
<body>
<nav>
<header>
<h1 >
[
<span id="zk-trigger"><span > S</span><span id="hide1" ><span >eid</span></span>
J<span id="hide2" >ama</span>
</span>
]
</h1>
</header>
<!-- Navigational Bar -->
<div >
<ul>
<li><a href="#Home">Home</a></li>
<li><a href="#About">About</a></li>
<li><a href="#Projects">Projects</a></li>
<li><a href="#Skills">Skills</a></li>
<li><a href="#Contact">Contact</a></li>
</ul>
</div>
<!-- Navigational Bar -->
</nav>
</body>
</html>
CodePudding user response:
I notice that your nav goes wider than 100% since it adds the 10px inline-padding. You can avoid this by using box-sizing:border-box
so that the box size is inclusive of padding. Doing so then allows you to justify your navigation bar as space-between
and thus stopping your nav shifting when your header expands.
EG:
html,
body {
margin: 0;
font-family: "Rubik", sans-serif;
background-color: #333333ff;
}
/* consistent box-sizing where width is inclusive of padding */
* {box-sizing:border-box}
/* Font Config */
h1 {
font-weight: normal;
font-size: 25px;
text-transform: uppercase;
letter-spacing: 1px;
margin: 0 0 0 0;
color: #f6f2f0;
white-space:nowrap;
}
/* Font Config */
/* Navigation Bar */
nav {
/*Keeps the nav fixed*/
position: fixed;
/*Size of the nav bar*/
height: 70px;
width: 100%;
/*Spaces out the nav elements*/
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 10px;
/*Blur property*/
backdrop-filter: blur(5px);
background-color: #262626ff;
opacity: 0.9;
border-bottom: 5px solid #6527a7ff;
}
/* Navigation Bar */
.Name {
display: inline;
font-style: italic;
}
#hide1,
#hide2 {
display: inline-block;
max-width: 0;
opacity: 0;
transition: max-width 0.2s, opacity 0.2s;
}
#zk-trigger:hover #hide1,
#zk-trigger:hover #hide2 {
max-width: 100px;
opacity: 1;
transition: max-width 0.5s, opacity 0.2s;
}
.Fname {
color: #ffc000;
}
li {
display: inline;
padding: 8px;
font-size: 20px;
}
/* My Nav List Position */
.nav-menu {
display: flex;
justify-content: flex-end;
}
/* My Nav List Position */
/* Navigation Link Interaction */
.nav-menu li a {
color: #f6f2f0;
}
.nav-menu li a:link {
text-decoration: none;
}
.nav-menu li a:hover {
color: #ffc000;
text-decoration: none;
}
/* Navigation Link Interaction */
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Portfolio</title>
<link href="Styles.css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css2?family=Rubik:wght@300;400&display=swap" rel="stylesheet" />
</head>
<body>
<nav>
<header>
<h1 >
[
<span id="zk-trigger"><span > S</span><span id="hide1" ><span >eid</span></span>
J<span id="hide2" >ama</span>
</span>
]
</h1>
</header>
<!-- Navigational Bar -->
<div >
<ul>
<li><a href="#Home">Home</a></li>
<li><a href="#About">About</a></li>
<li><a href="#Projects">Projects</a></li>
<li><a href="#Skills">Skills</a></li>
<li><a href="#Contact">Contact</a></li>
</ul>
</div>
<!-- Navigational Bar -->
</nav>
</body>
</html>