I have a container div with a width set to 100%. Inside the container, there is a wrapper div centered with a height of 80%
and a dynamic number of images listed horizontally with inline-block
.wrapper {
width: 100%;
}
.testimg{
height: 100%;
width: 100%;
}
#testDiv{
display: block;
width: 80%;
margin: 0 auto;
overflow-x: auto;
white-space: nowrap;
}
.testimgdiv{
width: 120px;
height: 100px;
display: inline-block;
}
<div id="testDiv">
<div class='testimgdiv'>
<img class="testimg" src="http://via.placeholder.com/100x100" />
</div>
<div class='testimgdiv'>
<img class="testimg" src="http://via.placeholder.com/100x100" />
</div>
<div class='testimgdiv'>
<img class="testimg" src="http://via.placeholder.com/100x100" />
</div>
<div class='testimgdiv'>
<img class="testimg" src="http://via.placeholder.com/100x100" />
</div>
<div class='testimgdiv'>
<img class="testimg" src="http://via.placeholder.com/100x100" />
</div>
<div class='testimgdiv'>
<img class="testimg" src="http://via.placeholder.com/100x100" />
</div>
</div>
I want the last image on the left and last image on the right to have a fading effect and not cut like shown in jsfiddle. Sort of like a carousel. Is there a way to do this with just css and html?
Thanks
You could do this with a linear gradient background applied to generated content :before and :after #testDiv
.wrapper {
position: relative;
max-width: 100%;
}
#testDiv {
overflow-x: auto;
white-space: nowrap;
margin: 0 auto;
}
.testimgdiv {
width: 120px;
height: 100px;
display: inline-block;
}
.testimg {
height: 100%;
width: 100%;
}
#testDiv:before,
#testDiv:after {
width: 40px;
height: 100%;
content: '';
position: absolute;
top: 0;
}
#testDiv:before {
left: 0;
background: linear-gradient(-90deg, rgba(255, 255, 255, 0), rgb(255, 255, 255));
}
#testDiv:after {
right: 0;
background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgb(255, 255, 255));
}
<div class="wrapper">
<div id="testDiv">
<div class='testimgdiv'>
<img class="testimg" src="http://via.placeholder.com/100x100" />
</div>
<div class='testimgdiv'>
<img class="testimg" src="http://via.placeholder.com/100x100" />
</div>
<div class='testimgdiv'>
<img class="testimg" src="http://via.placeholder.com/100x100" />
</div>
<div class='testimgdiv'>
<img class="testimg" src="http://via.placeholder.com/100x100" />
</div>
<div class='testimgdiv'>
<img class="testimg" src="http://via.placeholder.com/100x100" />
</div>
<div class='testimgdiv'>
<img class="testimg" src="http://via.placeholder.com/100x100" />
</div>
</div>
</div>
Related
I'm learning CSS and I have a problem with CSS flexbox and grid.
I wanted to make a grid as shown above but I couldn't. The first and last containers are in different sizes and the others are the same.
Here is my code:
.second-section {
width: 80%;
margin: 10px auto;
display: flex;
flex-direction: row;
position: relative;
flex-wrap: wrap;
}
.category-devider {
width: 80%;
margin: 0 auto;
}
.category-devider p {
font-size: 16px;
}
.category-devider span {
font-size: 18px;
color: #757575;
}
.image-containers {
position: relative;
width: 45%;
margin: 50px auto;
height: 434px;
background-color: #494949;
display: block;
text-align: center;
}
.image-containers h3 {
font-size: 18px;
}
.second-section #img-container img {
height: 100%;
width: 100%;
object-fit: cover;
}
.img1 img {
height: 612px;
}
<div class="second-section">
<div class="image-containers img1">
<img src="/img/apple-watch.jpg" alt="Apple Watch" />
<h3>Rule ratio</h3>
<p>Product design</p>
</div>
<div class="image-containers img2">
<img src="/img/circle.jpg" alt="Situation" />
<h3>Situation</h3>
<p>Visual identity</p>
</div>
<div class="image-containers img3">
<img src="/img/cards.jpg" alt="Cards" />
<h3>Dry air</h3>
<p>User research</p>
</div>
<div class="image-containers img4">
<img src="/img/orange-phone.jpeg" alt="Phone" />
<h3>Vertical</h3>
<p>Product design</p>
</div>
<div class="image-containers img5">
<img src="/img/phone.jpg" alt="Phone" />
<h3>Variable compose</h3>
<p>Product design</p>
</div>
<div class="image-containers img6">
<img src="/img/phone1.jpg" alt="Phone" />
<h3>Scope shift</h3>
<p>Product design</p>
</div>
</div>
You can make array of objects:
{
name: 'name',
title: 'title',
text: 'text'
}
and write:
<div class="second-section">
{array.map((picture, index) => {
<div class={`image-containers img${index}`}>
<img src={`/img/${name}.jpg`} alt="Phone" />
<h3>{picture.title}</h3>
<p>{picture.text}</p>
</div>
})}
</div>
<div id="grid">
<div class="grid-items">
<img src="./images/desktop/image-deep-earth.jpg" alt="" />
<h4 class="grid-items-heading">Deep earth</h4>
</div>
<div class="grid-items">
<img src="./images/desktop/image-night-arcade.jpg" alt="" />
<h4 class="grid-items-heading">night arcade</h4>
</div>
<div class="grid-items">
<img src="./images/desktop/image-soccer-team.jpg" alt="" />
<h4 class="grid-items-heading">soccor team vr</h4>
</div>
<div class="grid-items">
<img src="./images/desktop/image-grid.jpg" alt="" />
<h4 class="grid-items-heading">the grid</h4>
</div>
<div class="grid-items">
<img src="./images/desktop/image-from-above.jpg" alt="" />
<h4 class="grid-items-heading">from up above vr</h4>
</div>
<div class="grid-items">
<img src="./images/desktop/image-pocket-borealis.jpg" alt="" />
<h4 class="grid-items-heading">pokect borealis</h4>
</div>
<div class="grid-items">
<img src="./images/desktop/image-curiosity.jpg" alt="" />
<h4 class="grid-items-heading">the curiosity</h4>
</div>
<div class="grid-items">
<img src="./images/desktop/image-fisheye.jpg" alt="" />
<h4 class="grid-items-heading">Make it fisheye</h4>
</div>
</div>
#grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: 1fr 1fr;
place-items: center;
row-gap: 2.5rem;
}
.grid-items {
position: relative;
cursor: pointer;
}
.grid-items-heading {
position: absolute;
bottom: 25px;
padding: 0 2rem;
color: var(--white);
font-size: 1.5rem;
width: 74%;
margin: 0;
z-index: 100;
}
.grid-items::after {
content : "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: rgba(0,0,0,0.1);
}
.grid-items:hover .grid-items::after {
background-color: rgba(255, 255, 255, 0.5);
z-index : 80;
}
I am creating a grid that contains 8 elements each element has 2 items one is an image and one is a heading.
I have given a position relative to grid-items class and position absolute to heading to place it at the bottom of that particular gid item. So then I have created a after element of grid items and which I like a overlay its like a fade black color over a grid item and I want to change its color whenever I hover over grid-item which is not working. The whole after element is not working
use .grid-items:hover:after to work.
#grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: 1fr 1fr;
place-items: center;
row-gap: 2.5rem;
}
img{
width:200px;
height:200px;
}
.grid-items {
position: relative;
cursor: pointer;
border: 2px solid red;
}
.grid-items-heading {
position: absolute;
bottom: 25px;
padding: 0 2rem;
color: var(--white);
font-size: 1.5rem;
width: 74%;
margin: 0;
z-index: 100;
}
.grid-items::after {
content : "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: rgba(0,230,0,0.1);
}
.grid-items:hover:after{
background-color: rgba(255, 120, 255, 0.5);
z-index : 80;
}
<div id="grid">
<div class="grid-items">
<h4 class="grid-items-heading">Deep earth</h4>
</div>
<div class="grid-items">
<img src="./images/desktop/image-night-arcade.jpg" alt="" />
<h4 class="grid-items-heading">night arcade</h4>
</div>
<div class="grid-items">
<img src="./images/desktop/image-soccer-team.jpg" alt="" />
<h4 class="grid-items-heading">soccor team vr</h4>
</div>
<div class="grid-items">
<img src="./images/desktop/image-grid.jpg" alt="" />
<h4 class="grid-items-heading">the grid</h4>
</div>
<div class="grid-items">
<img src="./images/desktop/image-from-above.jpg" alt="" />
<h4 class="grid-items-heading">from up above vr</h4>
</div>
<div class="grid-items">
<img src="./images/desktop/image-pocket-borealis.jpg" alt="" />
<h4 class="grid-items-heading">pokect borealis</h4>
</div>
<div class="grid-items">
<img src="./images/desktop/image-curiosity.jpg" alt="" />
<h4 class="grid-items-heading">the curiosity</h4>
</div>
<div class="grid-items">
<img src="./images/desktop/image-fisheye.jpg" alt="" />
<h4 class="grid-items-heading">Make it fisheye</h4>
</div>
</div>
You just need a comma between your hover and after class.
.grid-items:hover, .grid-items::after {
background-color: rgba(255, 255, 255, 0.5);
z-index : 80;
}
(source: kheper.net)
The effect I'm going for is the whole square being one div, with each square being a smaller div within the bigger div, correctly aligned, to take up the entire viewport.
Similar to montere.it minus the JavaScript.
I've tried to highlight the problematic bits of code, the corresponding CSS isn't formatting correctly but I've linked a JS bin below.
Apologies if my code is spaghetti code, it's less my code and more a copy and paste session gone wild.
#bodyHobbies {
width: 100%;
height: 500px;
}
.intbox1 {
height: 25%;
width: 100%;
background-color: #009900;
margin: auto;
text-align: center;
}
.intbox2 {
height: 25%;
width: 100%;
background-color: #990000;
margin: auto;
text-align: center;
color: #FFFFFF;
}
.intbox3 {
height: 25%;
width: 100%;
background-color: #000000;
margin: auto;
text-align: center;
color: #FFFFFF;
}
.intbox4 {
height: 25%;
width: 100%;
background-color: #990000;
margin: auto;
text-align: center;
color: #FFFFFF;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div id="bodyHobbies">
<div class="intbox1">
<p>1</p>
<img src="foobar1.jpg" border="0" />
</div>
<div class="intbox2">
<p>2</p>
<img src="foobar.jpg" border="0" />
</div>
<div class="intbox3">
<p>3</p>
<img src="foobar.jpg" border="0" />
</div>
<div class="intbox4">
<p>4</p>
<img src="foobar.jpg" border="0" />
</div>
</div>
https://jsbin.com/heyibe/edit?html,css,output
you can done that using css3 flexbox concept
html,body{
margin:0;
padding:0;
width:100%;
height:100%;
}
img{
width:100%;
}
#bodyHobbies{
display:flex;
flex-flow: row wrap;
}
.item{
flex-basis:50%;
}
<div id="bodyHobbies">
<div class="intbox1 item"><p>1</p>
<img src="https://i.stack.imgur.com/GSqmw.jpg" border="0" />
</div>
<div class="intbox2 item"><p>2</p>
<img src="https://i.stack.imgur.com/GSqmw.jpg" border="0" />
</div>
<div class="intbox3 item"><p>3</p>
<img src="https://i.stack.imgur.com/GSqmw.jpg" border="0" />
</div>
<div class="intbox4 item"><p>4</p>
<img src="https://i.stack.imgur.com/GSqmw.jpg" border="0" />
</div>
</div>
Just added display: inline-table to you #bodyHobbies and added a common class to the intbox divs. Removed the individual intbox stylings related to width and heights.
#bodyHobbies {
width: 100%;
height: 500px;
display: inline-table;
}
.intbox {
width: 50%;
height: 50%;
display: inline-block;
}
.intbox img {
width: 100%;
}
.intbox1 {
background-color:#009900;
margin:auto;
text-align:center;
}
.intbox2 {
background-color:#990000;
margin:auto;
text-align:center;
color:#FFFFFF;
}
.intbox3 {
background-color:#000000;
margin:auto;
text-align:center;
color:#FFFFFF;
}
.intbox4 {
background-color:#933230;
margin:auto;
text-align:center;
color:#FFFFFF;
}
<div id="bodyHobbies">
<div class="intbox intbox1"><p>1</p>
<img src="http://lorempixel.com/900/700/sports/1/" border="0" />
</div>
<div class="intbox intbox2"><p>2</p>
<img src="http://lorempixel.com/900/700/sports/1/" border="0" />
</div>
<div class="intbox intbox3"><p>3</p>
<img src="http://lorempixel.com/900/700/sports/1/" border="0" />
</div>
<div class="intbox intbox4"><p>4</p>
<img src="http://lorempixel.com/900/700/sports/1/" border="0" />
</div>
</div>
Try this
<div id="bodyHobbies">
<div class="intbox1"><p>1</p>
<img src="foobar1.jpg" border="0" />
</div>
<div class="intbox2"><p>2</p>
<img src="foobar.jpg" border="0" />
</div>
<div class="intbox3"><p>3</p>
<img src="foobar.jpg" border="0" />
</div>
<div class="intbox4"><p>4</p>
<img src="foobar.jpg" border="0" />
</div>
CSS
#bodyHobbies div{
float: left;
width: 50%;
}
<div id="bodyHobbies">
<div class="box">
<p>1</p>
<img src="foobar1.jpg" border="0" />
</div>
<div class="box">
<p>2</p>
<img src="foobar.jpg" border="0" />
</div>
<div class="box">
<p>3</p>
<img src="foobar.jpg" border="0" />
</div>
<div class="box">
<p>4</p>
<img src="foobar.jpg" border="0" />
</div>
</div>
<style>
.box{width:calc(50% - 2px); margin:2px; float:left; min-height:100px;}
</style>
At css use vw, vh units to set body, parent element width, height to 100vw, 100vh. Set [class=^"int"] selector position to absolute. Set element left and top properties corresponding to the four positions within the viewport using :nth-of-type() pseudo class. left:0vw, top:0vh; left:50vw, top:0vh; left:0vw, top:50vh, left:50vw, top:50vh.
body {
width: 100vw;
height: 100vh;
}
#bodyHobbies {
width: 100vw;
height: 100vh;
display: block;
position: relative;
border: 2px solid sienna;
}
[class^="int"] {
width: 50vw;
height: 50vh;
display: block;
position: absolute;
border: 2px solid gold;
}
[class^="int"]:nth-of-type(1) {
left: 0vw;
top: 0vw;
background: blue;
}
[class^="int"]:nth-of-type(2) {
left: 50vw;
top: 0vh;
background: green
}
[class^="int"]:nth-of-type(3) {
left: 0vw;
top: 50vh;
background: red;
}
[class^="int"]:nth-of-type(4) {
left: 50vw;
top: 50vh;
background: tan;
}
<div id="bodyHobbies">
<div class="intbox1">
<p>1</p>
<img src="foobar1.jpg" border="0" alt="foobar1" />
</div>
<div class="intbox2">
<p>2</p>
<img src="foobar.jpg" border="0" alt="foobar2" />
</div>
<div class="intbox3">
<p>3</p>
<img src="foobar.jpg" border="0" alt="foobar3" />
</div>
<div class="intbox4">
<p>4</p>
<img src="foobar.jpg" border="0" alt="foobar4" />
</div>
</div>
jsfiddle https://jsfiddle.net/69zkbjgw/
Each image should have a transparent black overlay with a white number centered over it like "100", "200" etc. This number represents the amount of points needed to unlock the picture. How can I achieve this?
JSFiddle
HTML
<div class="wrapper">
<div class="scrolls">
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
<img src="http://placehold.it/150x150" style="height:100px"/>
</div>
</div>
CSS
.wrapper {
background:#f4f4f4;
margin: auto;
text-align: center;
position: relative;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
margin-bottom: 20px !important;
width: 550px;
padding-top: 5px;
}
.scrolls {
overflow-x: scroll;
overflow-y: hidden;
height: 150px;
white-space:nowrap
}
.imageDiv img {
margin: 2px;
max-height: 150px;
cursor: pointer;
display:inline-block;
*display:inline;
*zoom:1;
vertical-align:top;
}
You need to wrap each image and overlay in an individual div. The overlay is then positioned absolutely over the image.
.wrapper {
background: #f4f4f4;
margin: auto;
text-align: center;
position: relative;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
margin-bottom: 20px !important;
width: 550px;
padding-top: 5px;
}
.scrolls {
overflow-x: scroll;
overflow-y: hidden;
height: 150px;
white-space: nowrap;
padding-bottom: 25px;
}
.imageDiv {
margin: 2px;
max-height: 150px;
cursor: pointer;
display: inline-block;
*display: inline;
*zoom: 1;
vertical-align: top;
position: relative;
}
.imageDiv .overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.25);
line-height: 150px;
color: transparent;
font-size: 2em;
text-align: center;
transition: all .5s ease;
}
.imageDiv:hover .overlay {
background: rgba(0, 0, 0, 0.55);
color: white;
;
}
.imgaDiv img {
display: block;
}
<div class="wrapper">
<div class="scrolls">
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
<div class="imageDiv">
<img src=" http://placehold.it/150x150 " />
<div class="overlay">100</div>
</div>
</div>
</div>
For a refinement/enhancement, you could do away with an actual overlay div and use a pseudo-element instead..if it's just styling. The technique remains the same.
I'm trying to use this jquery grid plugin, but it's not working with my layout. The images are stacked on top of each other, they seem to be spilling out of .main, and they overlap the footer. Help? :C
body {
padding: 0;
margin: 0;
color: $fontcolor;
background-color: #eee;
font: 100% 'Open Sans', sans-serif;
background-color: $main-bg;
width: 100%;
height: 100%;
}
.container {
margin: 0 auto;
width: 80%;
height: 100%;
}
.main {
width: 100%;
background-color: $content-bg;
}
.grid-container {
background-color: #F9F9F9;
box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.15);
margin: 20px auto;
position: relative; }
.grid-item {
display: inline-block;
font-size: 0;
position: absolute;
}
.grid-item img {
cursor: pointer;
display: block;
width: 100%; }
<body>
<div class="container">
<div class="main">
<div class='grid-container'>
<div class='grid-item'>
<img alt='' src='stackgrid/example/img/short.jpg'>
</div>
<div class='grid-item'>
<img alt='' src='stackgrid/example/img/tall.jpg'>
</div>
<div class='grid-item'>
<img alt='' src='stackgrid/example/img/medium.jpg'>
</div>
<div class='grid-item'>
<img alt='' src='stackgrid/example/img/tall.jpg'>
</div>
<div class='grid-item'>
<img alt='' src='stackgrid/example/img/short.jpg'>
</div>
<div class='grid-item'>
<img alt='' src='stackgrid/example/img/medium.jpg'>
</div>
<div class='grid-item'>
<img alt='' src='stackgrid/example/img/medium.jpg'>
</div>
<div class='grid-item'>
<img alt='' src='stackgrid/example/img/short.jpg'>
</div>
<div class='grid-item'>
<img alt='' src='stackgrid/example/img/medium.jpg'>
</div>
</div>
</div>
</div>
</body>
Make sure you are initializing stackgrid in window load.
Also try the .reset() method.