I'm reverse engineering the navigation in http://dreamelectronic.com/ (must use desktop for correct view) but in my own way.
I practically have it down, spot on, but i have one little issue i need to fix to get it just right. what i have is 2 div's that are on top of eachother and they both increase the width of the top border as see in the website. BUT one div starts at the center and stretches from center to the right and the other one stretches from the left to the center (if that makes sense). i need the second div (div2 if you go and read my code from CSSDeck) to start from the center and stretch to the left.
What i have tried is to use transform: rotateX(-180deg); as suggested from one of the answers from another question, i also tried to set the test-align: right; on the div2 also suggested. I tried animation-direction: alternate; too but no cake.
I have come across several similar situations on here but none have worked for me so far.
CSSDeck Project
Many thanks if i can get this last detail down!
You could set the below properties on your div2:
div2 {
float: right;
margin-right: 50px;
...
}
Snippet:
ul {
padding: 0;
margin: 20px;
}
li {
float: left;
list-style: none;
display: inline-block;
width: 100px;
}
div1 {
margin-left: 50px;
text-align: center;
line-height: 3;
display: block;
position: absolute;
width: 0px;
height: 50px;
border-top: 3px solid #D50;
transition: all .4s ease-in-out;
opacity: 0;
}
div2 {
float: right;
margin-right: 50px;
text-align: center;
line-height: 3;
display: block;
width: 0px;
height: 50px;
border-top: 3px solid #D50;
transition: all .4s ease-in-out;
opacity: 0;
}
men a {
text-align: center;
line-height: 3;
color: #444;
text-decoration: none;
display: block;
position: absolute;
width: 100px;
height: 50px;
z-index: 1;
transition: color .4s ease;
margin-top: 4px;
}
men a:hover {
color: #D50;
}
men a:hover~div1 {
width: 50px;
opacity: 1;
}
men a:hover~div2 {
width: 50px;
opacity: 1;
}
<ul>
<li>
<men>
HOME
<div1></div1>
<div2></div2>
</men>
</li>
<li>
<men>
ABOUT
<div1></div1>
<div2></div2>
</men>
</li>
<li>
<men>
PRODUCTS
<div1></div1>
<div2></div2>
</men>
</li>
<li>
<men>
CONTACT
<div1></div1>
<div2></div2>
</men>
</li>
</ul>
So your div1 is pushed using margin-left (which you already had) and your div2 is first forced to float from right and then pushed using margin-right.
Hope this helps.
P.S. Don't forget to close the div2.
You can use positioning for "right-to-left" div:
position: absolute;
right: 0;
http://jsfiddle.net/u5ofdp9m/1/
Related
I'm having an animated underline effect when user points the links on my website. The underline is a bit wider than the text itself, as there's a bit of horizontal padding.
Here's the effect I wanted to achieve and I did:
I was thinking if it was possible to simplify my code. After some trial and error, I used negative margin-left on the underline element and calc() to calculate its width as 100% + 2 * padding. It looks to me like an overcomplicated solution. Can the same effect be achieved without calc() and, perhaps, without negative margin?
Of note, adding a wrapper element is not an option. It needs to be a plain <a> element.
:root {
--link-color: #f80;
--link-underline-padding: .5em;
}
a {
color: var(--link-color);
display: inline-block;
padding: 0 var(--link-underline-padding);
text-decoration: none;
}
a:after {
background-color: var(--link-color);
content: '';
display: block;
height: .1em;
margin-left: calc(var(--link-underline-padding) * -1);
margin-top: .2em;
transition: width .5s;
width: 0;
}
a:hover:after {
width: calc(100% + var(--link-underline-padding) * 2);
}
I find dogs pretty cool.
A simple background animation can do this:
a {
background: linear-gradient(currentColor 0 0)
bottom left/
var(--underline-width, 0%) 0.1em
no-repeat;
color: #f80;
display: inline-block;
padding: 0 .5em 0.2em;
text-decoration: none;
transition: background-size 0.5s;
}
a:hover {
--underline-width: 100%;
}
I find dogs pretty cool.
Related:
How to animate underline from left to right?
How to hover underline start from center instead of left?
If you set a to position: relative; you can then use position: absolute; and left: 0px; to push it past the padding and then just use width: 100% to have it extend the entire length.
:root {
--link-color: #f80;
--link-underline-padding: .5em;
}
a {
position: relative;
color: var(--link-color);
display: inline-block;
padding: 0px var(--link-underline-padding);
text-decoration: none;
}
a:after {
position: absolute;
left: 0px;
background-color: var(--link-color);
content: '';
display: block;
height: .1em;
margin-top: .2em;
transition: width .5s;
width: 0;
}
a:hover:after {
width: 100%;
}
I find dogs pretty cool.
I'm building a "staff" page with a liquid, four-column layout. I've placed a div element, absolutely positioned on top of the photo of each staff member to act as a button/link. My problem is that when I align this overlay div to bottom:0 and right:0 I will get the occasional 1 pixel gap between the image and the overlay as I resize the window. It seems this is a function of some sort of round-off error.
I've searched this site and others for help on this, but I haven't found this issue explicitly discussed anywhere. Any insights are greatly appreciated.
The page in question can be seen here:
communicationdesign.com/cwt-beta/about.html
Resize the window to see the occasional error/gap...
Here is the relevant markup:
<div class="staff-block">
<div class="staff-photo">
<img src="img/gruber.jpg" class="portrait" />
<a href="gruber.html">
<div class="plus-link">
<div class="plus-sign">+</div>
</div>
</a>
</div>
<div class="caption">
Drew Gruber<br /><span class="job-title">Executive Director</span>
</div>
</div>
And here is the CSS:
.staff-block {
position: relative;
width: 22.3%;
float: left;
background-color: #ffc;
margin-right: 3.5%;
}
.staff-photo{
position: relative;
}
.staff-photo img, .board-photo img, .bio-photo img {
width: 100%;
}
.portrait {
opacity: 1;
display: block;
width: 100%;
height: auto;
transition: .5s ease;
backface-visibility: hidden;
}
.plus-link {
transition: .5s ease;
opacity: 1;
position: absolute;
bottom: 0;
right: 0;
}
.plus-sign {
background-color: rgba(255,204,78,0.8);
color: white;
font-size: 40px;
line-height: 30px;
padding: 4px 8px 6px;
}
This is an occupational hazard when using percentages. You could use a hack like this:
.staff-photo{
overflow: hidden;
}
.plus-link {
background-color: rgba(255,204,78,0.8); // color on the plus sign parent
position: absolute;
bottom: -5px; // position it over the edge
right: -5px;
padding: 0 5px 5px 0; // and correct the extra space
}
.plus-sign {
background-color: transparent; // or remove bg color
}
I am trying to implement some CSS on my website that I am having a little bit of difficulty with. I currently have five 'balls' (which are just circular divs) that have staggered heights. I have been experimenting with having the balls move around when you hover on them, which is great, but currently they only continue to move as long as you keep your pointer trained on it as it moves.
Ideally, I would like to have all five move independently when you hover in the general area. I have enclosed them in a wrapper div, but I am unsure of the code to affect the child divs when you hover on the parent. I am also not sure if I'm using the terms parent and child correctly, as I've only come across this concept in the last 20 minutes!
Here is the HTML:
<div id='demoStrip'><div id='ballWrapper'>
<div id='bounce'>
<div class='ball' id='ball1'><p>Professional</p></div>
<div class='ball' id='ball2'><p>Copy</p></div>
<div class='ball' id='ball3'><p>Just</p></div>
<div class='ball' id='ball4'><p>For</p></div>
<div class='ball' id='ball5'><p>You</p></div>
</div>
</div></div> <!-- End of demoStrip div -->
Here is the CSS as it currently stands:
#demoStrip {
width: 960px;
height: 410px;
margin: 20px auto 0 auto;
/*background: #00cccc;*/
border-radius: 20px;
}
#ballWrapper {
width: 900px;
height: 410px;
margin: 0 auto 0 auto;
}
.ball {
margin: 0 20px 0 20px;
/*width: 150px;
height: 150px;*/
border-radius: 200px;
background-image: radial-gradient(circle closest-corner at center, #FFFF99 0%, #FFFF00 100%);
float: left;
box-shadow: 5px 5px 5px #333333;
}
.ball p {
text-align: center;
text-transform: uppercase;
font-family: sans-serif;
margin: 0;
}
#ball1 {
width: 150px;
height: 150px;
margin-top: 245px;
}
#ball2 {
width: 140px;
height: 140px;
margin-top: 185px;
}
#ball3 {
width: 130px;
height: 130px;
margin-top: 125px;
}
#ball4 {
width: 120px;
height: 120px;
margin-top: 65px;
}
#ball5 {
width: 110px;
height: 110px;
margin-top: 5px;
}
#ball1:hover {
margin-top: 5px;
transition: margin-top 3s;
}
#bounce:hover ~ #ball2:hover {
margin-top: 65px;
transition: margin-top 3s;
}
The very last bit of code is my attempts to make ball2 'bounce' when hovering on the 'bounce' div. At the moment it doesn't work, but I'm sure syntactically it is all wrong. Any advice would be much appreciated!
Write your CSS so it affects the balls inside a hovered div:
#bounce:hover .ball {
...
}
Or, if you need different CSS for each ball:
#bounce:hover #ball1 {
...
}
#bounce:hover #ball2 {
...
}
...
Give the hover a 100% width/ height
#ball1:hover {
width:100%;
height:100%
margin-top: 5px;
transition: margin-top 3s;
}
#bounce:hover ~ #ball2:hover {
margin-top: 65px;
transition: margin-top 3s;
width:100%;
height:100%
}
Ideally, I would like to have all five move independently when you
hover in the general area...
So do something like this:
#demoStrip:hover #bounce .ball:nth-child(1) {
//animation here
}
This should fix your second issue of...
currently they only continue to move as long as you keep your pointer
trained on it as it moves
If you still run into that issue then set them both to position: relative and set each element's z-index, but be sure to set the .ball to a higher z-index. See Submenu does not stay open for more on why.
Your last attempt wasn't too far off, but instead of
#bounce:hover ~ #ball2:hover {...}
use
#bounce:hover #ball2 {...}
this will
make ball2 'bounce' when hovering on the 'bounce' div
You do not need the second :hover on #ball2, nor do you need the tilde (~).
In CSS the tilde (~) symbol is the 'general sibling' combinator. See this article for a great intro to CSS selectors/combinators http://code.tutsplus.com/tutorials/the-30-css-selectors-you-must-memorize--net-16048
You could use the tilde to hover #ball1 and animate #ball2 (providing #ball2 is after #ball1 in the DOM) like so:
#ball1:hover ~ #ball2 {
margin-top: 65px;
transition: margin-top 3s;
}
At the moment i am working on a header with a slider animation (css3 only):
http://jimmytenbrink.nl/slider/
Everything is working fine except sometimes the slider is bugging if you go from the center to the right. It seems that i need to stop the animation for a few miliseconds to complete. However i searched everywhere on the internet but i cant seem to get it to work.
Anyone here has experience with it who can help me out?
HTML
<header>
<div><span>slide 1</span></div>
<div><span>slide 2</span></div>
<div><span>slide 3</span></div>
<div><span>slide 4</span></div>
<div><span>slide 5</span></div>
<div><span>slide 6</span></div>
<div><span>slide 7</span></div>
<div><span>slide 8</span></div>
</header>
CSS
header {
margin-top: 10px;
width: 800px;
overflow: hidden;
height: 500px;
}
header div {
background-color: #000;
width: 43.8px;
height: 200px;
position: relative;
float: left;
-webkit-transition: width .3s;
transition: width .3s;
overflow: hidden;
-webkit-animation-timing-function: linear;
-webkit-animation-iteration-count: 1;
-webkit-animation-fill-mode: forwards;
margin-right: 2px;
}
header div:first-child {
margin-left: 0px;
}
header div:last-child {
margin-right: 0px;
}
header div:hover span {
left: 50px;
opacity: 1;
}
header div img {
position: relative;
left: -240px;
-webkit-transition: all .3s;
transition: all .3s;
-webkit-filter: grayscale(1);
overflow:hidden;
}
header div span {
-webkit-transition: left .3s;
transition: left .3s;
position: absolute;
bottom: 30px;
color: white;
left: -350px;
opacity: 0;
width: 450px;
font-family:'Fugaz One', cursive;
text-transform: uppercase;
font-size: 24px;
color: #fff;
text-shadow: 0px 0px 10px #f1f1f1;
filter: dropshadow(color=#f1f1f1, offx=0, offy=0);
}
header:hover > div {
width: 43.8px;
}
header:hover > div:hover {
width: 150px;
}
Here is a JSFiddle
So the question is, how can i set a stop on the animation for a few miliseconds so the animation can finish before it gets triggered again?
Hope my question is clear!
(thanks for the edit)
One might call my answer a workaround. Maybe it is but according to my comment on ExtPro's answer - it is still completely pure CSS.
I decided to use display: table-cell since the table cell's width is distributed equally.
So, the CSS might look like this:
HINT: This is only a bunch of necessary CSS. All the code is in the jsFiddle
header {
width: 368px;
display: table;
overflow: hidden;
}
header > div {
width: 44px;
height: 200px;
position: relative;
-webkit-transition: width .3s;
transition: width .3s;
display: table-cell;
overflow: hidden;
}
header > div:hover {
width: 151px;
}
Fiddle
As you can see, we don't have to determine the width of all not-hovered divs. Actually, the problem came from that very CSS rule:
/* DON'T USE THIS RULE - IT'S THE RULE WHICH WAS BAD */
header:hover > div {
width: 43.8px;
}
You were changing the width of the divs on header:hover, so when the transition didn't manage to do its job in time, you came out with mouse pointing to the header but to non of the divs.
If I understand what you mean by 'bugging', what is happening is if you move the mouse quickly to the right, it traverses the currently open div and is left in an area which when that div collapses, does not contain (e.g. the mouse is not hovered over) the next one in order to expand it- namely the hover event of the following div(s) is/are not firing thus they do not expand. There wont be a CSS fix for this Im afraid as its browser related, you may want to replace with jQuery/JS.
I'm working on a site with a knotted rope-style bar that expands to show more information on hover, and I'm having issues getting the animation to look right. (Here's a staging link: http://couchcreative.co/tcc/).
Currently, the bar for the first step will move down to the bottom of the box before it animates upwards to its new position, while I want it to just move up to its new position on hover without starting at the bottom of the hover box. Can anyone help explain why this is happening? The relevant CSS starts with the ".look" class.
Apologies if I'm not explaining this right, but hopefully when you visit the site you'll see what I mean about the animation looking a bit… off. Thanks for the help!
I would rework your HTML structure to make it more semantic and less repetitious.
Demo: http://jsfiddle.net/krmn4/5/
HTML:
<a href="/testicularcancer/" class="look">
<figure><img src="http://couchcreative.co/tcc/img/look.png" /></figure>
<div class="bar"></div>
<div class="off">
<h4>Look</h4>
</div>
<div class="on">
<h4>Relax your scrotum.</h4>
<p>Check your testicles just after you’ve had a bath or shower, when the muscles in the scrotum are relaxed, making it easier for you to feel any lumps, growths or tenderness. Stand in front of the mirror. Look for any swelling on the skin of your scrotum.</p>
<span>Learn More</span>
</div>
</a>
CSS:
.look {
position: absolute;
bottom: 0;
left: 0;
width: 235px;
overflow: hidden;
/* optional styling */
color: #000;
text-align: center;
text-decoration: none;
}
.look h4 {
/* optional styling */
line-height: 48px;
font-size: 20px;
font-weight: bold;
}
.look .bar {
height: 48px;
background: url(http://couchcreative.co/tcc/img/step_1.png) 0 0 repeat-x;
margin: -24px 0 0; /* half of height */
/* necessary so figure img doesn't overlap */
position: relative;
z-index: 1;
}
.look figure,
.look .off,
.look .on {
-webkit-transition: all 300ms linear;
-moz-transition: all 300ms linear;
transition: all 300ms linear;
height: 0;
opacity: 0;
overflow: hidden;
}
.look figure {
/* optional styling */
background-color: #b2d5e6;
padding: 12px;
margin: 0;
}
.look .off {
height: 48px;
opacity: 1;
}
/* hover state */
.look:hover .off {
height: 0;
opacity: 0;
}
.look:hover figure {
height: 120px; /* or however tall it needs to be */
opacity: 1;
}
.look:hover .on {
height: 220px; /* or however tall it needs to be */
opacity: 1;
}