So I am trying to make a loop of images that has description overlaying each of it. The overlay would be visible when the picture is hovered. Here is an example of the code.
.container {
height: 100px;
width:100px;
display: inline-block;
}
.picture {
height: 100%;
width:100%
}
.contAlign {
text-align: center;
}
.desc {
position:flex;
bottom: 0;
left: 0;
right: 0;
background-color: black;
width: 100%;
height: 0%;
opacity: 0.5;
transition: .5s ease;
}
.container:hover .desc {
height: 40%;
}
<div class="contAlign">
<div class="container">
<img class="picture" src="https://kbob.github.io/images/sample-3.jpg">
<div class="desc"></div>
</div>
<div class="container">
<img class="picture" src="https://imagej.nih.gov/ij/images/baboon.jpg">
<div class="desc"></div>
</div>
<div class="container">
<img class="picture" src="https://www.visioncritical.com/wp-content/uploads/2014/12/BLG_Andrew-G.-River-Sample_09.13.12.png">
<div class="desc"></div>
</div>
</div>
In this case, the description box goes downwards since I wasnt using position: absolute;. However if I do so, the box wont inherit the pictures size and takes the size of the page. How do I solve this?
FIDDLE
Set the position of container to relative so the description would be absolute in relation to it:
.container {
height: 100px;
width:100px;
display: inline-block;
position:relative;
}
.picture {
height: 100%;
width:100%
}
.contAlign {
text-align: center;
}
.desc {
position:absolute;
bottom: 0;
left: 0;
right: 0;
background-color: black;
width: 100%;
height: 0%;
opacity: 0.5;
transition: .5s ease;
}
.container:hover .desc {
height: 40%;
}
<div class="contAlign">
<div class="container">
<img class="picture" src="https://kbob.github.io/images/sample-3.jpg">
<div class="desc"></div>
</div>
<div class="container">
<img class="picture" src="https://imagej.nih.gov/ij/images/baboon.jpg">
<div class="desc"></div>
</div>
<div class="container">
<img class="picture" src="https://www.visioncritical.com/wp-content/uploads/2014/12/BLG_Andrew-G.-River-Sample_09.13.12.png">
<div class="desc"></div>
</div>
</div>
I hope this helps you out. once you make an element absolute, just make sure to make its parent relative. so that it doesn't float anywhere. Now you can set positions accordingly where you want to make it appear on hover.
.container {
height: 100px;
width:100px;
display: inline-block;
position: relative;
}
.picture {
height: 100%;
width:100%
}
.contAlign {
text-align: center;
}
.desc {
position:absolute;
bottom: 0;
left: 0;
right: 0;
background-color: black;
width: 100%;
height: 0%;
opacity: 0.5;
transition: .5s ease;
}
.container:hover .desc {
height: 40%;
}
<div class="contAlign">
<div class="container">
<img class="picture" src="https://kbob.github.io/images/sample-3.jpg">
<div class="desc"></div>
</div>
<div class="container">
<img class="picture" src="https://imagej.nih.gov/ij/images/baboon.jpg">
<div class="desc"></div>
</div>
<div class="container">
<img class="picture" src="https://www.visioncritical.com/wp-content/uploads/2014/12/BLG_Andrew-G.-River-Sample_09.13.12.png">
<div class="desc"></div>
</div>
</div>
Related
Hi I'm following a tutorial. As far as I can see I have written exactly the same thing in my code but it is behaving differently.
.container {
display: flex;
width: 90vw;
}
.panel {
background-size: auto 100%;
background-position: center;
background-repeat: no-repeat;
height: 80vh;
border-radius: 50px;
color: white;
cursor: pointer;
flex: 0.5;
margin: 10px;
position: relative;
transition: flex 0.7s ease-in;
}
.panel h3 {
font-size: 24px;
position: absolute;
bottom: 20px;
left: 20px;
margin: 0;
opacity: 0;
}
.panel.active {
flex: 5;
}
.panel.active h3 {
opacity: 1;
}
<body>
<div class="container">
<div class="panel active" style="background-image: url('./vincent-guth-uhoILl3HUZM-unsplash.jpg')">
<h3>Beautiful Sky</h3>
</div>
<div class="panel" style="background-image: url('./juskteez-vu-TIrXot28Znc-unsplash.jpg')">
<h3>Incredible sky</h3>
</div>
<div class="panel" style="background-image: url('./casey-horner-fsJB3KT2rj8-unsplash.jpg')">
<h3>Northern Lights</h3>
</div>
<div class="panel" style="background-image: url('./vincent-guth-uhoILl3HUZM-unsplash.jpg')">
<h3>Northern Lights</h3>
</div>
<div class="panel" style="background-image: url('./vincent-guth-uhoILl3HUZM-unsplash.jpg')">
<h3>Beautiful Sky</h3>
</div>
</div>
</div>
</body>
but on the screen the panel that's active loses all the css from the panel class instead of using both. Any ideas why this might be? Thanks!
Actually it works but the problem is you are using 100% size of your images so its looks like this:
I added border to demonstrate
.container {
display: flex;
width: 90vw;
}
.panel {
background-size: auto 100%;
background-position: center;
background-repeat: no-repeat;
height: 80vh;
border-radius: 50px;
color: white;
cursor: pointer;
flex: 0.5;
margin: 10px;
position: relative;
transition: flex 0.7s ease-in;
border: red 2px solid;
}
.panel h3 {
font-size: 24px;
position: absolute;
bottom: 20px;
left: 20px;
margin: 0;
opacity: 0;
}
.panel.active {
flex: 5;
}
.panel.active h3 {
opacity: 1;
}
<body>
<div class="container">
<div class="panel active" style="background-image: url('https://picsum.photos/id/266/200/300')">
<h3>Beautiful Sky</h3>
</div>
<div class="panel" style="background-image: url('https://picsum.photos/id/230/200/300')">
<h3>Incredible sky</h3>
</div>
<div class="panel" style="background-image: url('https://picsum.photos/id/217/200/300')">
<h3>Northern Lights</h3>
</div>
<div class="panel" style="background-image: url('https://picsum.photos/id/227/200/300')">
<h3>Northern Lights</h3>
</div>
<div class="panel" style="background-image: url('https://picsum.photos/id/137/200/300')">
<h3>Beautiful Sky</h3>
</div>
</div>
</body>
The solution is using background-size: cover; instead
.container {
display: flex;
width: 90vw;
}
.panel {
background-size: cover;
background-position: center;
background-repeat: no-repeat;
height: 80vh;
border-radius: 50px;
color: white;
cursor: pointer;
flex: 0.5;
margin: 10px;
position: relative;
transition: flex 0.7s ease-in;
border: red 2px solid;
}
.panel h3 {
font-size: 24px;
position: absolute;
bottom: 20px;
left: 20px;
margin: 0;
opacity: 0;
}
.panel.active {
flex: 5;
}
.panel.active h3 {
opacity: 1;
}
<body>
<div class="container">
<div class="panel active" style="background-image: url('https://picsum.photos/id/266/200/300')">
<h3>Beautiful Sky</h3>
</div>
<div class="panel" style="background-image: url('https://picsum.photos/id/230/200/300')">
<h3>Incredible sky</h3>
</div>
<div class="panel" style="background-image: url('https://picsum.photos/id/217/200/300')">
<h3>Northern Lights</h3>
</div>
<div class="panel" style="background-image: url('https://picsum.photos/id/227/200/300')">
<h3>Northern Lights</h3>
</div>
<div class="panel" style="background-image: url('https://picsum.photos/id/137/200/300')">
<h3>Beautiful Sky</h3>
</div>
</div>
</body>
Try to change value of background-size property to cover (background-size: cover). I think this is what you need
I ran your code in codepen. I only changed the background-images to colors since the were loaded locally. It is behaving as it should, the panel active div displaying everything defined in the panel class aswell. What are you missing?
https://codepen.io/wischn/pen/OJwOQxp
.container {
display: flex;
width: 90vw;
}
.panel {
background-size: auto 100%;
background-position: center;
background-repeat: no-repeat;
height: 80vh;
border-radius: 50px;
color: white;
cursor: pointer;
flex: 0.5;
margin: 10px;
position: relative;
transition: flex 0.7s ease-in;
}
.panel h3 {
font-size: 24px;
position: absolute;
bottom: 20px;
left: 20px;
margin: 0;
opacity: 0;
}
.panel.active {
flex: 5;
}
.panel.active h3 {
opacity: 1;
}
I've a problem about css because I'm not touching css for now,
I've an image like this with normal zoom (100%):
But the image's goes wrong when zooming in 150%:
Already tried to find any article on internet, still nothing,
can someone provide me an example how to make image goes static at triangle position?
the code i've used:
HTML
<div class="col-md-8 col-sm-8 col-xs-12 nopadding">
<div class="boxtriangle" style="width: 100%;">
<!--<img src="assets/images/bg-triangle.png" width="100%" height="100%" class="img-responsive" usemap="#umbrellamap" id="map_ID">-->
<img src="assets/images/bg-triangle-Copy.png" usemap="#umbrellamap" style="width:100%; margin:0 auto;">
<map name="umbrellamap" style="display:inline; width: 100%">
<!-- coords="x,y,width,heigth" -->
<area shape="circle" coords="146,317,62" href="health.html" alt="health"/>
<area shape="circle" coords="282,317,35" href="legacy.html" alt="legacy" />
<area shape="circle" coords="417,317,42" href="life.html" alt="life" />
<area shape="circle" coords="217,204,42" href="retirement.html" alt="retirement" />
<area shape="circle" coords="346,204,52" href="education.html" alt="education" />
<area shape="circle" coords="282,95,42" href="investment.html" alt="investment" />
</map>
<div class="boxcircle1" id="investment">
<div class="circle-all">
<div class="circle circle-2x">
<a href="investment.html">
<img src="assets/images/icon-invesment.png" class="img-responsive" style="width:85%; text-align:center; display:inline-block; position:relative; top:50%; transform:translateY(-50%)">
</a>
</div>
</div>
</div>
<div class="boxcircle2" id="retirement">
<div class="circle-all">
<div class="circle circle-2x">
<img src="assets/images/icon-retirement.png" class="img-responsive" style="width:85%; text-align:center; display:inline-block; position:relative; top:50%; transform:translateY(-50%)">
</div>
</div>
</div>
<div class="boxcircle3" id="education">
<div class="circle-all">
<div class="circle circle-2x">
<img src="assets/images/icon-education.png" class="img-responsive" style="width:85%; text-align:center; display:inline-block; position:relative; top:50%; transform:translateY(-50%)">
</div>
</div>
</div>
<div class="boxcircle4" id="health">
<div class="circle-all">
<div class="circle circle-2x">
<img src="assets/images/icon-health.png" class="img-responsive" style="width:85%; text-align:center; display:inline-block; position:relative; top:50%; transform:translateY(-50%)">
</div>
</div>
</div>
<div class="boxcircle5" id="legacy">
<div class="circle-all">
<div class="circle circle-2x">
<img src="assets/images/icon-legacy.png" class="img-responsive" style="width:85%; text-align:center; display:inline-block; position:relative; top:50%; transform:translateY(-50%)">
</div>
</div>
</div>
<div class="boxcircle6" id="life">
<div class="circle-all">
<div class="circle circle-2x">
<img src="assets/images/icon-life.png" class="img-responsive" style="width:85%; text-align:center; display:inline-block; position:relative; top:50%; transform:translateY(-50%)">
</div>
</div>
</div>
</div>
<div class="boxwordcontact" id="umbrellatrans19">But dont worry. we got it covered! contact us <div id="umbrellatrans21">for further information</div>
</div>
</div>
css of class
.boxcircle1 {
position: absolute; display: block; left: 31%; top: 9%;
}
.boxcircle2 {
position: absolute; display: block; left: 22%; top: 38%;
}
.boxcircle3 {
position: absolute; display: block; top: 38%; left: 40%;
}
.boxcircle4 {
position: absolute; display: block; top: 68%; left: 12%;
}
.boxcircle5 {
position: absolute; top: 68%; display: block; left: 31%;
}
.boxcircle6 {
position: absolute; display: block; top: 68%; left: 50%;
}
.circle {
border-radius: 50%;
display: inline-block;
background: #676664;
cursor: pointer;
position: relative;
top:50%;
transform: translateY(-50%);
transition:All 1s ease;
-webkit-transition:All 1s ease;
-moz-transition:All 1s ease;
-o-transition:All 1s ease;
}
.circle:hover {
background: #d0202b;
}
.circle:after {
content: '';
display: block ;
position: absolute ;
top: 0 ;
bottom: 0 ;
left: 0 ;
right: 0 ;
margin:-5px;
border-radius: 50%;
transition:All 1s ease;
-webkit-transition:All 1s ease;
-moz-transition:All 1s ease;
-o-transition:All 1s ease;
border: 1px solid #d0202b;
}
.circle:hover:after {
border: none;
}
.circle.active {
background: #d0202b;
}
.circle.done {
background: #6ca843;
}
.circle.done:hover:after {
border: 1px solid #6ca843;
}
.circle-1x {
height: 60px;
width: 60px;
text-align: center;
font-size:26px;
}
.circle-2x {
height: 75px;
width: 75px;
text-align: center;
font-size:32px;
}
.circle-3x {
height: 95px;
width: 95px;
text-align: center;
font-size:45px;
}
.circle-4x {
height: 115px;
width: 115px;
text-align: center;
font-size:54px;
}
Your circles have a fixed size, there is nothing that says, that they should resize according to their parent.
You need something like this on your base class (width is arbitrary):
.circle {
width: 100%;
height: auto;
}
read up here:
https://www.w3schools.com/css/css_rwd_images.asp
I'm trying to build a simple teaser grid for featured posts on a website using flexbox. It should look like this:
And in FF and Chrome it's all good. If i change the resolution of one image, all the others follow and update their size. But not in Safari. Whatever i do, it never fits to an equal height:
I really don't get the point why this is happening. Each image container on the right has exactly 50% of the height calculated by flexbox. And each image should be stretched to that height.
I could probably achieve this with background-size:cover but i would love to find a solution to use img tags instead.
Here's a demo: https://jsfiddle.net/7tjw8j83/1/
.featured-grid{
margin: 0;
padding: 0;
display: flex;
flex-wrap: wrap;
}
img{
width: 100%;
height: 100%;
display: block;
object-fit:cover;
}
.left{
width: 66.6666%;
}
.right{
width: 33.3333%;
display: flex;
flex-direction: column;
}
.right-top{
background: green;
flex: 1;
}
.right-bottom{
background: red;
flex: 1;
}
<div class="featured-grid">
<div class="left">
<img src="https://unsplash.it/600/450?image=1055">
</div>
<div class="right">
<div class="right-top">
<img src="https://unsplash.it/600/400?image=1051">
</div>
<div class="right-bottom">
<img src="https://unsplash.it/600/400?image=1057">
</div>
</div>
</div>
In addition to Michaels suggestion, you could do like this, where I used background-image instead of img (since you use a given height anyway), and how to add text at an absolute position
html, body {
margin: 0;
}
.featured-grid{
display: flex;
height: 100vh;
}
div {
position: relative;
background-position: center;
background-repeat: no-reapat;
background-size: cover;
overflow: hidden;
}
.left {
width: 66.666%;
}
.right{
width: 33.333%;
display: flex;
flex-direction: column;
}
.right-top{
flex: 1;
}
.right-bottom{
flex: 1;
}
.text {
position: absolute;
left: 10px;
bottom: 10px;
color: white;
}
.text > * {
margin: 5px;
}
<div class="featured-grid">
<div class="left" style="background-image: url(https://unsplash.it/600/450?image=1055)">
<div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
<div class="right">
<div class="right-top" style="background-image: url(https://unsplash.it/600/400?image=1051)">
<div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
<div class="right-bottom" style="background-image: url(https://unsplash.it/600/400?image=1057)">
<div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
</div>
</div>
Updated based on a comment
html, body {
margin: 0;
}
.featured-grid{
display: flex;
height: 100vh;
}
div {
position: relative;
overflow: hidden;
}
img{
width: 100%;
height: 100%;
display: block;
object-fit:cover;
}
.left {
width: 66.666%;
}
.right{
width: 33.333%;
display: flex;
flex-direction: column;
}
.right-top{
flex: 1;
}
.right-bottom{
flex: 1;
}
.text {
position: absolute;
left: 10px;
bottom: 10px;
color: white;
}
.text > * {
margin: 5px;
}
<div class="featured-grid">
<div class="left">
<img src="https://unsplash.it/600/450?image=1055">
<div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
<div class="right">
<div class="right-top">
<img src="https://unsplash.it/600/400?image=1051">
<div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
<div class="right-bottom">
<img src="https://unsplash.it/600/400?image=1057"> <div class="text">
<h2>Title</h2>
<h3>Text</h3>
</div>
</div>
</div>
</div>
Updated (2:nd) based on a comment
html,
body {
margin: 0;
}
.featured-grid {
display: flex;
}
div {
position: relative;
overflow: hidden;
}
img {
visibility: hidden;
display: block;
}
img.show {
position: absolute;
visibility: visible;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: block;
object-fit: cover;
}
.left img {
max-height: 100vh;
}
.right img {
max-height: 50vh;
}
.left {
width: 66.666%;
}
.right {
width: 33.333%;
display: flex;
flex-direction: column;
}
.right-top {
flex: 1;
}
.right-bottom {
flex: 1;
}
.text {
position: absolute;
left: 10px;
bottom: 10px;
color: white;
}
.text > * {
margin: 5px;
}
<div class="featured-grid">
<div class="left">
<img src="https://unsplash.it/300/250?image=1055">
<img class="show" src="https://unsplash.it/300/250?image=1055">
<div class="text">
<h2>Title 1</h2>
<h3>Text 1</h3>
</div>
</div>
<div class="right">
<div class="right-top">
<img src="https://unsplash.it/300/200?image=1057">
<img class="show" src="https://unsplash.it/300/200?image=1057">
<div class="text">
<h2>Title 2</h2>
<h3>Text 2</h3>
</div>
</div>
<div class="right-bottom">
<img src="https://unsplash.it/300/200?image=1057">
<img class="show" src="https://unsplash.it/300/200?image=1057">
<div class="text">
<h2>Title 3</h2>
<h3>Text 3</h3>
</div>
</div>
</div>
</div>
I want to make simple photo gallery with 3 images in a row,
and when i add width: 33%; the width doesn't apply to layout class.
Can anyone suggest, how can i make it to display it correctly?
Example: https://jsfiddle.net/kani339/ed7g6hjp/
HTML:
<section>
<div class="photo-gallery">
<div class="layout">
<div class="img-block">
<img src="download.jpg" alt="">
</div>
</div>
</div>
</section>
CSS:
.layout {
background: red;
opacity: 1;
height: 250px;
width: 33%;
float: left;
}
.img-block img {
height: 250px;
width: 33%;
float: left;
}
.img-block img:hover{
opacity: 0.5;
cursor:pointer;
}
Your 33% impacts the image not the layout.
Something like this maybe?
.layout {
background: red;
opacity: 1;
height: 250px;
width: 100%;
/* width: 350px; */
float: left;
}
.img-block img {
height: 250px;
width: 33%;
float: left;
}
.img-block img:hover {
opacity: 0.5;
cursor: pointer;
}
<section>
<div class="photo-gallery">
<div class="layout">
<div class="img-block">
<img src="http://hdwpro.com/wp-content/uploads/2015/12/Widescreen-Image-1366x768.jpg" alt="">
<img src="http://hdwpro.com/wp-content/uploads/2015/12/Widescreen-Image-1366x768.jpg" alt="">
<img src="http://hdwpro.com/wp-content/uploads/2015/12/Widescreen-Image-1366x768.jpg" alt="">
</div>
</div>
</div>
</section>
I need some advice on this issue i'm having. In the jsfiddle below, I'm trying to create a responsive grid layout. The issue with what i have is, i would like the text to be in the middle of each individual grid. I've tried bumping it using margin-top but instead of the images stacking onto each other while resizing, the images are overlapping each other. The end result desired will be to have the text aligned center onto the image and have no gaps on all sides of the grid when resizing according to various screen resolution.
Link: http://jsfiddle.net/kelvinchow/VaDS9/
<style type="text/css">
#wrapper {
display: block;
width: 100%;
height: auto;
background: green;
}
.box {
display: inline-block;
float: left;
width: 50%;
height: auto;
vertical-align: baseline;
background: red;
}
.box-img img {
width: 100% !important;
height: auto;
}
.box-title {
display: block;
background: grey;
height: 25px;
font-size: 20px;
font-family: helvetica, san serif;
color: blue;
text-align: center;
margin-top: -100px;
}
</style>
<div id="wrapper">
<div class="box">
<div class="box-img">
<img src="http://airinlee.com/wp-content/uploads/2013/06/thumbnail6.png">
</div>
<p class="box-title">howdy</p>
</div>
<div class="box">
<div class="box-img">
<img src="http://airinlee.com/wp-content/uploads/2013/06/thumbnail6.png">
</div>
<p class="box-title">howdy</p>
</div>
<div class="box">
<div class="box-img">
<img src="http://airinlee.com/wp-content/uploads/2013/06/thumbnail6.png">
</div>
<p class="box-title">howdy</p>
</div>
<div class="box">
<div class="box-img">
<img src="http://airinlee.com/wp-content/uploads/2013/06/thumbnail6.png">
</div>
<p class="box-title">howdy</p>
</div>
</div>
You'll get this:
Fiddle here: http://jsbin.com/osazav/1.
With this markup:
<body>
<div id="tl" class="box">
<p class="box-title">howdy</p>
</div>
<div id="tr" class="box">
<p class="box-title">howdy</p>
</div>
<div id="bl" class="box">
<p class="box-title">howdy</p>
</div>
<div id="br" class="box">
<p class="box-title">howdy</p>
</div>
</body>
And this css:
div.box {
background: url('http://airinlee.com/wp-content/uploads/2013/06/thumbnail6.png');
position: absolute;
height: 50%;
width: 50%;
background-size: cover;
background-position: center;
}
div.box p.box-title {
color: red;
background-color: black;
padding: 5px;
position: absolute;
margin: -10px -20px;
top: 50%;
left: 50%;
}
div.box#tl { top: 0%; left: 0%; }
div.box#tr { top: 0%; left: 50%; }
div.box#bl { top: 50%; left: 0%; }
div.box#br { top: 50%; left: 50%; }