I'm trying to vertically align some text in a div whilst the text is under an image.
I'm not very good at explaining things but this is the code I have so far: https://jsfiddle.net/c1249bd8/
HTML:
<div class="childContainer">
<a href="#" class="childLink">
<img src="http://placekitten.com/g/500/500" alt="Test" class="childImg"/>
<h1 class="childName">Testing</h1>
</a>
</div>
CSS:
.childContainer {
/* Height and width */
height: 10rem;
width: 10rem;
/* Hide overflow */
overflow: hidden;
/* Allows z-index */
position: relative;
/* Circle */
border-radius: 50%;
}
.childLink {
/* No default link styling */
color: #000;
text-decoration: none;
/* All Bubble is link */
height: 100%;
width: 100%;
/* Circle */
border-radius: 50%;
}
.childImg {
/* Full Bubble */
height: 100%;
width: 100%;
/* On top of text */
z-index: 1;
position: absolute;
/* Fade in/out stuff */
opacity: 1;
transition: opacity .30s ease-in-out;
-moz-transition: opacity .30s ease-in-out;
-webkit-transition: opacity .30s ease-in-out;
}
.childNameWrapper {
vertical-align: middle;
display: table-cell;
}
#import url('http://fonts.googleapis.com/css?family=Roboto:400,300|Luckiest+Guy');
.childName {
/* Behind Image */
position: absolute;
z-index: 0;
/* In Center */
text-align: center;
/* Nice handwriting font */
font-family: 'Luckiest Guy', cursive;
}
.childImg:hover {
/* Fade on hover */
opacity: 0;
transition: opacity .30s ease-in-out;
-moz-transition: opacity .30s ease-in-out;
-webkit-transition: opacity .30s ease-in-out;
}
Thanks,
Oscar.
Use display flex. It is quite easy and simple to use.
Check the FIDDLE.
.childLink {
display:flex;
align-items : center;
/* No default link styling */
color: #000;
position:relative;
text-decoration: none;
/* All Bubble is link */
height: 100%;
width: 100%;
/* Circle */
border-radius: 50%;
// vertical-align:middle;
}
change your 'childname' class to this:
.childName {
/* Behind Image */
position: relative;
z-index: 0;
line-height: 90px;
/* In Center */
text-align: center;
/* Nice handwriting font */
font-family: 'Luckiest Guy', cursive;
The trick here is the lineheight :)
Related
How can I make such animation ?
(https://i.stack.imgur.com/NTWjH.png)
please check link below
https://preview.themeforest.net/item/shopify-outstock-clean-minimal-drag-drop/full_screen_preview/21041667?_ga=2.52492833.847676305.1666954417-2031082058.1666954417
.wrap-img {
transition: all 200ms ease 0s;
-webkit-transition: all 200ms ease 0s;
-moz-transition: all 200ms ease 0s;
overflow: hidden;
margin: 0px auto;
position: relative;
background: #fff;
padding: 15px;
}
One option would be this:
.box {
/* Required for the position: absolute property of the overlay. */
position: relative;
}
/* Scroll up and down effect */
.scrolling {
background-size: cover !important;
width: 285px;
min-height: 500px;
border: 15px solid #fff; /* Border is white */
cursor: pointer;
transition: background-position 1.5s ease-out 0.5s
}
.scroll {
background: url("https://velatheme.com/demo/outstock/images/cosmetic2.jpg");
background-position: top center;
}
.scroll_top:hover {
background-position: bottom center !important;
transition: background-position 2s linear 0s;
}
/* Background separating the image and the button */
.overlay {
position: absolute;
display: flex;
justify-content: center;
align-items:center;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: rgba(0,0,0,0.4);
}
.box:hover .overlay {
opacity: 1;
}
/* Button */
button {
display: none;
}
.box:hover button {
display: inline-block;
height: 48px;
width: 158px;
border: 4px solid #fff;
text-align: center;
line-height: 30px;
font-size: 14px;
font-weight: 600;
text-transform: uppercase;
color: #333;
}
.box button:hover {
display: inline-block;
color: #fff;
background: #333;
cursor: pointer
}
<div class="box scrolling scroll scroll_top">
<div class="overlay">
<button>VIEW DEMO</button>
</div>
</div>
To do the opposite effect, you would first have to change the classes to scroll_bottom and it would just change:
In .scroll :
background-position: bottom center;
And in .scroll_top:hover (In this case it would be .scroll_bottom:hover):
background-position: top center !important;
On hover, I am trying to swap a background image using a CSS transition. However, in Safari, the image shrinks during the animation and I'm not sure why.
.icon {
background-color: white;
width: 100px;
height: 100px;
background-image: url(data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA4MS44OSA4MS44OSI+PGRlZnM+PHN0eWxlPi5jbHMtMXtmaWxsOm5vbmU7c3Ryb2tlOiM4YjkyYTE7c3Ryb2tlLW1pdGVybGltaXQ6MTA7c3Ryb2tlLXdpZHRoOjZweDt9PC9zdHlsZT48L2RlZnM+PHRpdGxlPmljb24tc2VhcmNoPC90aXRsZT48Y2lyY2xlIGNsYXNzPSJjbHMtMSIgY3g9IjM1LjU5IiBjeT0iMzUuNTkiIHI9IjMyLjU5Ii8+PGxpbmUgY2xhc3M9ImNscy0xIiB4MT0iNTguNjMiIHkxPSI1OC42MyIgeDI9Ijc5Ljc3IiB5Mj0iNzkuNzciLz48L3N2Zz4=);
background-size: 14px 14px;
background-repeat: no-repeat;
transition: all 1s;
}
.icon:hover {
background-image: url(data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA4MS44OSA4MS44OSI+PGRlZnM+PHN0eWxlPi5jbHMtMXtmaWxsOm5vbmU7c3Ryb2tlOiM1YTJhODI7c3Ryb2tlLW1pdGVybGltaXQ6MTA7c3Ryb2tlLXdpZHRoOjZweDt9PC9zdHlsZT48L2RlZnM+PHRpdGxlPmljb24tc2VhcmNoLXB1cnBsZTwvdGl0bGU+PGNpcmNsZSBjbGFzcz0iY2xzLTEiIGN4PSIzNS41OSIgY3k9IjM1LjU5IiByPSIzMi41OSIvPjxsaW5lIGNsYXNzPSJjbHMtMSIgeDE9IjU4LjYzIiB5MT0iNTguNjMiIHgyPSI3OS43NyIgeTI9Ijc5Ljc3Ii8+PC9zdmc+);
}
https://jsfiddle.net/Lfqucz82/
Although I don't know why Safari behaves like this, if you're trying to crossfade icons on hover, work on :after and :before pseudo-selectors opacity. Try as in this fiddle: https://jsfiddle.net/ifthenelse/6s9g4kdn/
Your CSS would look like this:
/* Icon container */
.icon {
position: relative;
background-color: white;
width: 100px;
height: 100px;
}
/* Images containers */
.icon:before, .icon:after {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
content: "";
display: block;
background-size: 14px 14px;
background-repeat: no-repeat;
transition: opacity 1s;
}
/* Attach backgrounds */
.icon:before {
background-image: url(data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA4MS44OSA4MS44OSI+PGRlZnM+PHN0eWxlPi5jbHMtMXtmaWxsOm5vbmU7c3Ryb2tlOiM4YjkyYTE7c3Ryb2tlLW1pdGVybGltaXQ6MTA7c3Ryb2tlLXdpZHRoOjZweDt9PC9zdHlsZT48L2RlZnM+PHRpdGxlPmljb24tc2VhcmNoPC90aXRsZT48Y2lyY2xlIGNsYXNzPSJjbHMtMSIgY3g9IjM1LjU5IiBjeT0iMzUuNTkiIHI9IjMyLjU5Ii8+PGxpbmUgY2xhc3M9ImNscy0xIiB4MT0iNTguNjMiIHkxPSI1OC42MyIgeDI9Ijc5Ljc3IiB5Mj0iNzkuNzciLz48L3N2Zz4=);
opacity: 1;
}
.icon:after {
background-image: url(data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA4MS44OSA4MS44OSI+PGRlZnM+PHN0eWxlPi5jbHMtMXtmaWxsOm5vbmU7c3Ryb2tlOiM1YTJhODI7c3Ryb2tlLW1pdGVybGltaXQ6MTA7c3Ryb2tlLXdpZHRoOjZweDt9PC9zdHlsZT48L2RlZnM+PHRpdGxlPmljb24tc2VhcmNoLXB1cnBsZTwvdGl0bGU+PGNpcmNsZSBjbGFzcz0iY2xzLTEiIGN4PSIzNS41OSIgY3k9IjM1LjU5IiByPSIzMi41OSIvPjxsaW5lIGNsYXNzPSJjbHMtMSIgeDE9IjU4LjYzIiB5MT0iNTguNjMiIHgyPSI3OS43NyIgeTI9Ijc5Ljc3Ii8+PC9zdmc+);
opacity: 0;
}
/* Transition on hover */
.icon:hover:before {
opacity: 0;
}
.icon:hover:after {
opacity: 1;
}
If the images appearing (before and during hovering) are not of the same sizes, one image (in your case, the first image) will appear perfectly sized since you have set the background-size: 14px 14px; and the other image might look resized (expanded or shrinked).
So
1. Check the sizes of the images. (if they are not the same, then define the perfect css background-size property you need
2. For the transition to be perfect (in all browsers & browser version), do
.icon{
//other css codes;
transition: 1s;
-o-transition: 1s;
-ms-transition: 1s;
-moz-transition: 1s;
-webkit-transition: 1s;
}
I am trying to get an effect using css which I keep getting 90% right but each time I try something different, it results in another problem elsewhere.
What I am trying to do:
Have the image zoom on mouseover
Have the text remain in place and not zoom
Problem:
The hover works fine EXCEPT when the mouse goes over the text-overlay (because the effect is on img:hover. I effectively want the text-overlay to be visible to the eyes BUT transparent to the mouse-over
Here is my fiddle: https://jsfiddle.net/knrrrfxo/
I have tried making the image a background image but that creates a whole other list of issues with responsive sizing which also wont work.
Code:
<style>
.tile-wrapper {
margin:0;
padding:0;
overflow: hidden;
position: relative;
}
.new-arrivals-link {
line-height: 0;
}
.new-arrivals-link img {
-webkit-transition: all 1s ease; /* Safari and Chrome */
-moz-transition: all 1s ease; /* Firefox */
-ms-transition: all 1s ease; /* IE 9 */
-o-transition: all 1s ease; /* Opera */
transition: all 1s ease;
}
.new-arrivals-link img:hover {
-webkit-transform:scale(1.25); /* Safari and Chrome */
-moz-transform:scale(1.25); /* Firefox */
-ms-transform:scale(1.25); /* IE 9 */
-o-transform:scale(1.25); /* Opera */
transform:scale(1.25);
}
.new-arrivals-link img:hover {
opacity: 0.8;
}
.tile-wrapper .text-overlay {
position: absolute;
width: 50%;
height: 50%;
overflow: auto;
margin: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;
text-align: center;
}
.tile-wrapper .text-overlay h2 {
color: white;
font-size: 60px;
line-height: 74px;
margin: 0 0 10px;
}
.tile-wrapper .text-overlay p {
color: white;
font-size: 28px;
}
</style>
<div class="tile-wrapper">
<a href="#" itemprop="url" class="new-arrivals-link">
<img src="https://cdn.shopify.com/s/files/1/1307/5753/files/new-arrivals-tab.jpg?6713767595666642894" width="100%" alt="New Arrivals">
<div class="text-overlay">
<h2>NEW<br>ARRIVALS</h2>
<p>Shop Now</p>
</div>
</a>
</div>
You can set pointer-events: none; on the .text-overlay div.
All you need is change a single selector to apply to hover of the parent instead of the image element, like so (the changed line is indicated by a comment):
.tile-wrapper {
margin:0;
padding:0;
overflow: hidden;
position: relative;
}
.new-arrivals-link {
line-height: 0;
}
.new-arrivals-link img {
-webkit-transition: all 1s ease; /* Safari and Chrome */
-moz-transition: all 1s ease; /* Firefox */
-ms-transition: all 1s ease; /* IE 9 */
-o-transition: all 1s ease; /* Opera */
transition: all 1s ease;
}
.new-arrivals-link:hover img { /* this line has been changed */
-webkit-transform:scale(1.25); /* Safari and Chrome */
-moz-transform:scale(1.25); /* Firefox */
-ms-transform:scale(1.25); /* IE 9 */
-o-transform:scale(1.25); /* Opera */
transform:scale(1.25);
}
.new-arrivals-link img:hover {
opacity: 0.8;
}
.tile-wrapper .text-overlay {
position: absolute;
width: 50%;
height: 50%;
overflow: auto;
margin: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;
text-align: center;
}
.tile-wrapper .text-overlay h2 {
color: white;
font-size: 60px;
line-height: 74px;
margin: 0 0 10px;
}
.tile-wrapper .text-overlay p {
color: white;
font-size: 28px;
}
<div class="tile-wrapper">
<a href="#" itemprop="url" class="new-arrivals-link">
<img src="https://cdn.shopify.com/s/files/1/1307/5753/files/new-arrivals-tab.jpg?6713767595666642894" width="100%" alt="New Arrivals">
<div class="text-overlay">
<h2>NEW<br>ARRIVALS</h2>
<p>Shop Now</p>
</div>
</a>
</div>
This works because it applies when the parent element of both the image and the text box is hovered over, which is also true if you hover over any of it's child elements.
I'm trying to implement a menu nav bar that on hover highlights the menu item with an underline animation from LEFT to RIGHT.
Currently I have the underline animating from the center of the menu item to the outside.
I have tried searchng for a solution to this but can't figure out what I'm doing wrong.
Here is a link to the project on codepen http://codepen.io/anon/pen/JowgqP
HTML
<menu>
<p><strong>Home</strong>
<strong>About</strong>
<strong>Portfolio</strong>
<strong>Contact</strong> <strong>
<p class="note">This is a recreation of the link hover effect from factmag.com</small>
</menu>
CSS (SCSS)
#import url(http://fonts.googleapis.com/css?family=Noto+Serif:400,700,400italic);
$link-color: #E71818;
$text-color: black;
$article-font: Noto serif, serif;
menu {
color: $text-color;
font-family: $article-font;
max-width: 30em;
}
p {
font-size: 18px;
line-height: 1.5;
}
menu a {
#extend %fancy-link;
}
.note {
display: inline-block;
border-top: 1px solid $link-color;
color: #777;
font-size: .8em;
font-style: italic;
margin-top: 2em;
padding-top: 1em;
}
%fancy-link {
color: $link-color;
position: relative;
text-decoration: none;
transition: all 0.15s ease-out;
&:before {
content: "";
position: absolute;
width: 100%;
height: 1px;
bottom: 0px;
left: 0;
background: #f00;
visibility: hidden;
transform: scaleX(0);
transition: all 0.3s ease-in-out 0s;
}
&:hover {
transition: all 0.15s ease-out;
&:before {
visibility: visible;
transform: scaleX(1);
}
}
}
The default transformation point is center center...or rather 50% 50% for ease of reference. (For 2 dimensions...we'll leave out z offsets for now.)
You would have to amend this so that the origin is now center left
&:before {
content: "";
position: absolute;
width: 100%;
height: 1px;
bottom: 0px;
left: 0;
background: #f00;
visibility: hidden;
transform: scaleX(0);
transform-origin: center left; /* here */
transition: all 0.3s ease-in-out 0s;
}
Codepen Demo
Transform-Origin # MDN
Here is the page in questions: http://www.jacobsievers.com/sample.html
In Firefox and IE, My navigation bar displays correctly, but if you look at it with Chrome there is a line break after 'Gallery'. I'm wondering if someone can help me figure out what I need to do or change in my code. Something with the nav ul or nav li in my css?
(source: jacobsievers.com)
(source: jacobsievers.com)
I don't know how to make those scroll box things that other people put code in so here are some jpgs sorry! Thanks for the help.
nav ul {
text-align: center;
width: 700px;
margin: auto;
word-spacing: 50px;
padding: 0;
font-size: 20px;
}
Should fix it :)
EDIT:
/************************ =Nav ************************/
nav ul {
text-align: center;
width: 700px;
margin: auto;
padding: 0;
font-size: 20px;
}
nav li {
display: inline;
margin: auto;
position: relative;
top:30px;
margin-left: 100px;
}
nav li:first-child { margin-left: 0px; }
nav a {
text-decoration: none;
color: rgb(50, 140, 204);
transition: background-color 2s;
-moz-transition: background-color 2s;
/* Firefox 4 */
-webkit-transition: background-color 2s;
/* Safari and Chrome */
-o-transition: background-color 2s;
/* Opera */
transition: color 2s;
-moz-transition: color 2s;
/* Firefox 4 */
-webkit-transition: color 2s;
/* Safari and Chrome */
-o-transition: color 2s;
/* Opera */
}
nav a:hover {
background-color: #E0EEEE;
color: black;
}
jsFiddle - http://jsfiddle.net/andyjh07/cqZTV/