Text when hover on HTML - html

I would like to place a text on an image when hovering it. So far, I have created a hover effect to zoom the picture in and reduce the opacity which looks smooth. My problem now is to place text on the image because I am not sure how to place it in the picture.
Here is what I have so far: enter link description here
Code:
#portfolio {
background-color: : white;
padding-bottom: 100px;
}
#portfolio h1 {
font-size: 30px;
font-weight: 400px;
letter-spacing: 5px;
text-align: center;
color: #000;
}
#portfolio h2 {
font-size: 15px;
letter-spacing: 2px;
text-align: center;
color: #000;
}
.project {
display: inline-block;
width: 33.33%;
margin-right: -4px;
}
.img-box {
padding: 20px;
}
.project img {
width: 100%;
display: block;
border-radius: 12px;
}
.img-box img:hover {
transform: scale(1.1);
transition: 0.5s;
opacity: 0.5;
}
<section id="portfolio">
<div class="container">
<h1>MY WORK</h1>
<h2>Below you will find my favorite projects & school assignments</h2>
<!--CPU-->
<div class="project">
<div class="img-box">
<img src="./img/cpu.png">
</div>
</div>
<!--JAVA-->
<div class="project">
<div class="img-box">
<img src="./img/JSON.png">
</div>
</div>
<!--PHOTOSHOP-->
<div class="project">
<div class="img-box">
<img src="./img/photoshop.png">
</div>
</div>
</div>
</section>

Add another DIV as a child element to .img-box with settings as follows which contains the text. The most important part is position: absolute, plus the top, left and transform settings for the text position.
.img-box .hovertext {
display: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.img-box:hover .hovertext {
display: block;
}
Also make sure to add position: relative to .img-box to create an anchor element for the absolutely positioned text DIV:
#portfolio {
background-color: : white;
padding-bottom: 100px;
}
#portfolio h1 {
font-size: 30px;
font-weight: 400px;
letter-spacing: 5px;
text-align: center;
color: #000;
}
#portfolio h2 {
font-size: 15px;
letter-spacing: 2px;
text-align: center;
color: #000;
}
.project {
display: inline-block;
width: 33.33%;
margin-right: -4px;
}
.img-box {
padding: 20px;
position: relative;
}
.project img {
width: 100%;
display: block;
border-radius: 12px;
}
.img-box img:hover {
transform: scale(1.1);
transition: 0.5s;
opacity: 0.5;
}
.img-box .hovertext {
display: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.img-box:hover .hovertext {
display: block;
}
<section id="portfolio">
<div class="container">
<h1>MY WORK</h1>
<h2>Below you will find my favorite projects & school assignments</h2>
<!--CPU-->
<div class="project">
<div class="img-box">
<img src="./img/cpu.png">
<div class="hovertext">Test Text 1</div>
</div>
</div>
<!--JAVA-->
<div class="project">
<div class="img-box">
<img src="./img/JSON.png">
<div class="hovertext">Test Text 2</div>
</div>
</div>
<!--PHOTOSHOP-->
<div class="project">
<div class="img-box">
<img src="./img/photoshop.png">
<div class="hovertext">Test Text 3</div>
</div>
</div>
</div>
</section>

You can use pseudo-element and you can either add the text you want as an attribute value or add it manually which would be hideous. and then style it as you would, but of course add position:absolute to take it off of the flow so it can be put on top of the image. And don't forget your position:relative on the parent.
I used the div, because <img> doesn't have a closing tag therefore no pseudo-elements
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
#portfolio {
background-color: : white;
padding-bottom: 100px;
}
#portfolio h1 {
font-size: 30px;
font-weight: 400px;
letter-spacing: 5px;
text-align: center;
color: #000;
}
#portfolio h2 {
font-size: 15px;
letter-spacing: 2px;
text-align: center;
color: #000;
}
.project {
display: inline-block;
width: 33.33%;
margin-right: -4px;
}
.img-box {
padding: 20px;
position: relative;
}
.img-box:after {
/* the text will be coming from the custom attribute data-text*/
content: attr(data-text);
background: #000000ba;
width: 100%;
font-size: 1.5em;
padding: 10px 0;
left: 0;
bottom: 0;
text-align: center;
position: absolute;
opacity: 0;
transition: opacity .2s linear;
}
.img-box:hover:after {
opacity: 1;
}
.project img {
width: 100%;
display: block;
border-radius: 12px;
}
.img-box img:hover {
transform: scale(1.1);
transition: 0.5s;
opacity: 0.5;
}
<section id="portfolio">
<div class="container">
<h1>MY WORK</h1>
<h2>Below you will find my favorite projects & school assignments</h2>
<!--CPU-->
<div class="project">
<div data-text="Text" class="img-box">
<img src="http://via.placeholder.com/350x150">
</div>
</div>
<!--JAVA-->
<div class="project">
<div data-text="text on image" class="img-box">
<img src="http://via.placeholder.com/350x150">
</div>
</div>
<!--PHOTOSHOP-->
<div class="project">
<div data-text="i'm a text too" class="img-box">
<img src="http://via.placeholder.com/350x150">
</div>
</div>
</div>
</section>

Related

positioning a div in above another div

This is challenging for me to position the share div like in the picture above. well, I tried the position absolute with bottom and left it's so frustrating adjusting the px but the output is always either stacked on top or bottom. how can I achieve that similar output in the picture?
:root {
--VeryDarkGrayishBlue: hsl(217, 19%, 35%);
--DesaturatedDarkBlue: hsl(214, 17%, 51%);
--GrayishBlue: hsl(212, 23%, 69%);
--LightGrayishBlue: hsl(210, 46%, 95%);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Manrope", sans-serif;
}
body {
background-color: var(--GrayishBlue);
display: flex;
flex-direction: column;
min-height: 100vh;
padding: 20px;
}
.container {
display: grid;
grid-template-columns: 2fr 3fr;
max-width: 1150px;
max-height: 390px;
margin: auto;
background-color: white;
overflow: hidden;
border-radius: 0.8em;
}
.img-box {}
.img-box img {
width: 100%;
height: 100%;
object-fit: cover;
}
.text-box {
padding: 8%;
}
.text {
padding-bottom: 30px;
}
.title {
color: var(--VeryDarkGrayishBlue);
padding-bottom: 10px;
}
.subtitle {
color: var(--GrayishBlue);
font-size: 1.1em;
}
.writer img {
width: 50px;
height: 50px;
border-radius: 50%;
}
.footer {
display: flex;
flex-direction: row;
align-items: center;
}
.name {
margin-left: 12px;
}
.name h4 {
color: var(--VeryDarkGrayishBlue);
}
.name p {
color: var(--GrayishBlue);
}
.share {
margin-left: auto;
}
.share-icon button {
border: none;
width: 40px;
height: 40px;
border-radius: 50%;
background-color: var(--LightGrayishBlue);
cursor: pointer;
}
.share-option {
width: 250px;
height: 40px;
background: var(--VeryDarkGrayishBlue);
border-radius: 10px;
display: flex;
justify-content: center;
align-items: center;
color: white;
position: absolute;
bottom: ;
}
<main class="container">
<div class="img-box">
<img src="/images/drawers.jpg" alt="" />
</div>
<div class="text-box">
<div class="text">
<h1 class="title">
Shift the overall look and feel by adding these wonderful touches to furniture in your home
</h1>
<p class="subtitle">
Ever been in a room and felt like something was missing? Perhaps it felt slightly bare and uninviting. I’ve got some simple tips to help you make any room feel complete.
</p>
</div>
<div class="footer">
<div class="writer">
<img src="/images/avatar-michelle.jpg" alt="" />
</div>
<div class="name">
<h4>Michelle Appleton</h4>
<p>28 Jun 2020</p>
</div>
<div class="share">
<div class="share-icon">
<button><img src="/images/icon-share.svg" alt=""></button>
</div>
<div class="share-option hidden">
<span>Share</span>
<a href="#"> <img src="/images/icon-facebook.svg" alt=""> <a/>
<a href="#"> <img src="/images/icon-pinterest.svg" alt=""> <a/>
<a href="#"> <img src="/images/icon-twitter.svg" alt=""> <a/>
</div>
</div>
</div>
</div>
</main>
I have made some changes in the code and made the popup visible with absolute.
:root {
--VeryDarkGrayishBlue: hsl(217, 19%, 35%);
--DesaturatedDarkBlue: hsl(214, 17%, 51%);
--GrayishBlue: hsl(212, 23%, 69%);
--LightGrayishBlue: hsl(210, 46%, 95%);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Manrope", sans-serif;
}
body {
background-color: var(--GrayishBlue);
display: flex;
flex-direction: column;
min-height: 100vh;
padding: 20px;
}
.container {
display: grid;
grid-template-columns: 2fr 3fr;
max-width: 1150px;
max-height: 390px;
margin: auto;
background-color: white;
border-radius: 0.8em;
}
.container:after {
display: block;
content: '';
clear: both;
}
.img-box {}
.img-box img {
width: 100%;
height: 100%;
object-fit: cover;
}
.text-box {
padding: 8%;
}
.text {
padding-bottom: 30px;
}
.title {
color: var(--VeryDarkGrayishBlue);
padding-bottom: 10px;
}
.subtitle {
color: var(--GrayishBlue);
font-size: 1.1em;
}
.writer img {
width: 50px;
height: 50px;
border-radius: 50%;
}
.footer {
display: flex;
flex-direction: row;
align-items: center;
}
.name {
margin-left: 12px;
}
.name h4 {
color: var(--VeryDarkGrayishBlue);
}
.name p {
color: var(--GrayishBlue);
}
.share {
margin-left: auto;
position: relative;
padding: 20px 0 0;
}
.share-icon button {
border: none;
width: 40px;
height: 40px;
border-radius: 50%;
background-color: var(--LightGrayishBlue);
cursor: pointer;
}
.share-option {
width: 250px;
height: 40px;
background: var(--VeryDarkGrayishBlue);
border-radius: 10px;
color: white;
position: absolute;
bottom: 100%;
right: 50%;
transform: translatex(50%);
visibility: hidden;
opacity: 0;
transition: visibility 0s, opacity 0.5s linear;
}
.share-option:after {
top: 100%;
left: 50%;
border: solid transparent;
content: "";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-color: rgba(136, 183, 213, 0);
border-top-color: var(--VeryDarkGrayishBlue);
border-width: 10px;
margin-left: -10px;
}
.share:hover .share-option {
visibility: visible;
opacity: 1;
}
<main class="container">
<div class="img-box">
<img src="/images/drawers.jpg" alt="" />
</div>
<div class="text-box">
<div class="text">
<h1 class="title">
Shift the overall look and feel by adding these wonderful touches to furniture in your home
</h1>
<p class="subtitle">
Ever been in a room and felt like something was missing? Perhaps it felt slightly bare and uninviting. I’ve got some simple tips to help you make any room feel complete.
</p>
</div>
<div class="footer">
<div class="writer">
<img src="/images/avatar-michelle.jpg" alt="" />
</div>
<div class="name">
<h4>Michelle Appleton</h4>
<p>28 Jun 2020</p>
</div>
<div class="share">
<div class="share-icon">
<button><img src="/images/icon-share.svg" alt=""></button>
</div>
<div class="share-option hidden">
<span>Share</span>
<a href="#"> <img src="/images/icon-facebook.svg" alt=""> <a/>
<a href="#"> <img src="/images/icon-pinterest.svg" alt=""> <a/>
<a href="#"> <img src="/images/icon-twitter.svg" alt=""> <a/>
</div>
</div>
</div>
</div>
</main>
I think without javascript you won't be able to do it.
You could include your share-option (position absolute) inside share-icon (position relative). This way option would be positioned relative to the button.
<div class="share">
<div class="share-icon">
<button>
<img src="/images/icon-share.svg" alt="">
</button>
<div class="share-option hidden">
<span>Share</span>
<img src="/images/icon-facebook.svg" alt="">
<img src="/images/icon-pinterest.svg" alt="">
<img src="/images/icon-twitter.svg" alt="">
</div>
</div>
</div>
and css
.share-icon {
position: relative;
}
.share-icon button {
border: none;
width: 40px;
height: 40px;
border-radius: 50%;
background-color: var(--LightGrayishBlue);
cursor: pointer;
}
.share-option {
width: 250px;
height: 40px;
background: var(--VeryDarkGrayishBlue);
border-radius: 10px;
display: flex;
justify-content: center;
align-items: center;
color: white;
position: absolute;
top: -40px;
z-index: 100;
}
Now the problem is options are in the boundary of the relative, so it doesn't extend on the right!
I suppose this container is responsive, meaning size can change. So I think the only way would be to put the option in the body (display none), when a click (or hover) happens on the button, you take the position of the button and position options on top of it with display flex

How can I fix images in flexbox to wrap 2x2? And correct the hover option?

These are my two flexboxes, one for text and the other for category links. I'm trying to lay the category pictures as 2 by 2. I tried to use row wrap, and center the contents, but it didn't work. I also used various methods using containers, but it always ends up 1 x 4... Also, I'm trying to hover option to fit perfectly into the image, but somehow I have the hover background image not perfectly fit with the image although it's height and width is set to 100%.
How can I solve these issues?
.flex-container {
display: flex;
justify-content: center;
flex-direction: row;
width: 800px;
}
.flex-container > div {
margin: 10px;
padding: 20px;
font-size: 20px;
text-align: center;
flex-flow: row wrap;
}
.one {
flex: 1 1 auto;
}
.two {
flex: 1 1 auto;
}
div.two a > img {
padding: 10px;
margin: 10px;
}
a {
text-decoration: none;
}
h1 {
display: block;
font-size: 1.3em;
margin: 0.67em 0;
font-weight: bold;
}
h2 {
display: block;
font-size: 0.8em;
margin: 0.83em 0;
font-weight: bold;
}
.container {
position: relative;
width: 50%;
}
.image {
display: block;
width: 200%;
height: auto;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: darkorchid;
}
.container:hover .overlay {
opacity: 1;
}
.text {
color: Black;
font-size: 18px;
position: absolute;
top: 30%;
left: 100%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
<section>
<div class="flex-container">
<div class="one"> <h1> Welcome to Delicious Book store, <br>
where you can find so many delicious food!</h1>
<p> As a specialized book store, we have many cooking books on
holiday specials, vegetarian, desserts and cultural cuisines!</p>
</div>
<div class="two"> <h2> Shop By Category </h2>
<div class="container">
<a href="category.html">
<img src="images/categories/holiday.jpg" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Holiday</div>
</div></a>
</div>
<div class="container">
<a href="category.html">
<img src="images/categories/holiday.jpg" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Dessert</div>
</div></a>
</div>
<div class="container">
<a href="category.html">
<img src="images/categories/holiday.jpg" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Vegetarian</div>
</div></a>
</div>
<div class="container">
<a href="category.html">
<img src="images/categories/holiday.jpg" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Cultural Cuisine</div>
</div></a>
</div>
</div>
</div>
</section>
I've wrapped your boxes with flex container, and change some css regards width of the boxes and their content. Also added width: 100% to your .flex-container.
.flex-container {
display: flex;
justify-content: center;
flex-direction: row;
width: 100%;
}
.flex-container > div {
margin: 10px;
padding: 20px;
font-size: 20px;
text-align: center;
flex-flow: row wrap;
width: 500%;
}
.one {
flex: 1 1 auto;
}
.two {
flex: 1 1 auto;
}
a {
text-decoration: none;
}
h1 {
display: block;
font-size: 1.3em;
margin: 0.67em 0;
font-weight: bold;
}
h2 {
display: block;
font-size: 0.8em;
margin: 0.83em 0;
font-weight: bold;
}
.container {
position: relative;
width: calc(50% - 20px);
margin: 10px;
}
.image {
display: block;
width: 100%;
height: 100%;
min-height: 75px;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: darkorchid;
min-height: 75px;
}
.container:hover .overlay {
opacity: 1;
}
.text {
color: Black;
font-size: 18px;
position: relative;
text-align: center;
padding: 10px;
}
.images-container{
display: flex;
flex-wrap: wrap;
}
<section>
<div class="flex-container">
<div class="one"> <h1> Welcome to Delicious Book store, <br>
where you can find so many delicious food!</h1>
<p> As a specialized book store, we have many cooking books on
holiday specials, vegetarian, desserts and cultural cuisines!</p>
</div>
<div class="two"> <h2> Shop By Category </h2>
<div class="images-container">
<div class="container">
<a href="category.html">
<img src="https://via.placeholder.com/150" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Holiday</div>
</div></a>
</div>
<div class="container">
<a href="category.html">
<img src="https://via.placeholder.com/150" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Dessert</div>
</div></a>
</div>
<div class="container">
<a href="category.html">
<img src="https://via.placeholder.com/150" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Vegetarian</div>
</div></a>
</div>
<div class="container">
<a href="category.html">
<img src="https://via.placeholder.com/150" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Cultural Cuisine</div>
</div></a>
</div>
</div>
</div>
</div>
</section>

Duplicating Youtube's navigation bar, but, I have a habit of using position: absolute; I need a more effective way of doing this

This is the epitome of DRY code, I need to find an effective way of writing this code. I am currently using The Odin Project and the guidelines were to Duplicate Youtube's video section. I completed the navigation bar, but I am unhappy with it since I am just using position: absolute all the time. I was about using Grid or flexbox but I do not really know if it will help.
* {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
body {
background-color: #f8f8f8;
}
.navigation {
height: 70px;
width: 100%;
background-color: #fff;
box-shadow: 0px 1px 4px #ebebeb;
}
.menu {
position: absolute;
left: 30px;
top: 22px;
opacity: .4;
cursor: pointer;
}
.menu:hover {
opacity: 1;
}
.youtube-logo {
width: 90px;
position: absolute;
left: 70px;
top: 10px;
}
.search-bar {
position: absolute;
top: 21px;
left: 390px;
width: 600px;
height: 33px;
background: url(images/search.svg) no-repeat 95% 50%;
background-size: 16px;
border-radius: 2px;
border: 1px solid #b3b3b3;
padding-left: 20px;
box-sizing: border-box;
outline: none;
}
::placeholder {
font-family: Arial, Helvetica, sans-serif;
font-size: 1.2em;
padding-left: 3px;
}
.video {
position: absolute;
left: 1150px;
top: 25px;
cursor: pointer;
opacity: .4;
}
.stack {
position: absolute;
left: 1210px;
cursor: pointer;
width: 18px;
opacity: .4;
top: 27px;
}
.message {
position: absolute;
left: 1265px;
top: 24px;
;
opacity: .4;
cursor: pointer;
}
.bell {
position: absolute;
left: 1320px;
top: 23px;
opacity: .4;
cursor: pointer;
}
.icon {
position: absolute;
top: 16px;
left: 1374px;
cursor: pointer;
width: 36px;
opacity: .4;
}
<nav class="navigation">
<img src="images/menu.svg" alt="menu for the top left, shaped like a hamburger" class="menu">
<img src="images/youtube.logo.png" alt="youtube logo" class="youtube-logo">
<input type="text" name="searchbar" placeholder="Search" class="search-bar">
<img src="images/video.svg" alt="video icon" class="video">
<img src="images/google-app-button.png" alt="square stacks" class="stack">
<img src="images/message-square (1).svg" alt="message forr youtube" class="message">
<img src="images/bell.svg" alt="bell for top right bar" class="bell">
<img src="images/icons8-male-user-512.png" alt="profile picture for the bar" class="icon">
</nav>
Flexbox is pretty straight forward. You only need to set display: flex; on the parent element and the children elements will be affected.
.parent-flex {
display: flex;
}
<h2>Without Flexbox</h2>
<div>
<div>Child 1</div>
<div>Child 2</div>
<div>Child 3</div>
</div>
<h2>With Flexbox</h2>
<div class="parent-flex">
<div class="child-1">Child 1</div>
<div class="child-2">Child 2</div>
<div class="child-3">Child 3</div>
</div>
Since you are trying to replicate the youtube navbar, I'd recommend using flexbox to setup the "regions" of the navbar and then applying justify-content: space-between; to space out the regions equally.
.flex {
display: flex;
}
.parent {
justify-content: space-between;
}
.child-1 {}
.child-2 {}
.child-3 {
justify-content: flex-end;
}
<div class="flex parent">
<div class="flex child-1">
<div class="menu">[Menu Icon]</div>
<div class="logo">[Logo]</div>
</div>
<div class="flex child-2">
<div class="search-box">[search box]</div>
<div class="search-button">[search button]</div>
</div>
<div class="flex child-3">
<div class="user-photo">[the user's photo]</div>
<div class="etc">[whatever other icons...]</div>
</div>
</div>
You can check out this great article on css-tricks to learn more about the ins and outs of flexbox.
https://css-tricks.com/snippets/css/a-guide-to-flexbox/

Text on Shape to Diff. Text upon Hover

I've definitely never identified myself as a coder, which is why I need some help. I've tried & tried to get a grid of shapes with text overlayed to change to different text whenever the mouse is hovering over it - completely different text. I looked up before & after properties but still can't get it right because of the "grid" css.
I'm hoping to have "name" on the normal shape, and then other text on the hovered shape for more information. How would I go about doing this? I've supplied a fiddle to show everything.
http://jsfiddle.net/6c4v2ypv/3/
Thank you all tremendously for your help.
CSS
.grid {
width: 100%;
max-width: 900px;
margin: 0 auto;
background: #fff;
}
.grid::after {
content: "";
display: block;
clear: both;
}
.grid-item {
width: 21.833%;
padding-bottom: 21.833%;
overflow: hidden;
float: left;
background: #BBB;
transform: rotate(45deg);
margin: 5.5%;
margin-top: -11%;
}
.grid-item:nth-child(1),
.grid-item:nth-child(2),
.grid-item:nth-child(3) {
margin-top: 5%;
}
.grid-item:nth-child(5n+4) {
margin-left: 21.9%;
}
.grid-item:nth-child(5n+6) {
clear: left;
}
.grid-item:nth-child(5n+6):last-of-type {
margin-left: 38.25%;
}
.grid-item:hover {
background: #000;
}
.grid-inner {
box-sizing: border-box;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform: rotate(-45deg);
text-align: center;
padding-top: 40%;
font-size: 1em;
}
.grid-inner:hover a span {
display: none;
}
.grid-inner:hover:after {
box-sizing: border-box;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform: rotate(-45deg);
text-align: center;
padding-top: 40%;
font-size: 1em;
background-color: black;
}
Maybe so?
.grid {
width: 100%;
max-width: 900px;
margin: 0 auto;
background: #fff;
}
.grid::after {
content: "";
display: block;
clear: both;
}
.grid-item {
width: 21.833%;
padding-bottom: 21.833%;
overflow: hidden;
float: left;
background: #BBB;
transform: rotate(45deg);
margin: 5.5%;
margin-top: -11%;
}
.grid-item:nth-child(1),
.grid-item:nth-child(2),
.grid-item:nth-child(3) {
margin-top: 5%;
}
.grid-item:nth-child(5n+4) {
margin-left: 21.9%;
}
.grid-item:nth-child(5n+6) {
clear: left;
}
.grid-item:nth-child(5n+6):last-of-type {
margin-left: 38.25%;
}
.grid-item:hover {
background: #000;
}
.grid-inner {
box-sizing: border-box;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform: rotate(-45deg);
text-align: center;
padding-top: 40%;
font-size: 1em;
}
.grid-inner:hover a span {
display: none;
}
.grid-inner:hover:after {
box-sizing: border-box;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform: rotate(-45deg);
text-align: center;
padding-top: 40%;
font-size: 1em;
background-color: black;
}
.grid-inner-hover {
opacity: 0;
}
.grid-item:hover .grid-inner-hover {
opacity: 1;
color: #fff;
}
<div class="grid">
<div class="grid-item">
<div class="grid-inner">Name 1</div>
<div class="grid-inner grid-inner-hover">Name 1 Hover</div>
</div>
<div class="grid-item">
<div class="grid-inner">Name 2</div>
<div class="grid-inner grid-inner-hover">Name 2 Hover</div>
</div>
<div class="grid-item">
<div class="grid-inner">Name 3</div>
<div class="grid-inner grid-inner-hover">Name 3 Hover</div>
</div>
<div class="grid-item">
<div class="grid-inner">Name 4</div>
<div class="grid-inner grid-inner-hover">Name 4 Hover</div>
</div>
<div class="grid-item">
<div class="grid-inner">Name 5</div>
<div class="grid-inner grid-inner-hover">Name 5 Hover</div>
</div>
<div class="grid-item">
<div class="grid-inner">Name 6</div>
<div class="grid-inner grid-inner-hover">Name 6 Hover</div>
</div>
</div>
here's a simple example:
.item1:hover span, .item2:hover span{
display: none;
}
.item1:hover:after{
content: 'ADD';
}
.item2:hover:after{
content: 'Subtract';
}
<div class="item1">
<span >first</span>
</div>
<div class="item2">
<span>second</span>
</div>
You can also add something like this in your css:
.grid-inner:hover:after{
content:'hello';
color:#fff;
transform:rotate(0deg);
}
http://jsfiddle.net/6c4v2ypv/5/

How to make this div with display:table take the height of 80% of its parent, without affecting the negative margins of table-cells

JSFiddle here!
In this SSCCE, I have given a display:table property to .container, which contains <section> elements with display:table-row property, and each section has an <img> with display:table-cell property, and another nested <section> with display:table-cell property.
In the first column, each table-cell contains an image, and because I have used negative margin-bottom on the table-cells in this column, all the images in the first column give the look/illusion of one image.
What I want is that the .container div (with display:table;) should get a height of the "height of the viewport (that is the visible-screen-size without scrolling) MINUS a padding-top and padding-bottom of 200px each." So that the illusion-of-the-image in the first column shrinks to that size.
#import url(<link href='http://fonts.googleapis.com/css?family=Open+Sans:700,300,600,400' rel='stylesheet' type='text/css'>);
.section-big {
padding: 100px 0;
}
.section-big .container {
width: 970px;
margin: 200px auto;
}
.section-big .col {
width: 47%;
}
.section-big .col-left {
float: left;
text-align: right;
padding-right: 25px;
}
.section-big .col-right {
float: left;
text-align: left;
padding-left: 25px;
}
.section-big .col-left img {
height: 80%;
width: 50%;
}
h3 {
color: #6c6969;
transition: color 0.3s ease 0s;
font-family: 'Open Sans', sans-serif;
font-weight: 600;
font-size: 40px;
}
h5 {
color: #6c6969;
transition: color 0.3s ease 0s;
font-family: 'Open Sans', sans-serif;
font-weight: 400;
font-size: 20px;
}
.container {
display: table;
margin: 200px auto;
}
.container>section {
display: table-row;
}
.col1td,
.col2td {
display: table-cell;
vertical-align: middle;
padding: 0px 25px;
/*height: 250px;*/
}
.top1 {
vertical-align: bottom;
margin-bottom: -64px;
}
.top2 {
vertical-align: top;
margin-bottom: -62px;
/*margin-left:45px;*/
}
.top3 {
vertical-align: top;
margin-bottom: -62px;
/*margin-left:45px;*/
}
.top5 {
vertical-align: top;
margin-bottom: -62px;
/*margin-left:25px;*/
}
.section-big {
height: 100vh;
padding: 0px;
margin: 0px;
}
<div class="section-big">
<div class="container">
<section class="section-one">
<img class="col1td top1" src="http://www.mediafire.com/convkey/0a97/utelxs08krq3fd3zg.jpg" alt="ton ton 1">
<section class="col2td">
<h3>HEADING</h3>
<h5>Paragraph paragraph</h5>
</section>
</section>
<section class="section-two">
<img class="col1td top2" src="http://www.mediafire.com/convkey/7f55/jsl7mw25qbs3e54zg.jpg" alt="ton ton 2">
<section class="col2td">
<h3>HEADING</h3>
<h5>Paragraph paragraph</h5>
</section>
</section>
<section class="section-three">
<img class="col1td top3" src="http://www.mediafire.com/convkey/6e7e/jjd597oeexkd5h4zg.jpg" alt="ton ton 3">
<section class="col2td">
<h3>HEADING</h3>
<h5>Paragraph paragraph</h5>
</section>
</section>
<section class="section-four">
<img class="col1td top5" src="http://www.mediafire.com/convkey/d99d/4g75pbwt1c59971zg.jpg" alt="ton ton 5">
<section class="col2td">
<h3>HEADING</h3>
<h5>Paragraph paragraph</h5>
</section>
</section>
</div>
</div>
WHAT I TRIED:
I saw this example, and tried to give a height:500px; as well
as height:50%; after giving the body a height:100%;, but that
does not seem to have any effect.
I saw this SO question and gave the .section-big a
height:100vh so that if I give the .container (the
display:table element) a percentage height (which will be
calculated as X% of the height of .section-big). So I gave .container a height:80%; and adjusted the margin-bottoms of table-cells of first column, which resulted in JSFiddle. BUT
first, the section-big does get a height:100vh as I can see that
by
hovering over it in the Google chrome inspector, but that 100vh is
overflowing below the visible viewport as shown in the following
figure.
Second, even the body does not start at the top of the document as
shown in the following screenshot.
Third, the .container bleeds/overflows out of its parent
section-big.
JSFiddle here. So I am clueless about what to do!
Try this out.. it could help...
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<div class="heading-bar">
<u>
<li><a class="js-scroll" href="#section-one">section1</a></li>
<li><a class="js-scroll" href="#section-two">section2</a></li>
<li><a class="js-scroll" href="#section-three">section3</a></li>
<li><a class="js-scroll" href="#section-four">section4</a></li>
</u>
<header>
<h1>heading</h1>
</header>
</div>
<div class="container">
<section id="section-one">
<img class="col1td top1" src="http://www.mediafire.com/convkey/0a97/utelxs08krq3fd3zg.jpg" alt="ton ton 1">
<section class="col2td">
<h3>HEADING</h3>
<h5>Paragraph paragraph</h5>
</section>
</section>
<section id="section-two">
<img class="col1td top2" src="http://www.mediafire.com/convkey/7f55/jsl7mw25qbs3e54zg.jpg" alt="ton ton 2">
<section class="col2td">
<h3>HEADING</h3>
<h5>Paragraph paragraph</h5>
</section>
</section>
<section id="section-three">
<img class="col1td top3" src="http://www.mediafire.com/convkey/6e7e/jjd597oeexkd5h4zg.jpg" alt="ton ton 3">
<section class="col2td">
<h3>HEADING</h3>
<h5>Paragraph paragraph</h5>
</section>
</section>
<section id="section-four">
<img class="col1td top5" src="http://www.mediafire.com/convkey/d99d/4g75pbwt1c59971zg.jpg" alt="ton ton 5">
<section class="col2td">
<h3>HEADING</h3>
<h5>Paragraph paragraph</h5>
</section>
</section>
</div>
css
/*#import url(<link href='http://fonts.googleapis.com/css?family=Open+Sans:700,300,600,400' rel='stylesheet' type='text/css'>);*/
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 0px;
padding: 0px;
}
.heading-bar {
height: 200px;
background-color: white;
position: fixed;
z-index: 100;
width: 100%;
min-width: 100%;
top: 0px;
text-align: center;
}
li {
direction: ltr;
text-decoration: none;
margin: 10px;
display: inline-block;
}
li a{
}
.container {
width: 80%;
overflow: scroll;
}
.section-big .col {
width: 47%;
}
.section-big .col-left {
float: left;
text-align: right;
padding-right: 25px;
}
.section-big .col-right {
float: left;
text-align: left;
padding-left: 25px;
}
.section-big .col-left img {
height: 80%;
width: 50%;
}
h3 {
color: #6c6969;
transition: color 0.3s ease 0s;
font-family: 'Open Sans', sans-serif;
font-weight: 600;
font-size: 40px;
}
h5 {
color: #6c6969;
transition: color 0.3s ease 0s;
font-family: 'Open Sans', sans-serif;
font-weight: 400;
font-size: 20px;
}
.container {
display: table;
margin: 200px auto;
}
.container>section {
display: table-row;
}
.col1td,
.col2td {
display: table-cell;
vertical-align: middle;
padding: 0px 25px;
/*height: 250px;*/
}
.top1 {
vertical-align: bottom;
margin-bottom: -64px;
}
.top2 {
vertical-align: top;
margin-bottom: -62px;
/*margin-left:45px;*/
}
.top3 {
vertical-align: top;
margin-bottom: -62px;
/*margin-left:45px;*/
}
.top5 {
vertical-align: top;
margin-bottom: -62px;
/*margin-left:25px;*/
}
.section-big {
height: 100vh;
padding: 0px;
margin: 0px;
}
javascript
$('.js-scroll').click(function(){
var headerHeight = 200;
$('body').animate({
scrollTop: $( $.attr(this, 'href') ).offset().top - headerHeight
}, 500);
return false;
});