When I hover over the red box, the reddit logo stretches with it, any way to fix this? I hope the snippet will help you understand my problem. Seems like it's a problem with "translate: scaleY();", but I can't use transitions or animations because I'm making like a card and elements push each other.
* {
margin: 0;
}
li {
list-style: none;
}
#card {
width: 460px;
height: 350px;
left: 50%;
transform: translate(-50%);
position: absolute;
}
#socialLinks {
display: inline-flex;
padding: 0;
}
#socialLinks li:hover {
transform-origin: bottom;
transform: scaleY(1.1);
}
#socialLinks li {
width: 152px;
height: 100px;
border-style: solid;
border-color: rgb(43, 43, 43);
border-width: 1px;
transition-timing-function: ease-in-out;
transition-duration: 0.3s;
transform: scaleY(1);
}
#socialLink1 {
background: tomato;
}
.logoReddit {
width: 85px;
height: 75px;
}
<div id="card">
<ul id="socialLinks">
<li id="socialLink1">
<a href="#">
<img
class="logoReddit" src="https://i.ibb.co/1QWXV8g/reddit-logo.png" alt="reddit-logo">
</a>
</li>
</ul>
</div>
Try these CSS rules:
#socialLinks li .logoReddit {
transition: .3s ease-in-out;
}
#socialLinks li:hover .logoReddit {
transform: scaleY(0.9);
}
Related
Here's my code:
HTML
<div id="featuredWrapper">
<div id="featuredContentWrapper">
<div class="ContentThumbnail">
<a>
<div class="ContentThumbnailCaption">
<h3>Lorem</h3>
<p>Ipsum</p>
</div>
<img src="https://i.picsum.photos/id/1/200/300.jpg" class="ContentThumbnailImage" />
</a>
</div>
</div>
</div>
CSS
#featuredWrapper
{
/*SETUP*/
display:inline-block;
margin-left:13.85%;
margin-right:13.85%;
width:72.3%;
/*BORDER*/
border-bottom: solid 1px gray;
/*ANIMATION*/
transition: 0.3s;
}
#featuredContentWrapper
{
/*SETUP*/
text-align:center;
}
.ContentThumbnail
{
/*SETUP*/
display:inline-block;
height: 30%;
width: 22.5%;
margin: 2% 4% 2% 4%;
/*VISUAL*/
background-color:aqua;
/*ANIMATION*/
transition: 0.3s;
}
.ContentThumbnail:hover .ContentThumbnailCaption
{
/*VISUAL*/
filter:opacity(100%);
}
.ContentThumbnail:hover .ContentThumbnailImage
{
/*VISUAL*/
filter:brightness(50%);
}
.ContentThumbnail a
{
/*SETUP*/
display:inline-block;
position:relative;
}
.ContentThumbnailImage
{
/*SETUP*/
display:inline-block;
height: 100%;
width: 100%;
}
.ContentThumbnailCaption
{
/*SETUP*/
position:absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
/*VISUAL*/
color:white;
filter:opacity(0);
/*ANIMATION*/
transition:0.3s;
}
I would like for the brightness and opacity changes to occur concurrently, so that the text would display over the darkened image.
As it stands now, I think either the brightness filter is somehow hiding the text or the effects are occurring one after another because when you stop hovering, the text will appear and play the fading out animation.
I have tried changing the mechanisms used to do both effects, like using visibility CSS instead of filters. I haven't tried JavaScript yet, but I would like to keep this effect within CSS.
Changed for below mentioned css
.ContentThumbnail:hover .ContentThumbnailCaption
{
/*VISUAL*/
filter:opacity(100%);z-index:1;
}
#featuredWrapper {
/*SETUP*/
display: inline-block;
margin-left: 13.85%;
margin-right: 13.85%;
width: 72.3%;
/*BORDER*/
border-bottom: solid 1px gray;
/*ANIMATION*/
transition: 0.3s;
}
#featuredContentWrapper {
/*SETUP*/
text-align: center;
}
.ContentThumbnail {
/*SETUP*/
display: inline-block;
height: 30%;
width: 22.5%;
margin: 2% 4% 2% 4%;
/*VISUAL*/
background-color: aqua;
/*ANIMATION*/
transition: 0.3s;
}
.ContentThumbnail:hover .ContentThumbnailCaption {
/*VISUAL*/
filter: opacity(100%);
z-index: 1;
}
.ContentThumbnail:hover .ContentThumbnailImage {
/*VISUAL*/
filter: brightness(50%);
}
.ContentThumbnail a {
/*SETUP*/
display: inline-block;
position: relative;
}
.ContentThumbnailImage {
/*SETUP*/
display: inline-block;
height: 100%;
width: 100%;
}
.ContentThumbnailCaption {
/*SETUP*/
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
/*VISUAL*/
color: white;
filter: opacity(0);
/*ANIMATION*/
transition: 0.3s;
}
<div id="featuredWrapper">
<div id="featuredContentWrapper">
<div class="ContentThumbnail">
<a>
<div class="ContentThumbnailCaption">
<h3>Lorem</h3>
<p>Ipsum</p>
</div>
<img src="https://i.picsum.photos/id/1/200/300.jpg" class="ContentThumbnailImage" />
</a>
</div>
</div>
</div>
I need the title link to direct to a separate page.
Here is a snippet of my code.
<div class="img-container design" data-category="design">
<h3 class="pro2">Angular JS Sales List <a class="pro1" href="https://github.com/Daniel1836/Angular-JS-Project">Git Hub</a> </h3>
<img src="img/angular.png">
<a class="img-overlay" href="/portfolio/index2.html"></a>
<div class="img-overlay-text">
I've tried many combinations of ordering the code, but the link on the bottom is the one that both links redirect to, as if it is spanning the entire image length.
Thanks
Edit
Here is the relevant CSS. The code is not my own.
.img-container {
position: relative;
width: 30%;
margin: 10px;
height: auto; }
.img-container img {
border-radius: 10px; }
#media screen and (max-width: 760px) {
.img-container {
width: 100%; } }
.img-overlay {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: rgba(229, 46, 45, 0.3);
border-radius: 10px;
outline: 1px solid #fff;
outline-offset: -15px;
cursor: pointer;
-webkit-transition: all .3s ease-out;
-o-transition: all .3s ease-out;
transition: all .3s ease-out;
opacity: 0; }
.img-overlay:hover {
opacity: 1; }
.img-overlay-text {
position: inherit;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
color: #fff;
text-align: center; }
.img-overlay-text h3 {
margin: 0; }
.img-overlay-text p {
color: #fff; }
The second link should be like this:
<a class="img-overlay" href="/portfolio/index2.html">
<img src="img/angular.png" />
</a>
I have a small issue, I need to rotate 2 spans and create a perfect 'X'.
I've created a JSfiddle for this. Can you guys help me?
I can't seem to get my head around how much should i transform origin...
HTML
<div class="toggle-btn">
<span></span>
<span></span>
</div>
SASS
.toggle-btn {
width: 38px;
height: 19px;
cursor: pointer;
position: relative;
margin-top: 18px;
text-align: center;
&:after {
content: '';
display: block;
clear: both;
}
span {
height: 2px;
margin: 5px 0px;
background: #333;
width: 100%;
display: block;
transition: .15s ease-in;
text-align: center;
&.toggled {
&:nth-of-type(1) {
transform: rotate(-45deg);
transform-origin: 22px 9px;
}
&:nth-of-type(2) {
transform: rotate(45deg);
transform-origin: 20px -5px;
}
}
}
}
and JS
$('.toggle-btn').on('click',function(){
$(this).find('span').toggleClass('toggled');
});
This appears to work. I had to adjust the margin to 4px. The rotation needs to come after the x/y translation because translating after the rotation appears to change the point of origin on which the element is rotating instead of origin of the element. You can observe this behavior by trying a large (100px) x-translation after the rotation.
.toggle-btn {
width: 38px;
height: 19px;
cursor: pointer;
position: relative;
margin-top: 18px;
text-align: center;
overflow: show;
&:after {
content: '';
display: block;
clear: both;
}
span {
height: 2px;
margin: 4px 0px;
background: #333;
width: 38px;
display: block;
transition: .15s ease-in;
text-align: center;
&.toggled {
&:nth-of-type(1) {
transform: translate(0px, 3px) rotate(-45deg);
}
&:nth-of-type(2) {
transform: translate(0px, -3px) rotate(45deg);
}
}
}
}
I am having two different issues. The first is really irritating. I am attempting to align the text with the image inside of the first box, so that they are side-by-side an inline fashion. I am not sure what I am doing wrong and I do not want to use floats.
Secondly, I am attempting to get the image to transform: translate on the x-axis on hover. The thing is, I want the image to transform on the .extra-box:hover...not on the actual image, but I only want the image to move. I cannot figure this out.
What am I doing wrong?
#extra {
margin: 25px auto;
width: 460px;
height: auto;
}
.extra-box {
position: relative;
width: 40%;
padding: 8px;
border-radius: 3px;
/*border: 1px solid #739BAF;*/
border: 2px solid black;
display: inline-block;
background: none;
transition: 0.5s ease;
}
.extra-box:hover {
border: 2px solid red;
transition: 0.5s ease;
}
.extra-box:first-child {
margin-left: 0;
width: 40%;
margin-right: 10%;
}
.extra-box:last-child {
width: 40%;
}
.extra-box a {
text-decoration: none;
}
.extra-box-text {
color: black;
font-size: 1em;
display: inline-block;
width: auto;
}
.extra-box-icon img {
padding-left: 5px;
width: 15px;
height: auto;
display: inline-block;
-webkit-transition: all .5 ease-in-out;
transition: all .5 ease-in-out;
/*transform: translateX(30px);
-webkit-transform: translateX(30px);*/
}
<div id="extra"><div class="extra-box">
<a href="contact">
<div class="extra-box-text">Need help?<br>Contact Us Now</div><div class="extra-box-icon"><img src="icons/right-arrow.png"></div>
</a>
</div><div class="extra-box">
<a href="register">
<div class="extra-box-text">Need an account?<br>Register Now</div>
</a>
</div>
</div>
As other answers pointed out, you were missing a display: inline-block, but the problem was in .extra-box-icon
I have also added the transform for the image: (See the beginning of the CSS)
.extra-box-icon {
display: inline-block;
}
img {
transition: transform 1s;
}
.extra-box:hover img {
transform: translateX(-100px);
}
#extra {
margin: 25px auto;
width: 460px;
height: auto;
}
.extra-box {
position: relative;
width: 40%;
padding: 8px;
border-radius: 3px;
/*border: 1px solid #739BAF;*/
border: 2px solid black;
display: inline-block;
background: none;
transition: 0.5s ease;
}
.extra-box:hover {
border: 2px solid red;
transition: 0.5s ease;
}
.extra-box:first-child {
margin-left: 0;
width: 40%;
margin-right: 10%;
}
.extra-box:last-child {
width: 40%;
}
.extra-box a {
text-decoration: none;
}
.extra-box-text {
color: black;
font-size: 1em;
display: inline-block;
width: auto;
}
.extra-box-icon img {
padding-left: 5px;
width: 15px;
height: auto;
display: inline-block;
-webkit-transition: all .5 ease-in-out;
transition: all .5 ease-in-out;
/*transform: translateX(30px);
-webkit-transform: translateX(30px);*/
}
<div id="extra">
<div class="extra-box">
<a href="contact">
<div class="extra-box-text">Need help?
<br>Contact Us Now</div>
<div class="extra-box-icon">
<img src="icons/right-arrow.png">
</div>
</a>
</div>
<div class="extra-box">
<a href="register">
<div class="extra-box-text">Need an account?
<br>Register Now</div>
</a>
</div>
</div>
Add vertical-align:top; in .extra-box class to align it to same level.
to fix the alignment issue and if you don't want to use float, you can change the display property of .extra-box-text and extra-box-text img to inline-block
.extra-box-text, .extra-box-text img{
display:inline-block;
width: /*adjust as needed*/
}
to deal with the animation, i suggest you set the image itself as a background of .extra-box, you would then change the background-position on hover
Hope this helps
I want to have a swipeable horizontal menu on my mobile website, just like Google uses on it's results page. I created one with basic html/css, which works fine but I cannot get rid of the scroll bar...
Here's the code:
<div style=" -ms-overflow-style: -ms-autohiding-scrollbar; -webkit-user-select: none; display: block; height: 50px; overflow-y: hidden; padding: 0px; position: relative; -webkit-overflow-scrolling: touch; overflow-x: scroll;">
<div style="display: inline-block; position: relative; white-space: nowrap; overflow: hidden;">
<div style="display: inline-block; height: 40px; text-align: center; padding: 0 16px;">ITEM</div>
<div style="display: inline-block; height: 40px; text-align: center; padding: 0 16px;">ITEM</div>
<div style="display: inline-block; height: 40px; text-align: center; padding: 0 16px;">ITEM</div>
<div style="display: inline-block; height: 40px; text-align: center; padding: 0 16px;">ITEM</div>
<div style="display: inline-block; height: 40px; text-align: center; padding: 0 16px;">ITEM</div>
<div style="display: inline-block; height: 40px; text-align: center; padding: 0 16px;">ITEM</div>
<div style="display: inline-block; height: 40px; text-align: center; padding: 0 16px;">ITEM</div>
</div>
</div>
Any idea?
See my menu here
See Google example here
You can make a container <div> element that holds the scrolling <div>.
This parent <div> style can be set to: oveflow:hidden and its size smaller than its child <div> -of which the style is set to overflow:scroll.
This way the scrollbar is hidden and you need not worry about doing this with JavaScript; however:
It is recommended that you create your CSS classes in either a <style> element, or a separate CSS file in which you can define these classes, and use these classes in your HTML like: <div class="menu">...
Using inline CSS as per the example above renders unmanageable code, especially in larger projects
Update
Here's a full example:
div
{
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}
.scrollHider
{
display:inline-block;
width:302px;
height:162px;
overflow:hidden;
border:1px solid #AAA;
}
.menuBox
{
width:315px;
height:175px;
overflow:scroll;
white-space:nowrap;
}
.menuSection
{
width:300px;
height:160px;
display:table-cell;
overflow:hidden;
}
.menuItem
{
width:300px;
height:40px;
text-align:center;
padding:10px;
border:1px solid #AAA;
}
<div class="scrollHider">
<div class="menuBox">
<div class="menuSection">
<div class="menuItem">ITEM 1</div>
<div class="menuItem">ITEM 2</div>
<div class="menuItem">ITEM 3</div>
<div class="menuItem">ITEM 4</div>
</div>
<div class="menuSection">
<div class="menuItem">ITEM 5</div>
<div class="menuItem">ITEM 6</div>
<div class="menuItem">ITEM 7</div>
<div class="menuItem">ITEM 8</div>
</div>
</div>
</div>
Preview: (partial screenshot)
The preview (above) shows where it is scrolled to the right. Copy & paste the code above in an empty HTML file, save & open in web browser. You can also click it and use keyboard arrows to scroll if you're not using a phone/touch-screen.
First put this link in your head tags. it is from purecss.io which is a small library of css modules. I use pure in about 40% of my projects.
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css">
Then put this into the body of your HTML page. I would recommend separating the css and js into their own files later.
<style>
.custom-menu-wrapper {
background-color: #808080;
margin-bottom: 2.5em;
white-space: nowrap;
position: relative;
}
.custom-menu {
display: inline-block;
width: auto;
vertical-align: middle;
-webkit-font-smoothing: antialiased;
}
.custom-menu .pure-menu-link,
.custom-menu .pure-menu-heading {
color: white;
}
.custom-menu .pure-menu-link:hover,
.custom-menu .pure-menu-heading:hover {
background-color: transparent;
}
.custom-menu-top {
position: relative;
padding-top: .5em;
padding-bottom: .5em;
}
.custom-menu-brand {
display: block;
text-align: center;
position: relative;
}
.custom-menu-toggle {
width: 44px;
height: 44px;
display: block;
position: absolute;
top: 3px;
right: 0;
display: none;
}
.custom-menu-toggle .bar {
background-color: white;
display: block;
width: 20px;
height: 2px;
border-radius: 100px;
position: absolute;
top: 22px;
right: 12px;
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-ms-transition: all 0.5s;
transition: all 0.5s;
}
.custom-menu-toggle .bar:first-child {
-webkit-transform: translateY(-6px);
-moz-transform: translateY(-6px);
-ms-transform: translateY(-6px);
transform: translateY(-6px);
}
.custom-menu-toggle.x .bar {
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
.custom-menu-toggle.x .bar:first-child {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
transform: rotate(-45deg);
}
.custom-menu-screen {
background-color: rgba(0, 0, 0, 0.5);
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-ms-transition: all 0.5s;
transition: all 0.5s;
height: 3em;
width: 70em;
position: absolute;
top: 0;
z-index: -1;
}
.custom-menu-tucked .custom-menu-screen {
-webkit-transform: translateY(-44px);
-moz-transform: translateY(-44px);
-ms-transform: translateY(-44px);
transform: translateY(-44px);
}
#media (max-width: 62em) {
.custom-menu {
display: block;
}
.custom-menu-toggle {
display: block;
display: none\9;
}
.custom-menu-bottom {
position: absolute;
width: 100%;
border-top: 1px solid #eee;
background-color: #808080\9;
z-index: 100;
}
.custom-menu-bottom .pure-menu-link {
opacity: 1;
-webkit-transform: translateX(0);
-moz-transform: translateX(0);
-ms-transform: translateX(0);
transform: translateX(0);
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-ms-transition: all 0.5s;
transition: all 0.5s;
}
.custom-menu-bottom.custom-menu-tucked .pure-menu-link {
-webkit-transform: translateX(-140px);
-moz-transform: translateX(-140px);
-ms-transform: translateX(-140px);
transform: translateX(-140px);
opacity: 0;
opacity: 1\9;
}
.pure-menu-horizontal.custom-menu-tucked {
z-index: -1;
top: 45px;
position: absolute;
overflow: hidden;
}
}
</style>
<div class="custom-menu-wrapper">
<div class="pure-menu custom-menu custom-menu-top">
Brand
<s class="bar"></s><s class="bar"></s>
</div>
<div class="pure-menu pure-menu-horizontal pure-menu-scrollable custom-menu custom-menu-bottom custom-menu-tucked" id="tuckedMenu">
<div class="custom-menu-screen"></div>
<ul class="pure-menu-list">
<li class="pure-menu-item">Home</li>
<li class="pure-menu-item">About</li>
<li class="pure-menu-item">Contact</li>
<li class="pure-menu-item">Blog</li>
<li class="pure-menu-item">GitHub</li>
<li class="pure-menu-item">Twitter</li>
<li class="pure-menu-item">Apple</li>
<li class="pure-menu-item">Google</li>
<li class="pure-menu-item">Wang</li>
<li class="pure-menu-item">Yahoo</li>
<li class="pure-menu-item">W3C</li>
</ul>
</div>
</div>
<script>
(function (window, document) {
document.getElementById('toggle').addEventListener('click', function (e) {
document.getElementById('tuckedMenu').classList.toggle('custom-menu-tucked');
document.getElementById('toggle').classList.toggle('x');
});
})(this, this.document);
</script>