Css making transition of margin and padding - html

I made a navigator on top of my website, I want it to shrink a bit when I hover over it.
.top-container ul>li{
display: inline;
float: left;
margin: 5px 15px;
padding: 0;
scale: 1;
background-color: white;
border: solid 0px #333;
transition: padding ease-out .3s, margin ease-out .3s,
border ease-out .3s, background-color ease-out .3s;
}
.top-container ul>li:hover{
background-color: red;
padding: 5px 15px;
margin: 0;
}
(its not the full code of style sheet!)
okay so when I use this code, my list elements starting to shake when I hover over.
how can I solve this problem?
or is there a more efficient way to do this?
Also i tried scale and Transform: scale(); did not give me what i want because they scaled up the text and border too D:
Here is the Web site the issue is current.
https://akiokiyota.github.io/RemoteWebsite/

You need to separate the text and visual components. The text does not change, so it makes no sense to animate the entire block with text, but will be limited only to decoration when hovering.
Another very bad practice is that the size of the menu item (element a) is smaller than the element li, pointing at which activates the animation. This may confuse the user.
How would I do:
header {
display: flex;
align-items: center;
font-family: sans-serif;
font-stretch: condensed;
}
header a {
text-decoration: none;
color: #333;
}
.logo {
margin-right: auto;
font-size: 300%;
font-weight: 400;
}
.top-container {
white-space: nowrap;
}
.top-container ul,
.top-container li {
list-style: none;
display: inline;
}
.top-container ul>li>a {
font-size: 120%;
padding: 5px 15px;
position: relative;
}
.top-container ul>li>a::after {
content: "";
z-index: -1;
position: absolute;
background-color: red;
transition: ease-out 0.3s;
width: 0;
height: 0;
left: 50%;
top: 50%;
}
.top-container ul>li>a:hover::after {
left: 0;
top: 0;
width: 100%;
height: 100%;
}
<header>
<h1 class="logo">QZEN</h1>
<div class="top-container">
<ul>
<li>HOME</li>
<li>GAMES</li>
<li>ARTS</li>
<li>ASSETS</li>
<li>ABOUT</li>
</ul>
</div>
</header>

Related

Div Wider than Viewport

I am currently coding a responsive menu using the checkbox hack and noticed that when my menu appears after clicking the hamburger icon, it is wider than the viewport. The menu has a fixed position and a flex display. I have added red borders around elements to give show this issue. Here is the relevant code:
/* General styles */
html, body { height: 100%; }
body {
font-family: 'Miriam Libre', sans-serif;
}
a {
color: white;
text-decoration: none;
transition: 0.2s;
}
a:hover {
color: #ea3c53;
}
/* Navigation styles */
nav {
position: absolute;
top: 0;
left: 0;
width: 100%;
background: #222222;
}
.donate {
position: absolute;
margin: 21px;
}
nav .brand {
display: block;
height: 70px;
margin: 10px auto;
}
input[type=checkbox] {
position: absolute;
top: -9999px;
left: -9999px;
}
nav label {
position: absolute;
top: 0;
right: 0;
padding: 21px;
background: #63E2C6;
cursor: pointer;
z-index: 2;
}
nav > label > span {
display: block;
margin: 4px auto;
height: 4px;
width: 25px;
border-radius: 1px;
background: #ffffff;
transition: 0.5s;
}
.menu {
display: flex;
position: fixed;
flex-direction: column;
align-items: center;
justify-content: center;
margin: 0;
top: -100vh;
left: 0;
height: 100vh;
width: 100%;
background: #222;
list-style-type: none;
border: 1px solid red;
transition: top 0.5s cubic-bezier(0.3, 0.1, 0.3, 0.85);
}
.menu li {
font-size: 30px;
border: 1px solid red;
}
input[type=checkbox]:checked ~ .menu {
top: 0;
}
<nav>
<!-- Top bar -->
Donate
<img src="media/logo2.png" alt="Logo" class="brand">
<input type="checkbox" id="nav">
<label for="nav">
<span></span>
<span></span>
<span></span>
</label>
<ul class="menu">
<li>Home.</li>
<li>Mission.</li>
<li>Contact.</li>
</ul>
</nav>
So, my question is, why is this happening? After all, I do have the width set to 100%, not 110%.
You have margin on your body element. Add:
body {
margin: 0;
}
There is also default margin and padding on your ul element that is also being set to width: 100%;
I recommend checking all of your primary containers, looking at them in your browser's inspector will highlight when you have additional spacing on an element that you may not be accounting for.

CSS Sliver on Nav animation

So as I was updating my design website, I encountered a problem (?). It's hard to quantify because it shows at different times when I resize my browser. But I can see it when it's full screen on my laptop.
In my navigation, I have a right to left animation. The background color is white and it slides to a dark gray. But, when I'm full screen in Chrome, there is a small sliver on the right of "HIRE ME" (this link isn't currently functional btw). Like I said before, when I re-size my screen it flashes and disappears not only of the "HIRE ME," but on all of the nav links.
I don't know if this is some semantic code problem or merely the browser compatibility. Any assistance would be great. I'd attached a bit of the code, although the issue doesn't show there, but my website.
WARNING! I am a graphic designer by trade, so my mostly self-taught code is probably uglier than mud on a white picket fence to most. If you have any suggestions for semantics, I would definitely appreciate that as well. Thank you in advance!
www.kelsiewilson.co/
#import url(https://fonts.googleapis.com/css?family=Playfair+Display:400,900);
#import url(https://fonts.googleapis.com/css?family=Fira+Sans+Extra+Condensed:400,700);
.yellowline {
width: 100%;
height: 8px;
background-color: #FFC45C;
}
.outline {
width: 20%;
padding: 130px 20%;
margin: -10px 0 0 31.5%;
border: .75px solid #FFC45C;
}
h1.name {
margin-left: 26%;
font-size: 72px;
font-family: 'Playfair Display', serif;
letter-spacing: 1.2px;
font-weight: 900;
margin-top: -170px;
color: #2B343E;
}
nav {
margin: 0 auto;
display: block;
text-align: center;
padding-bottom: 100px;
padding-top: 10px;
}
nav ul {
display: inline-block;
list-style-type: none;
}
nav ul li {
float: left;
margin: 0 auto;
clear: float;
}
nav ul li.active a {
color: #2B343E;
}
nav ul li.active:hover a {
color: white;
}
nav ul li a {
font-size: 16px;
font-family: 'Fira Sans Extra Condensed', sans-serif;
font-weight: 400;
color: #d3d3d3;
width: 100px;
padding: 4px 16px;
margin: 0 50px;
background: #fff;
background: linear-gradient(to left, #2B343E 50%, white 50%);
background-size: 200% 100%;
background-position: left bottom;
margin-left: 10px;
transition: all 2s ease;
text-decoration: none;
border-right: solid 0px #6b5d53;
}
nav li:hover a {
font-family: 'Fira Sans Extra Condensed';
font-weight: 400;
background-position: right bottom;
color: white;
}
<div class="yellowline">
</div>
<div class="outline">
</div>
<header>
<h1 class="name">Kelsie Wilson</h1>
</header>
<nav>
<ul>
<li class="active">WORK</li>
<li>ABOUT</li>
<li>HIRE ME</li>
</ul>
<div class="keepopen"></div>
</nav>
The problem here is, that you're using the background position for your animation. (I'm not entirely sure what exactly is the reason why it's shown, but i would assume that it's because chrome renders the background a pixel too far to the left.)
But, nonetheless, it's bad pratice to animate the background property since it causes the browser to repaint the page.
One solution to solve this could be to use a pseudo element and transform: scale() for the animation:
nav ul li a::after {
content: "";
position: absolute;
background: #2B343E;
width: 100%;
height: 100%;
left: 0;
top: 0;
transform: scaleX(0); // scales the width down to 0
transform-origin: 100% 100%; //set transform origin to right-most,
//otherwise it would scale from the center of the button
transition: all 2s ease; // pseudo element needs its own transition
z-index: -1; // set z-index to -1 so that the link text is visible
}
and then for the hover:
nav li:hover a:after {
transform: scaleX(1); // scale the width to normal size
}
if you do it this way, you also need to add
position: relative;
to your a
Here's some further reading about cheap and not so cheap animations to help you understand why i chose to animate with transform: scale.
Here's the complete updated code, hope this helps :) :
#import url(https://fonts.googleapis.com/css?family=Playfair+Display:400,900);
#import url(https://fonts.googleapis.com/css?family=Fira+Sans+Extra+Condensed:400,700);
.yellowline {
width: 100%;
height: 8px;
background-color: #FFC45C;
}
.outline {
width: 20%;
padding: 130px 20%;
margin: -10px 0 0 31.5%;
border: .75px solid #FFC45C;
}
h1.name {
margin-left: 26%;
font-size: 72px;
font-family: 'Playfair Display', serif;
letter-spacing: 1.2px;
font-weight: 900;
margin-top: -170px;
color: #2B343E;
}
nav {
margin: 0 auto;
display: block;
text-align: center;
padding-bottom: 100px;
padding-top: 10px;
}
nav ul {
display: inline-block;
list-style-type: none;
}
nav ul li {
float: left;
margin: 0 auto;
clear: float;
}
nav ul li.active a {
color: #2B343E;
}
nav ul li.active:hover a {
color: white;
}
nav ul li a {
position: relative; //<-- added position: relative
font-size: 16px;
font-family: 'Fira Sans Extra Condensed', sans-serif;
font-weight: 400;
color: #d3d3d3;
width: 100px;
padding: 4px 16px;
margin: 0 50px;
margin-left: 10px;
transition: all 2s ease;
text-decoration: none;
border-right: solid 0px #6b5d53;
}
nav ul li a::after {
content: "";
position: absolute;
background: #2B343E;
width: 100%;
height: 100%;
left: 0;
top: 0;
transform: scaleX(0);
transform-origin: 100% 100%;
transition: all 2s ease;
z-index: -1;
}
nav li:hover a {
font-family: 'Fira Sans Extra Condensed';
font-weight: 400;
color: white;
}
nav li:hover a:after {
transform: scaleX(1);
}
<div class="yellowline">
</div>
<div class="outline">
</div>
<header>
<h1 class="name">Kelsie Wilson</h1>
</header>
<nav>
<ul>
<li class="active">WORK</li>
<li>ABOUT</li>
<li>HIRE ME</li>
</ul>
<div class="keepopen"></div>
</nav>

Extra space underneath navigation bar

I'm currently trying to make a website, and I managed to create a navigation bar. However, there is a weird "extra" space between my navigation bar. It was working fine at first but after I referenced a JQuery. However, I doubt the JQuery is the one that caused the problem as the site looks the same even after I took it out. Here's a screenshot of the problem. I'm trying to get rid of the circled part.
My HTML code:
<div id="nav"> <!-- Navigation Bar -->
<nav>
<ul>
<li><a class="selected" href="#">Home</a></li>
<li>About Me</li> <!-- Link to about page -->
<li class="drop">
Games
<div class="drop-content">
Red Faction: Guerrilla <!-- Contains links to the respective pages -->
Way of the Samurai 3
Singularity
</div>
</li>
<li>Reviews</li>
<li>External Store</li> <!-- Link to external site -->
<li>Videos</li> <!-- Contains links to Youtube -->
<li>Feedback</li> <!--Feedback form-->
And here's the stylesheet:
#nav nav{ /* Navigation bar*/
padding-top: 5%;
margin-bottom: 5% }
#nav ul {
list-style-type: none;
margin: 0;
background-color: #1C86EE;
padding: 0;
position: relative;
width: 100%;
bottom: 0;
display: inline-block }
#nav li {
float: left;
width: 14% }
li a, .dropbtn {
display: inline-block;
color: #FFFFFF;
text-align: center;
padding-left: 15%;
padding-right: 15%;
text-decoration: none }
.selected {
background-color: #6CCC0A;
padding-right: 25% }
li a:hover, .drop:hover .dropbtn {
background-color: #BFA810 }
a {
padding-top: 1em;
padding-bottom: 1em }
li.drop {
display: inline-block }
.drop-content {
display: none;
position: absolute;
background-color: #970707;
min-width: 14%;
box-shadow: 0px 8px 16px 0px #000000;
z-index: 100 }
.drop-content a {
color: #FFFFFF;
padding: 15px 20px;
display: block;
text-align: left }
.drop-content a:hover {
background-color: #02BBC4 }
.drop:hover .drop-content {
display: block;
border: 1px solid black;
position: absolute } /*End of navigation*/
* { /* index style */
box-sizing:border-box
}
body {
font-family: Verdana,sans-serif;
margin:0
}
.slideshow-fade {
display:none
}
/* Slideshow container */
.slideshow {
max-width: 100%;
position: relative;
margin: auto;
}
.slideshow img {
opacity: 0.7
}
/* Next & previous buttons */
.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 1em;
margin-top: -1em;
color: #FFFFFF;
font-weight: bold;
font-size: 1.5em;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
}
/* Caption text */
.text {
color: #000000;
font-size: 1.3em;
padding: 1% 2%;
position: absolute;
bottom: 2%;
width: 100%;
text-align: center;
}
/* Number text (1/3 etc) */
.number {
color: #000000;
font-size: 1em;
padding: 8px 12px;
position: absolute;
top: 0;
}
/* The dots/bullets/indicators */
.dot {
cursor: pointer;
height: 1em;
width: 4%;
margin: 0 2px;
background-color: #bbbbbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.active, .dot:hover {
background-color: #717171;
}
/* Fading animation */
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}
#-webkit-keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
#keyframes fade {
from {opacity: .4}
to {opacity: 1}
}
/* On smaller screens, decrease text size */
#media only screen and (max-width : 720px ){
.prev, .next,.text {font-size: 11px}
}
.slideshow-fade a {
color: #FFFFFF
}
.slideshow-fade a:visited {
color: #5115D0
} /*End of style for index*/
footer { /*Footer*/
background: #000000;
width: 100%;
height: 5%;
position: relative;
bottom: 0;
left: 0;
padding-top: 2%;
overflow: hidden;
}
footer p {
font-family: arial, calibri, sans-serif;
color: #FFFFFF;
text-align: center;
padding-bottom: 2%;
} /*End of footer*/
Any help will be much appreciated. Thank you.
Here is the jsfiddle file to make it more convenient to see the problem. https://jsfiddle.net/8xutoea5/
Edit: Added more CSS codes.
Edit: I solved the problem. Thanks everyone for taking the time to solve this problem.
It appears to be a margin somewhere else in your CSS, not provided here, that is causing the issue. You could try setting margin-bottom:0; a few places to see if that solves it.
#nav nav ul li {
margin-bottom: 0;
padding-bottom: 0;
}
#nav nav ul li a {
margin-bottom: 0;
}
Or provide the rest of your style sheet.
It's most likely because you have your ul as inline-block, that will cause some space after elements. Also you have float on your li without a clearfix on nav.
You can solve this in various ways, here is one where you can use display: flex; and remove the float: left; on li. This is a pretty solid base you can build on with changing the justify-content property. You can find a awesome guide to flexbox over at css-tricks.com
UPDATE
I made some updates to the fiddle to solve the problem. Please note the code on top, also I made some other changes. Write if there is something unclear
* {
box-sizing: border-box;
}
jsfiddle
#nav ul {
list-style-type: none;
margin: 0;
background-color: #1C86EE;
padding: 0;
position: relative;
width: 100%;
bottom: 0;
display: flex;
justify-content: space-between;
}
#nav li {
width: 14%;
}
It's caused by the section "External Store", it's too long and it wraps. You can make it shorter or force a "no-wrap".
With the css property white-space with the value nowrap.
You have no classes on your internal tags so I would suggest add a class to the a tags and add the rule to it.
a.listLink{
white-space: nowrap;
}
Or you can just add a style attribute to that specific tag but I don't find that solution cool enough.

navbar hover effect above horizontal rule

I am designing a new website, and I always spend a lot of time on the navigation bars when I do so. The following code has this intended effect:
HTML:
<div class="navbar">
Home
About
</div>
<hr></hr>
CSS:
hr {
width: 80%;
border: 0;
height: 1px;
margin-top: 0px;
background-color: #000;
}
.navbar {
text-align: center;
}
.navbar a {
display: inline-block;
position: relative;
text-align: center;
color: #000;
text-decoration: none;
font-size: 20px;
overflow: hidden;
top: 5px;
padding-bottom: 10px;
padding-top: 10px;
padding-left: 30px;
padding-right: 30px;
}
.navbar a:after {
content: "";
position: absolute;
background-color: #c00;
height: 2px;
width: 0%;
transform: translateX(-50%);
left: 50%;
bottom: 0;
transition: .35s ease;
}
.navbar a:hover:after {
width: 100%;
}
This works in Chrome, Opera, and even some versions of Internet Explorer, but the other browsers can't agree on anything:
Firefox (and some IE versions):
Safari:
here is a code snippet:
hr {
width: 80%;
border: 0;
height: 1px;
margin-top: 0px;
background-color: #000;
}
.navbar {
text-align: center;
}
.navbar a {
display: inline-block;
position: relative;
text-align: center;
color: #000;
text-decoration: none;
font-size: 20px;
overflow: hidden;
top: 5px;
padding-bottom: 10px;
padding-top: 10px;
padding-left: 30px;
padding-right: 30px;
}
.navbar a:after {
content: "";
position: absolute;
background-color: #c00;
height: 2px;
width: 0%;
transform: translateX(-50%);
left: 50%;
bottom: 0;
transition: .35s ease;
}
.navbar a:hover:after {
width: 100%;
}
<div class="navbar">
Home
About
</div>
<hr>
Is there any way to achieve the intended effect without browser sniffing?
The problem can be solved by doing following steps:
Add reset CSS (could be normalize or Meyer reset CSS)
Set a specific height to navbar and the element as Safari doesn't do well without the height
Applying box-sizing: border-box; for easy
styling without much of calculation between padding, border, margin
within one element.
Beside, I usually use the border of navbar instead of another hr tag for the line under the menu

How do you make an IMAGE move independent of the elements around it using CSS3 Transition?

I'm trying to use a CSS3 transition to make the image inside this <div> move 10 pixels upward when the <div> is hovered over. It works great in Firefox, but when I view it in Chrome and Safari, the <h3> and <p> elements jitter up and down a bit.
This is my CSS:
.feature-table #box {
width: 325px;
height: 372px;
margin-right: 20px;
float: left;
}
.feature-table a {
display: block;
width: 325px;
height: 372px;
}
.feature-table a img {
display: block;
margin-left: auto;
margin-right: auto;
padding-top: 54px;
padding-bottom: 40px;
-moz-transition: all 0.3s linear;
-webkit-transition: all 0.3s linear;
transition: all 0.3s linear;
}
.feature-table a: hover img {
padding-top: 44px;
padding-bottom: 50px;
}
.feature-table a h3 {
font-family: 'GothamBold', sans-serif;
font-size: 30px;
color: #3d3d3d;
text-align: center;
text-decoration: none;
margin: 0;
padding: 0 25px;
}
.feature-table a: hover h3 {
color: #f6ce4f;
}
.feature-table a {
text-decoration: none;
}
.feature-table p {
font-family: 'GothamLight', sans-serif;
font-size: 14.5px;
color: #949494;
text-align: center;
padding: 10px 28px;
}
.feature-table .caret {
border-top: 5px solid #fff;
border-bottom: 5px solid #fff;
border-left: 5px solid #ffc235;
content: "";
display: inline-block;
height: 0;
width: 0;
margin-left: 10px;
}
This is part of my HTML:
<div id="box">
<a href="#">
<img src="images/payment_icon.png" width="114" height="115" border="0" />
<h3>Customizable Campaign Pages</h3>
<p>Tell your story with images, video, rich text and social updates<b class="caret"></b></p>
</a>
</div>
Any ideas?
It may be a performance issue because you're animating 2 different properties that affect the current layout.
The ideal solution would be to use a certain prop that doesn't affect the other elements. In your case, this can be done with the top property, after setting the image's position to relative :
a img{
position : relative;
top : 0;
}
a:hover img{
top : -4px;
}
Here's a working demo : http://jsfiddle.net/p7Lxz/