just to preface I would say I'm rather new at coding, in particular, this is related to web coding.
I am using HTML and CSS to code a website and I've created a navbar with animation upon hovering. I followed a tutorial to do so and edited the values accordingly to fit with my website. All was fine, I saved it and opened it again and it was working just fine.
However I opened it up again today and all of the menu options have just been squashed to one side, though the animations still moved to the correct place when hovering over it. I had not edited any of the code and am unsure how to fix it.
I've tried to edit the position (left) of each menu item but it doesn't seem to be working.
Visualisation of the problem
here is the HTML coding for it:
<nav>
HOME
ABOUT
RECIPES
GALLERY
SUBSCRIBE
<div class="animation start-home"></div>
</nav>
And here is the CSS
nav {
position: relative;
width: 100%;
height: 55px;
background-color: white;
border-radius: 8px;
font-size: 0;
box-shadow: 0 2px 3px 0 rgba(0, 0, 0, .1)
}
nav a{
font-family: dunbar-tall, sans-serif;
font-weight: 500;
font-style: normal;
font-size: 15px;
text-transform: uppercase;
color: #d79da8;
text-decoration: none;
line-height: 50px;
position: relative;
z-index: 1;
/* display: inline-block; */
text-align: center;
}
nav .animation {
position: absolute;
height: 100%;
top: 0;
z-index: 0;
background: whitesmoke;
border-radius:8px;
transition: all .5s ease 0s;
}
nav a:nth-child(1){
width:120px
}
nav .start-home, a:nth-child(1):hover~.animation{
width: 120px;
left: 00;
}
nav a:nth-child(2){
width: 120px;
}
nav a:nth-child(2):hover~.animation{
width: 150px;
left:102px;
}
nav a:nth-child(3){
width: 120px;
}
nav a:nth-child(3):hover~.animation{
width: 140px;
left: 230px;
}
nav a:nth-child(4){
width: 120px;
}
nav a:nth-child(4):hover~.animation{
width: 140px;
left: 350px;
}
nav a:nth-child(5){
float:right;
margin-right: 40px;
}
nav a:nth-child(5):hover~.animation{
width: 150px;
left: 1290px;
}
a:hover{
color: #c18392;
}
(Also I am aware the navbar doesn't navigate to anything yet)
Please help!
And thank you in advance
nav:adding display:flex to put them in one line. putting gap:10px that is the gap between all the a tags. setting width to 100vw meaning 100% view-width . everything else is the same as you have added previously.
nav a:same as you have added.
nav a:nth-child(5) meaning the last of the a tag with subscribe. adding margin-left:auto meaning what ever space is left in the container put it to the last a tag's left. i hope it makes sense.
hover:adding different bgcolor on hover. but you can do anything you want
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
nav {
padding: 10px;
display: flex;
align-items: center;
gap: 10px;
width: 100vw;
height: 55px;
background-color: white;
border-radius: 8px;
font-size: 0;
box-shadow: 0 2px 3px 0 rgba(0, 0, 0, .1);
}
nav a {
font-family: dunbar-tall, sans-serif;
font-weight: 500;
font-style: normal;
font-size: 15px;
text-transform: uppercase;
color: #d79da8;
text-decoration: none;
line-height: 50px;
}
nav a:nth-child(5) {
margin-left: auto;
}
a:hover {
background-color: whitesmoke;
}
<nav>
HOME
ABOUT
RECIPES
GALLERY
SUBSCRIBE
<div class="animation start-home"></div>
</nav
I want to make a small button hover animation. the animation is like that:
a blue div which have the same width an height as the button comes from the bottom left of the button to cover it. The problem is that they have not the same height and width.
Here's the HTML and the css :
[![button{
box-sizing: border-box;
background-color: transparent;
border: none;
display: inline-block;
}
.button-wrapper {
position: relative;
overflow: hidden;
padding: 15px 30px;
font-family: 'Montserrat', sans-serif;
font-weight: bold;
font-size: 14px;
line-height: 20px;
border: solid 2px #2A5A8B;
border-radius: 6px;
text-decoration: none;
color: #2A5A8B;
cursor : pointer;
transition: all .5s;
z-index: 1;
}
.button-wrapper::after{
width: 100%;
height: 100%;
margin: auto;
position: absolute;
bottom: -100%;
right: -100%;
background-color: #2A5A8B;
transition: all .25s;
z-index: -1;
content: '';
}
.button-wrapper:hover{
color: white;
}
.button-wrapper:hover::after{
transform: translateX(-100%) translateY(-100%);
}
<button>
<div className='button-wrapper'>
{Login}
</div>
</button>
PS: it's working properly on firefox.
Im making an online game and was making the play button, but had the following issue:
What i want to achieve:
What is happening:
For some reason the background of the text is getting transparent...
HTML:
.wrapper {
display: flex;
justify-content: center;
}
.cta {
display: flex;
padding: 10px 45px;
text-decoration: none;
font-family: "Ceviche One", sans-serif;
font-size: 55px;
color: white;
background: #6225e6;
transition: 1s;
box-shadow: 6px 6px 0 black;
transform: skewX(-15deg);
}
.cta:focus {
outline: none;
}
.cta:hover {
transition: 0.5s;
box-shadow: 10px 10px 0 #fbc638;
}
.cta span:nth-child(2) {
transition: 0.5s;
margin-right: 0px;
}
.cta:hover span:nth-child(2) {
transition: 0.5s;
margin-right: 45px;
}
span {
transform: skewX(15deg);
}
span:nth-child(2) {
width: 20px;
margin-left: 30px;
position: relative;
top: 12%;
}
<div class="wrapper">
<a class="cta" href="#">
<span>JUGAR</span>
</a>
</div>
Any idea how to fix this? It works fine in codepen but not in my project.
Because you are applying the color on class cta which is parent for the text JUGAR. You need to set the color to the span not a tag
I was accidentaly applying a background-color to everything with *{}
I wan the arrows on my navbar to produce the animation I've created when I hover the options on top of them,
When my mouse hovers "contact", "register" or "login", the arrows under them should move down indicating that they are dropdown buttons, how can I do this? I already have the code of the animation but I don't know how to sync this code with my buttons, I would appreciate any help. Here's the code:
#arrow1 {
position: absolute;
top: 11%;
left: 83.5%;
transform: translate(-50%, -50%);
width: 15px;
height: 100px;
text-align: center;
line-height: 110px;
color: white;
font-size: 30px;
overflow: hidden;
color: yellow;
}
#arrow1 {
margin: 0;
padding: 0;
animation: animate 1s;
right: 0;
pointer-events: none;
}
#keyframes animate {
50% {
transform: translateX(-8px);
margin-top: -35px;
}
}
#arrow2 {
position: absolute;
top: 11%;
left: 66%;
transform: translate(-50%, -50%);
width: 15px;
height: 100px;
text-align: center;
line-height: 110px;
color: white;
font-size: 30px;
overflow: hidden;
color: yellow;
}
#arro2 {
margin: 0;
padding: 0;
animation: animate 1s;
right: 0;
pointer-events: none;
}
#keyframes animate {
50% {
transform: translateX(-8px);
margin-top: -35px;
}
}
#arrow3 {
position: absolute;
top: 11%;
left: 48.7%;
transform: translate(-50%, -50%);
width: 15px;
height: 100px;
text-align: center;
line-height: 110px;
color: white;
font-size: 30px;
overflow: hidden;
color: yellow;
}
#arrow3 {
margin: 0;
padding: 0;
animation: animate 1s;
right: 0;
pointer-events: none;
}
#keyframes animate {
50% {
transform: translateX(-8px);
margin-top: -35px;
}
}
<ul>
<li id="inicio">INICIO</li>
<li id="contacto">CONTACTO</li>
<li id="registrate">REGISTRATE</li>
<li id="ingresar">INGRESAR</li>
<div class="circle">
<i class="fas fa-angle-down" id="arrow1"></i>
<i class="fas fa-angle-down" id="arrow2"></i>
<i class="fas fa-angle-down" id="arrow3"></i>
</div>
</ul>
Since you have your animation assigned to each arrow ID, that animation is playing on page load.
To have the animation play only when the cursor is hovering over the element, you need to add a :hover pseudo-class to each arrow and add the animation within that block.
#arrow1:hover {
animation: animate 1s;
}
After doing that, you should have something like this:
#container {
width: 100%;
height: 80px;
background: #151515;
}
#container,
.navItem {
display: flex;
flex-flow: column wrap;
justify-content: center;
align-items: center;
transform: translateZ(0);
}
.navItem {
cursor: pointer;
}
.navItem:hover .arrow {
animation: animate 1s;
}
.navText {
font-family: 'Arial', sans-serif;
color: #fff;
text-transform: uppercase;
letter-spacing: 1px;
}
.arrow {
position: absolute;
color: #ffff4c;
bottom: -15px;
}
#keyframes animate {
50% {
transform: translateY(8px);
margin-top: -35px;
}
}
<script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
<div id="container">
<div class="navItem">
<div class="navText">
Contacto
</div>
<i class="fas fa-angle-down arrow"></i>
</div>
</div>
You may notice that I also edited the HTML and CSS for that example, but the idea is the same. This brings me to my next point, and something that may help you.
Classes
Using ID's is a perfectly acceptable way to write your markup and use CSS to style; however, using id as opposed to class can be cumbersome. Since you have multiple arrows, I would advise using classes as opposed to ID's.
So, all of your arrows would be assigned a class. In my example, I used a simple .arrow class. This is proper CSS styling. ID's are unique and should only be used sparingly, usually only once in a document. Classes are reused.
I should also note that this is purely a syntactical thing. CSS will treat ID's and classes similarly if you require it.
Transitions
You may have also noticed that the animation in my example stops if you hover away from the navItem. This is expected behavior if using a :hover pseudo-class on an element. A workaround is substituting an animation for a transition.
Transitions are an alternate way to apply animated properties to elements. They will animate 'forward' and 'backward' on, say, pseudo-classes like :hover and :focus.
Here's what that example looks like with a transition in place of an animation.
#container {
width: 100%;
height: 80px;
background: #151515;
}
#container,
.navItem {
display: flex;
flex-flow: column wrap;
justify-content: center;
align-items: center;
transform: translateZ(0);
}
.navItem {
cursor: pointer;
}
.navItem:hover .arrow {
transform: translateY(8px);
}
.navText {
font-family: 'Arial', sans-serif;
color: #fff;
text-transform: uppercase;
letter-spacing: 1px;
}
.arrow {
position: absolute;
color: #ffff4c;
bottom: -15px;
transition: all 1s;
}
<script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
<div id="container">
<div class="navItem">
<div class="navText">
Contacto
</div>
<i class="fas fa-angle-down arrow"></i>
</div>
</div>
So this gives you a much smoother interaction when hovering over a menu.
Pseudo Elements
Lastly, I want to touch up on using Pseudo Elements for things like icons. They're useful for adding additional children to a parent element, without affecting your written markup.
We can replace the arrows with a pseudo-element to clean up our HTML, as well as creating a more manageable workspace. Here's that example, again, but using a pseudo-element in place of HTML for the arrow.
#container {
width: 100%;
height: 80px;
background: #151515;
}
#container,
.navItem {
display: flex;
flex-flow: column wrap;
justify-content: center;
align-items: center;
transform: translateZ(0);
}
.navItem {
cursor: pointer;
}
.navItem:hover .navText::after {
transform: translateY(8px);
}
.navText {
font-family: 'Arial', sans-serif;
color: #fff;
text-transform: uppercase;
letter-spacing: 1px;
text-align: center;
}
.navText::after {
content: "\f107";
font-family: 'FontAwesome';
color: #FFFF00;
position: absolute;
transition: all 1s;
}
<script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
<div id="container">
<div class="navItem">
<div class="navText">
Contacto
</div>
</div>
</div>
Conclusion
Should you have any further questions, I'd be happy to answer them and go more in depth.
I also leave you with this final example via Codepen:
https://codepen.io/jeffheral/pen/NYKbZq
The HTML tags may not be what you want, but feel free to change them. The important thing is we have a solid setup of ID's and classes. If you want to add more navigation items, you only need to add more HTML to your document.
Instead of targetting every arrow individually, you can use a more generic solution:
.menu {
display: flex;
list-style: none;
background-color: #444;
}
.menu li {
padding: 10px 15px;
cursor: pointer;
padding-bottom: 20px;
position: relative;
margin: 5px;
color: white;
font-weight: bold;
font-family: sans-serif;
}
.menu li:after {
font-family: FontAwesome;
font-size: 20px;
font-weight: bold;
content: '\f107';
display: inline-block;
color: yellow;
position: absolute;
bottom: 0;
left: 50%;
transform: translate(-50%, 0);
transition: transform 0.3s ease;
}
.menu li:hover {
background-color: rgba(0, 0, 0, 0.25);
}
.menu li:hover:after {
transform: translate(-50%, 5px);
}
<ul class="menu">
<li>INICIO</li>
<li>CONTACTO</li>
<li>REGISTRATE</li>
<li>INGRESAR</li>
</ul>
I'm looking for a CSS only solution to fade an image in a back DIV when hovering over any section of the DIV, including DIVs that are in front of it.
Here is what I've been able to build so far: http://jsfiddle.net/kqo10jLb/
The CSS:
#caseouter {
position: relative;
top: 0px;
}
#casewrap2 {
background-color: #000;
}
#casetitle {
font-size: 30px;
width: 100%;
display: block;
text-transform: uppercase;
text-align: center;
padding: 10px 0px 0px 0px;
color: #fff;
margin-bottom: 0px;
}
#casethumb {
width: 100%;
display: block;
margin-bottom: -100px;
opacity: 1;
transition: .2s opacity ease .2s;
height: 100px;
}
#casesecondline {
font-size: 30px;
color: #666;
text-transform: uppercase;
margin: 0 auto;
display: block;
width: 100%;
text-align: center;
color: #fff;
margin-top: -10px;
padding: 0px;
}
#casethumb img {
width: 100%;
}
#casethumb:hover {
opacity: .75;
}
#casetitle:hover ~ #casethumb a {
opacity: .75;
}
#casesecond:hover ~ #casethumb a {
opacity: .75;
}
And the HTML:
<div id="casewrap2">
<div id="casethumb">
<a href="www.google.com">
<img src="http://ringer.tv/wp-content/uploads/2014/08/case_bravo.jpg">
</a>
</div>
</div>
<div id="caseouter">
<a href="www.google.com">
<div id="casetitle">Headline</div>
<div id="casesecondline">Subheadline</div>
</a>
</div>
As you'll see, the back image fades on hover, however, it will not fade when I hover over the headline and subheadline text. I've tried using #casetitle:hover ~ #casethumb a but I'm obviously doing something wrong. Thanks!
Is this what you're after? http://jsfiddle.net/kqo10jLb/1/
I moved the caseouter into the casewrap2 object and changed the hover to this:
#casewrap2:hover #casethumb {
opacity: .75;
}