different distance between elements with same classes - html

I've stuck with styling issues. What I'm trying to reach is make sure that every single h3 tag has same distance between bottom border of his container (pink border) and bottom border of his parent (picture bottom border). Now it looks like this:
Both of them has same css, difference is only with amount of text.
HTML:
<div class="col-6">
<a href='{{link}}' style='background-image: url("{{image}}")' class="histories__image">
<div class="histories__text">
<h3>{{title}}</h3>
</div>
<div class="histories__underline"></div>
</a>
</div>
CSS:
.histories {
margin-bottom: 100px;
&__image {
height: 41vh;
margin-top: 33px;
display: block;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
transition: filter 1s;
&:hover{
filter: brightness(80%);
}
&:hover .histories__text{
bottom: 15px;
}
&:hover .histories__underline{
opacity: 1;
left: 0;
width: 70%;
}
}
&__text {
text-align: center;
display: block;
position: absolute;
width: 100%;
bottom: 0px;
left: 50%;
transform: translate(-50%, -50%);
transition: bottom .3s;
color: white;
border: 1px solid pink;
}
&__underline {
position: absolute;
display: block;
bottom: 10%;
width: 0%;
left: 50%;
margin-left: 15%;
background-color: white;
height: 1px;
opacity: 0;
transition: width .3s, left .3s;
}
}

You can try using translate like this to center your content with the same class.
.histories__text{
width: 100%;
}
.histories__text h3{
transform: translate(50%,50%);
}
<div class="col-6">
<a href='{{link}}' class="histories__image">
<div class="histories__text">
<h3>Your Text</h3>
</div>
<div class="histories__underline"></div>
</a>
</div>

Related

CSS scale jitter on one of 2 div

I put 2 <div> side by side and added both a scale animation and an overlay on hover. Yet the left side jitters when the mouse moves inside the area while the right side is quite stable on hover.
I thought both sides are using pretty much the same code and could not figure out the cause of this problem. What caused the jitter?
code here
body {
font-family: 'Asap', sans-serif;
color: white;
margin-left: 10%;
margin-right: 10%;
margin-top: 5%;
background: repeating-linear-gradient( 45deg, #222, #222 10px, #333 10px, #333 20px);
background-attachment: fixed;
}
.showcase {
margin-top: 5%;
position: relative;
display: block;
overflow: hidden;
}
.cameraShowcase {
width: 47.5%;
padding-right: 2.5%;
float: left;
transition: transform .3s;
}
.cameraShowcase:hover .overlay {
opacity: 0.75;
}
.cameraShowcase:hover {
transform: scale(1.1);
}
.wheelShowcase {
width: 47.5%;
padding-left: 2.5%;
float: left;
transition: transform .3s;
}
.wheelShowcase:hover .overlay {
opacity: 0.75;
}
.wheelShowcase:hover {
transform: scale(1.1);
}
.overlay {
text-align: center;
position: absolute;
opacity: 0;
transition: .3s;
background-color: #333;
top: 0;
bottom: 0;
right: 0;
height: 100%;
width: 95%;
}
#leftOverlay {
left: 0;
}
#rightOverlay {
left: 5%;
}
.textContainer {
padding-left: 10%;
padding-right: 10%;
padding-top: 15%;
line-height: 2;
}
<div class="showcase">
<div class="cameraShowcase">
<div class="pic">
<img src="https://www.w3schools.com/html/img_chania.jpg" alt="camera" />
</div>
<div class="overlay" id="leftOverlay">
<div class="textContainer">
<h3>Camera and Sensors</h3>
</div>
</div>
</div>
<div class="wheelShowcase">
<div class="pic">
<img src="https://www.w3schools.com/html/img_chania.jpg" alt="wheel" />
</div>
<div class="overlay" id="rightOverlay">
<div class="textContainer">
<h3>Power System</h3>
</div>
</div>
</div>
</div>
You are having a complex case of stacking elements. You set your overlay element position:absolute and the first positionned ancestor is showcase so initially both overlay are overlapping and filling the width of showcase
Remove the opacity to notice this:
body {
font-family: 'Asap', sans-serif;
color: white;
margin-left: 10%;
margin-right: 10%;
margin-top: 5%;
background: repeating-linear-gradient( 45deg, #222, #222 10px, #333 10px, #333 20px);
background-attachment: fixed;
}
.showcase {
margin-top: 5%;
position: relative;
display: block;
overflow: hidden;
}
.cameraShowcase {
width: 47.5%;
padding-right: 2.5%;
float: left;
transition: transform .3s;
}
.cameraShowcase:hover .overlay {
opacity: 0.75;
}
.cameraShowcase:hover {
transform: scale(1.1);
}
.wheelShowcase {
width: 47.5%;
padding-left: 2.5%;
float: left;
transition: transform .3s;
}
.wheelShowcase:hover .overlay {
opacity: 0.75;
}
.wheelShowcase:hover {
transform: scale(1.1);
}
.overlay {
text-align: center;
position: absolute;
transition: .3s;
background-color: #333;
top: 0;
bottom: 0;
right: 0;
height: 100%;
width: 95%;
}
#leftOverlay {
left: 0;
}
#rightOverlay {
left: 5%;
}
.textContainer {
padding-left: 10%;
padding-right: 10%;
padding-top: 15%;
line-height: 2;
}
<div class="showcase">
<div class="cameraShowcase">
<div class="pic">
<img src="https://www.w3schools.com/html/img_chania.jpg" alt="camera" />
</div>
<div class="overlay" id="leftOverlay">
<div class="textContainer">
<h3>Camera and Sensors</h3>
</div>
</div>
</div>
<div class="wheelShowcase">
<div class="pic">
<img src="https://www.w3schools.com/html/img_chania.jpg" alt="wheel" />
</div>
<div class="overlay" id="rightOverlay">
<div class="textContainer">
<h3>Power System</h3>
</div>
</div>
</div>
</div>
Now on hover you add scale() to the parent element of your overlay which will make them positionned relatively to them since transform change the containing block of absolute and fixed element.
So you will have this:
body {
font-family: 'Asap', sans-serif;
color: white;
margin-left: 10%;
margin-right: 10%;
margin-top: 5%;
background: repeating-linear-gradient( 45deg, #222, #222 10px, #333 10px, #333 20px);
background-attachment: fixed;
}
.showcase {
margin-top: 5%;
position: relative;
display: block;
overflow: hidden;
}
.cameraShowcase {
width: 47.5%;
padding-right: 2.5%;
float: left;
transition: transform .3s;
}
.cameraShowcase:hover .overlay {
opacity: 0.75;
}
.cameraShowcase {
transform: scale(1.1);
}
.wheelShowcase {
width: 47.5%;
padding-left: 2.5%;
float: left;
transition: transform .3s;
}
.wheelShowcase:hover .overlay {
opacity: 0.75;
}
.wheelShowcase:hover {
transform: scale(1.1);
}
.overlay {
text-align: center;
position: absolute;
transition: .3s;
background-color: #333;
top: 0;
bottom: 0;
right: 0;
height: 100%;
width: 95%;
}
#leftOverlay {
left: 0;
}
#rightOverlay {
left: 5%;
}
.textContainer {
padding-left: 10%;
padding-right: 10%;
padding-top: 15%;
line-height: 2;
}
<div class="showcase">
<div class="cameraShowcase">
<div class="pic">
<img src="https://www.w3schools.com/html/img_chania.jpg" alt="camera" />
</div>
<div class="overlay" id="leftOverlay">
<div class="textContainer">
<h3>Camera and Sensors</h3>
</div>
</div>
</div>
<div class="wheelShowcase">
<div class="pic">
<img src="https://www.w3schools.com/html/img_chania.jpg" alt="wheel" />
</div>
<div class="overlay" id="rightOverlay">
<div class="textContainer">
<h3>Power System</h3>
</div>
</div>
</div>
</div>
You are toggling between both states and since in the first one you have an overlap, you will get that bad effect where you are losing the hover effect. It doesn't happen with the second image because its overlay is on the top so you will never loss the hover.
To avoid this you can keep transform on your element initially or consider position:relative on them to make sure your overlay elements are positioned relatively to their parent and never overlap:
body {
font-family: 'Asap', sans-serif;
color: white;
margin-left: 10%;
margin-right: 10%;
margin-top: 5%;
background: repeating-linear-gradient( 45deg, #222, #222 10px, #333 10px, #333 20px);
background-attachment: fixed;
}
.showcase {
margin-top: 5%;
position: relative;
display: block;
overflow: hidden;
}
.cameraShowcase {
width: 47.5%;
padding-right: 2.5%;
float: left;
transition: transform .3s;
transform: scale(1);
}
.cameraShowcase:hover .overlay {
opacity: 0.75;
}
.cameraShowcase:hover {
transform: scale(1.1);
}
.wheelShowcase {
width: 47.5%;
padding-left: 2.5%;
float: left;
transition: transform .3s;
transform: scale(1);
}
.wheelShowcase:hover .overlay {
opacity: 0.75;
}
.wheelShowcase:hover {
transform: scale(1.1);
}
.overlay {
text-align: center;
position: absolute;
transition: .3s;
background-color: #333;
opacity:0;
top: 0;
bottom: 0;
right: 0;
height: 100%;
width: 95%;
}
#leftOverlay {
left: 0;
}
#rightOverlay {
left: 5%;
}
.textContainer {
padding-left: 10%;
padding-right: 10%;
padding-top: 15%;
line-height: 2;
}
<div class="showcase">
<div class="cameraShowcase">
<div class="pic">
<img src="https://www.w3schools.com/html/img_chania.jpg" alt="camera" />
</div>
<div class="overlay" id="leftOverlay">
<div class="textContainer">
<h3>Camera and Sensors</h3>
</div>
</div>
</div>
<div class="wheelShowcase">
<div class="pic">
<img src="https://www.w3schools.com/html/img_chania.jpg" alt="wheel" />
</div>
<div class="overlay" id="rightOverlay">
<div class="textContainer">
<h3>Power System</h3>
</div>
</div>
</div>
</div>
I added the following to your cameraShowcase and wheelShowcase:
position: relative;
display: inline-block;
float: left;

Changing the background image of a circle

I am trying to draw a number of CSS generated circles that have images as background. In my current code, the background image is set as a fixed image in the CSS code.
.container {
text-align: center;
}
.circle {
position: relative;
height: 180px;
width: 180px;
border-radius: 50%;
display: inline-flex;
vertical-align: top;
justify-content: center;
align-items: center;
overflow: hidden;
text-decoration: none;
border: 0;
margin: 10px;
}
.circle:after {
content: "";
position: absolute;
z-index: -1;
top: 0;
left: 0;
height: 100%;
width: 100%;
background: url("http://deepchains.com/images/team.png") center / cover no-repeat;
opacity: .25;
transition: .25s;
}
.circle:hover:after {
opacity: 1;
color: transparent;
}
.circle:hover {
color: transparent;
}
.ccont {
display: inline-block;
margin: 10px;
}
.ccont:hover {
color: transparent;
}
<div class="container">
<a class="circle" href="http://www.url1.html">
<div class="ccont" style="font-weight: bold; text-decoration:none !important;">This is <br>Text1</div>
</a>
<a class="circle" href="http://www.url2.html">
<div class="ccont" style="font-weight: bold; text-decoration:none !important;">This is <br>Text2</div>
</a>
</div>
Here is a sample result that I see in Chrome Browser:
My question is how to change the background images of each circle separately in the HTML code? I will have a number of these circles that I like them to be aligned and in the same line, and I want to set their background images in the HTML code and remove the background image from the CSS. How can I do that?
An easy solution is to transform your peudo element to an element and use background-image as inline style so you can easily change the image for each element and apply all the same properties as the pseudo element:
.container {
text-align: center;
}
.circle {
position: relative;
height: 180px;
width: 180px;
border-radius: 50%;
display: inline-flex;
vertical-align: top;
justify-content: center;
align-items: center;
overflow: hidden;
text-decoration: none;
border: 0;
margin: 10px;
}
.circle .image {
position: absolute;
z-index: -1;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-position:center;
background-size:cover;
background-repeat:no-repeat;
opacity: .25;
transition: .25s;
}
.circle:hover .image {
opacity: 1;
color: transparent;
}
.circle:hover .ccont{
color: transparent;
}
.ccont {
display: inline-block;
margin: 10px;
}
<div class="container">
<a class="circle" href="http://www.url1.html">
<span class="image" style="background-image: url(http://lorempixel.com/400/300/)"></span>
<div class="ccont" style="font-weight: bold; text-decoration:none !important;">This is <br>Text1</div>
</a>
<a class="circle" href="http://www.url2.html">
<span class="image" style="background-image:url(https://lorempixel.com/400/200/)"></span>
<div class="ccont" style="font-weight: bold; text-decoration:none !important;">This is <br>Text2</div>
</a>
</div>
Simply set up the background image on the pseudo to be inherited from parent, set the size on parent to 0 to hide it there, and finally, set style="background-image: url(...)" in the markup.
Updated
You can even drop the inner div and still achieve the same effect
Stack snippet
.container {
text-align: center;
}
.circle {
position: relative;
height: 180px;
width: 180px;
border-radius: 50%;
display: inline-flex;
justify-content: center;
align-items: center;
overflow: hidden;
font-weight: bold;
text-decoration: none;
border: 0;
margin: 10px;
background-size: 0; /* hide image by set its size to 0 */
}
.circle:after {
content: "";
position: absolute;
z-index: -1;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-image: inherit; /* inherit from parent */
background-position: center;
background-size: cover;
background-repeat: no-repeat;
opacity: .25;
transition: .25s;
}
.circle:hover:after {
opacity: 1;
}
.circle:hover {
color: transparent;
}
<div class="container">
<a class="circle" href="http://www.url1.html" style="background-image: url(https://picsum.photos/300/300?image=1070);">
This is <br>Text1
</a>
<a class="circle" href="http://www.url2.html" style="background-image: url(https://picsum.photos/300/300?image=1072);">
This is <br>Text2
</a>
</div>

CSS: Stacking Order Issue

I currently have a few vertical tabs that when hovered expand down toward the content within the page. As they expand down, a "content" div within the hovered tab expands out to the right away from the tab. I like the way this looks aside from the fact that I can't seem to get the "content" div to appear on top of the other tabs. I would assume that this is due to stacking order since when I reverse the order it works just fine. Can anyone help me resolve this issue? I've tried z-index, and opacity tricks to get it to work and nothing so far. I understand that z-index changes context based on position and opacity but my knowledge on this is limited. When you supply a possible solution, can you explain why it works?
Code:
.tab {
background: #0AF;
width: 50px;
height: 150px;
position: absolute;
top: -100px;
border-radius: 5px;
transition: all linear 0.2s;
}
.tab:hover {
top: -5px;
border-bottom-right-radius: 0px;
}
.content {
position: absolute;
left: 0;
width: 50px;
height: 150px;
background: #EEE;
border-radius: 5px;
transition: all linear 0.2s;
opacity: 0;
text-align: center;
color: #222;
}
.content .foot {
position: absolute;
bottom: 0;
margin-left: -50px;
margin-bottom: 5px;
}
.tab:hover > .content, .content:hover {
left: 40px;
width: 300px;
opacity: 1;
border-bottom-left-radius: 0px;
}
.about {
background: #0AF;
}
.social {
left: 80px;
background: #F05;
}
.projects {
left: 150px;
background: #0F5;
}
<div class="tab about">
<div class="content">
<span class="foot">About Me</span>
</div>
</div>
<div class="tab social">
<div class="content">
<span class="foot">Social Media</span>
</div>
</div>
<div class="tab projects">
<div class="content">
<span class="foot">Projects</span>
</div>
</div>
Thanks,
Jamie
You could give an z-index to .tab:hover. The order is given by the order of elements in the DOM so if you give a z-index you create a new stacking order referred to the nearest position relative parent. Smashing magazing has a good post in merit link
.tab {
background: #0AF;
width: 50px;
height: 150px;
position: absolute;
top: -100px;
border-radius: 5px;
transition: all linear 0.2s;
}
.tab:hover {
top: -5px;
z-index: 3;
}
.content {
position: absolute;
left: 0;
width: 50px;
height: 150px;
background: #EEE;
border-radius: 5px;
transition: all linear 0.2s;
opacity: 0;
text-align: center;
color: #222;
}
.content .foot {
position: absolute;
bottom: 0;
margin-left: -50px;
margin-bottom: 5px;
}
.tab:hover > .content, .content:hover {
left: 40px;
width: 300px;
opacity: 1;
}
.about {
background: #0AF;
}
.social {
left: 70px;
background: #F05;
}
.projects {
left: 130px;
background: #0F5;
}
<div class="tab about">
<div class="content">
<span class="foot">About Me</span>
</div>
</div>
<div class="tab social">
<div class="content">
<span class="foot">Social Media</span>
</div>
</div>
<div class="tab projects">
<div class="content">
<span class="foot">Projects</span>
</div>
</div>
Just Insert z-index:999 to .content
.tab {
background: #0AF;
width: 50px;
height: 150px;
position: absolute;
top: -100px;
border-radius: 5px;
transition: all linear 0.2s;
}
.tab:hover {
top: -5px;
border-bottom-right-radius: 0px;
}
.content {
position: absolute;
left: 0;
width: 50px;
height: 150px;
background: #EEE;
border-radius: 5px;
transition: all linear 0.2s;
opacity: 0;
text-align: center;
color: #222;
z-index: 999;
}
.content .foot {
position: absolute;
bottom: 0;
margin-left: -50px;
margin-bottom: 5px;
}
.tab:hover > .content, .content:hover {
left: 40px;
width: 300px;
opacity: 1;
border-bottom-left-radius: 0px;
}
.about {
background: #0AF;
}
.social {
left: 80px;
background: #F05;
}
.projects {
left: 150px;
background: #0F5;
}
<div class="tab about">
<div class="content">
<span class="foot">About Me</span>
</div>
</div>
<div class="tab social">
<div class="content">
<span class="foot">Social Media</span>
</div>
</div>
<div class="tab projects">
<div class="content">
<span class="foot">Projects</span>
</div>
</div>

Mask position incorrect when I stop using a background image

Using http://jsfiddle.net/4UNuB/5/ as an example, the image has been set as background
.box1 {
border: #999 2px solid;
width: 180px;
height: 250px;
background-image: url(http://smilesoftware.com/assets/images/uploads/products/icon_pdfpenipad_140x140.png);
background-position: center;
background-repeat: no-repeat;
}
But, if I can't use a background image, and instead have an img src within the div itself like this
<div class="box1">
<img src="http://placehold.it/180x250">
</div>
The mask no longer covers the image, instead sitting below it.
See this fiddle http://jsfiddle.net/4UNuB/6/
But the mask is still being applied to the same place as before, so why does it move, and how to stop it moving?
Add Position Absolute and relative css for boxes.
Check The Fiddle here
.box1 {
border: #999 2px solid;
width: 180px;
height: 250px;
/*background-image: url(http://smilesoftware.com/assets/images/uploads/products/icon_pdfpenipad_140x140.png);*/
background-position: center;
background-repeat: no-repeat;
position: relative;
}
.black-box {
text-align: center;
font-size: 16px;
color: #fff;
background-color: rgba(00,00,00,0.8);
width: 100%;
height: 100%;
opacity: 1.0;
transition: all 0.5s ease-in-out;
position: absolute;
top: 0;
}
You can put both in the same anchor and use positioning + z-index:
.box1 {
border: #999 2px solid;
width: 180px;
height: 250px;
/*background-image: url(http://smilesoftware.com/assets/images/uploads/products/icon_pdfpenipad_140x140.png);
background-position: center;
background-repeat: no-repeat;*/
}
img {
position: absolute;
z-index: 0;
}
.black-box {
position: relative;
z-index: 1;
text-align: center;
font-size: 16px;
color: #fff;
background-color: rgba(00,00,00,0.8);
width: 100%;
height: 100%;
opacity: 1.0;
transition: all 0.5s ease-in-out;
}
.black-box:hover {
opacity: 0.0;
transition: all 0.5s ease-in-out;
}
h2 {
padding-top: 110px;
margin: 0px;
}
<div class="box1">
<a href="http://placehold.it">
<img src="http://placehold.it/180x250">
<div class="black-box">
<h2>View Details</h2>
</div>
</a>
</div>
Also, I had to remove the h2's margin.

Overflow hidden not working on hover

I have this div and I want to show the title when I hover over title div. The problem is that I get the hover effect even if I hover on the edges of the div. So the div is treated as a square and not as a circle when I hover on it. This works pretty well on Firefox but not on Chrome and Safari.
Fiddle: http://jsfiddle.net/roeg629c/2/
Note: I do not want to change the aspect ratio of the image. The image should be 100% of the parent height.
HTML
<div class="video_wrap update" video_name="rikthejmna">
<div class="related img_wrap"><img src="http://img.youtube.com/vi/XyzYVpJGRG8/hqdefault.jpg"></div>
<div class="title">rikthejm na</div>
</div>
CSS
.video_wrap {
width: 232px;
height: 232px;
display: inline-block;
border-radius: 116px;
overflow: hidden;
margin: 10px;
position: relative;
z-index: 2;
}
.img_wrap img {height: 100%}
.related {height: 100%;}
.title {
position: relative;
top: -50px;
left: 0px;
background: #fff;
height: 50px;
opacity: .5;
color: #f8008c;
font-size: 12px;
text-align: center;
line-height: 50px;
overflow: hidden;
cursor: default;
transition: all .5s ease-in;
}
.title:hover {opacity: 1}
Avoid positioning of the .title, and opacity.
.video_wrap{
width: 232px;
height: 232px;
border-radius: 50%;
overflow: hidden;
margin: 10px;
}
.related {
width: 232px;
height: 232px;
position: absolute;
border-radius: 50%;
overflow: hidden;
z-index: -1;
}
.img_wrap img {
height: 100%;
}
.title{
margin: 185px 0 0;
background: rgba(255,255,255,.5);
line-height: 50px;
text-align: center;
transition: all .5s ease-in;
}
.title:hover{
background: #fff;
}
<div class="video_wrap update">
<div class="related img_wrap"><img src="http://img.youtube.com/vi/XyzYVpJGRG8/hqdefault.jpg"></div>
<div class="title">
rikthejm na
</div>
</div>