I have just started to learn about coding in school, and I'm trying to make a simple project.
I have created a flip card consisting of the Finnish flag and an image. The problem is that when I hover over the flag and it flips, half the picture doesn't show.
.wallpaper {
background: green;
height: 2000px;
width: 1920px;
position: absolute;
}
.flag {
height: 310px;
width: 550px;
background: white;
position: relative;
}
.horizontal {
position: relative;
background: rgba(0, 54, 128, 255);
height: 75px;
top: 40%;
}
.vertical {
position: relative;
top: -75px;
bottom: 0;
left: -75px;
right: 0;
margin: auto;
background: rgba(0, 54, 128, 255);
height: 310px;
width: 75px;
}
.vodka {
height: 200px;
width: 200px;
}
img {
position: relative;
top: 900px;
bottom: 0;
left: 525px;
right: 0;
width: 350px;
height: 250px;
}
.text {
position: absolute;
left: 450px;
top: 100px;
}
.mannen {
color: white;
position: relative;
top: 200px;
left: 75px;
}
.myten {
color: rgba(0, 54, 128, 255);
position: relative;
top: 200px;
left: 200px;
}
.legenden {
color: white;
position: relative;
left: 300px;
top: 200px;
}
.container {
background: rgba(0, 54, 128, 255);
position: fixed;
height: 100px;
width: 1920px;
top: 0;
}
.mikko {
color: white;
position: relative;
left: 800px;
}
.group {
position: relative;
left: 250px;
}
.flip-card {
background: transparent;
width: 550px;
height: 310px;
perspective: 1000px;
position: absolute;
top: 500px;
left: 450px;
}
.flip-card-inner {
position: relative;
width: 100%;
height: 100%;
transition: transform 0.8s;
transform-style: preserve-3d;
}
.flip-card:hover .flip-card-inner {
transform: rotateY(180deg);
}
.flip-card-front,
.flip-card-back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
.image {
position: relative;
top: -900px;
left: 525px;
transform: scale(-1, 1);
z-index: -1;
}
<div class="wallpaper">
<div class="group">
<div class="text">
<h1 style="font-family: Verdana">
<div class="mannen">Mannen,</div>
<div class="myten">myten,</div>
<div class="legenden">legenden!</div>
</h1>
</div>
<div class="vodka">
<img src="https://folkofolk.se/sites/default/files/styles/article_large/public/2016-02/Finlandia_0.jpg.jpeg?itok=2vkru5VU" />
</div>
<div class="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front">
<div class="flag">
<div class="horizontal"></div>
<div class="vertical"></div>
</div>
</div>
<div="flip-card-back">
<div class="image">
<img src="https://primatelounge.se/wp-content/uploads/2017/03/mikko-tahtinen-500x748.jpg" style="width:550px;height:310px;" />
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="mikko">
<h1 style="font-family: Verdana">Mikko Tähtinen</h1>
</div>
</div>
</div>
Removed some of the top/left properties of the person image and added
height: 310px;
width: 550px;
object-fit: cover;
to the .image class and some minor changes .
Style according to need and it is advised not to use such a positioning using all from top/bottom as these will be hard to debug and know the behavior
.wallpaper {
background: green;
height: 2000px;
width: 1920px;
position: absolute;
}
.flag {
height: 310px;
width: 550px;
background: white;
position: relative;
}
.horizontal {
position: relative;
background: rgba(0, 54, 128, 255);
height: 75px;
top: 40%;
}
.vertical {
position: relative;
top: -75px;
bottom: 0;
left: -75px;
right: 0;
margin: auto;
background: rgba(0, 54, 128, 255);
height: 310px;
width: 75px;
}
.vodka {
height: 200px;
width: 200px;
}
img {
position: relative;
bottom: 0;
right: 0;
}
.text {
position: absolute;
left: 450px;
top: 100px;
}
.mannen {
color: white;
position: relative;
top: 200px;
left: 75px;
}
.myten {
color: rgba(0, 54, 128, 255);
position: relative;
top: 200px;
left: 200px;
}
.legenden {
color: white;
position: relative;
left: 300px;
top: 200px;
}
.container {
background: rgba(0, 54, 128, 255);
position: fixed;
height: 100px;
width: 1920px;
top: 0;
}
.mikko {
color: white;
position: relative;
left: 800px;
}
.group {
position: relative;
left: 250px;
}
.flip-card {
background: transparent;
width: 550px;
height: 310px;
perspective: 1000px;
position: absolute;
top: 500px;
left: 450px;
}
.flip-card-inner {
position: relative;
width: 100%;
height: 100%;
transition: transform 0.8s;
transform-style: preserve-3d;
}
.flip-card:hover .flip-card-inner {
transform: rotateY(180deg);
}
.flip-card-front,
.flip-card-back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
.image {
height: 310px;
width: 550px;
object-fit: cover;
position: relative;
transform: scale(-1, 1);
z-index: -1;
}
<div class="wallpaper">
<div class="group">
<div class="text">
<h1 style="font-family: Verdana">
<div class="mannen">Mannen,</div>
<div class="myten">myten,</div>
<div class="legenden">legenden!</div>
</h1>
</div>
<div class="vodka">
<img src="https://folkofolk.se/sites/default/files/styles/article_large/public/2016-02/Finlandia_0.jpg.jpeg?itok=2vkru5VU" style="width:550px;height:310px;" />
</div>
<div class="flip-card">
<div class="flip-card-inner">
<div class="flip-card-front">
<div class="flag">
<div class="horizontal"></div>
<div class="vertical"></div>
</div>
</div>
<div="flip-card-back">
<div class="image">
<img src="https://primatelounge.se/wp-content/uploads/2017/03/mikko-tahtinen-500x748.jpg" style="width:550px;height:310px;" />
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="mikko">
<h1 style="font-family: Verdana">Mikko Tähtinen</h1>
</div>
</div>
</div>
Simple image flip from above :
.flag {
height: 310px;
width: 550px;
background: white;
position: relative;
margin: 20px;
}
.horizontal {
position: relative;
background: rgba(0, 54, 128, 255);
height: 75px;
top: 40%;
}
.vertical {
position: relative;
top: -75px;
left: -75px;
margin: auto;
background: rgba(0, 54, 128, 255);
height: 310px;
width: 75px;
}
.flipImage1 {
position: absolute;
top: 0;
left: 0;
background-color:white;
z-index: -10;
transform: rotateY(180deg);
}
.flag:hover {
transform: rotateY(180deg);
transform-style: preserve-3d;
}
<div class="flag">
<div class="horizontal"></div>
<div class="vertical"></div>
<img src="https://primatelounge.se/wp-content/uploads/2017/03/mikko-tahtinen-500x748.jpg" style="width:550px;height:310px;" class="flipImage1" />
</div>
Ok first, good on you for learning code.
second, this might be counter intuitive but you shouldn't be using position absolute and transform translate for this much positioning you should try using display flex or grid,
also the problem is that chrome seems to be having problems with z-index: -1 from that .image.
an easier way to do this is to use transition-delay on the image instead of having the image perspective change
Related
I was trying to participate in a CSS challenge when this occurred. Everything seems working as expected, however when clicking on the plus circle to display div#card the div.container loses it's top margin and I cannot understand why. Please if anyone can help me with this, I'd be really grateful - And maybe we can all learn from it ;)
Thanks!
Codepen: https://codepen.io/albertrf147/pen/LMKKeK
HTML
html,
body {
width: 100%;
height: 100%;
}
body {
margin: 0px;
overflow: hidden;
background: lightblue;
}
.container {
width: 400px;
height: 400px;
margin: 20px auto !important;
position: relative;
display: flex;
flex-wrap: wrap;
background: white;
padding: 2px;
}
.square {
box-sizing: border-box;
padding: 2px;
width: 50%;
height: 50%;
position: relative;
background: white;
}
.square>img {
height: 100%;
width: 100%;
object-fit: cover;
display: block;
margin: auto;
}
.onhover {
box-sizing: border-box;
width: 100%;
height: 100%;
position: absolute;
cursor: pointer;
transition: all .6s ease-in-out;
}
.onhover:hover {
background: rgba(0, 0, 0, 0.5);
}
.circle-aux {
position: relative;
width: 100%;
height: 100%;
transition: all .6s ease-in-out;
}
.circle-aux:hover .circle {
visibility: visible;
opacity: 1;
transform: scale(0.2);
transition: all .6s ease-in-out;
}
.circle {
visibility: hidden;
opacity: 0;
position: absolute;
border-radius: 50%;
width: 100%;
height: 100%;
background: salmon;
}
.circle:before {
content: "";
background: white;
height: 50%;
width: 6px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.circle:after {
content: "";
background: white;
height: 6px;
width: 50%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.container-card {
visibility: hidden;
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
}
.container-card>img {
width: 100%;
height: 60%;
object-fit: cover;
}
.container-card:target {
visibility: visible;
}
.avatar {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 50%;
box-shadow: 0px 0px 20px black;
width: 25%;
height: 25%;
background: white;
z-index: 2;
text-align: center;
font-family: calibri;
font-weight: bold;
color: white;
font-size: 18px;
}
.avatar>img {
box-sizing: border-box;
width: 100%;
height: 100%;
object-fit: cover;
border-radius: inherit;
padding: 4px;
}
.mini-circle {
display: inline-block;
width: 15%;
height: 15%;
border: 1px solid white;
border-radius: 50%;
margin-top: 12px;
}
.mini-circle:hover {
background: white;
cursor: pointer;
}
footer {
box-sizing: border-box;
position: absolute;
bottom: 0;
left: 0;
background: salmon;
height: 50%;
width: 100%;
z-index: 1;
padding: 2px;
}
.close {
position: absolute;
border-radius: 50%;
width: 8%;
height: 8%;
background: black;
transform: rotate(45deg);
right: 10px;
top: 10px;
cursor: pointer;
}
.close:before {
content: "";
background: white;
height: 60%;
width: 2px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.close:after {
content: "";
background: white;
height: 2px;
width: 60%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<main>
<div class="container">
<div class="square">
<div class="onhover">
<div class="circle-aux">
<a class="circle" href="#card"></a>
</div>
</div>
<img src="https://images.pexels.com/photos/305241/pexels-photo-305241.jpeg?auto=compress&cs=tinysrgb&h=650&w=940" />
</div>
<div class="square">
<div class="onhover">
<div class="circle-aux">
<div class="circle"></div>
</div>
</div>
<img src="https://images.pexels.com/photos/1546711/pexels-photo-1546711.jpeg?auto=compress&cs=tinysrgb&h=650&w=940" />
</div>
<div class="square">
<div class="onhover">
<div class="circle-aux">
<div class="circle"></div>
</div>
</div>
<img src="https://images.pexels.com/photos/1800433/pexels-photo-1800433.jpeg?auto=compress&cs=tinysrgb&h=650&w=940" />
</div>
<div class="square">
<div class="onhover">
<div class="circle-aux">
<div class="circle"></div>
</div>
</div>
<img src="https://images.pexels.com/photos/1757111/pexels-photo-1757111.jpeg?auto=compress&cs=tinysrgb&h=650&w=940" />
</div>
<div id="card" class="container-card">
<a class="close" href="#"></a>
<img src="https://images.pexels.com/photos/1769331/pexels-photo-1769331.jpeg?auto=compress&cs=tinysrgb&h=650&w=940" />
<div class="avatar">
<img src="https://images.pexels.com/photos/769772/pexels-photo-769772.jpeg?auto=compress&cs=tinysrgb&h=650&w=940" />
<span>David Craig</span>
<span>
<div class="mini-circle"></div>
<div class="mini-circle"></div>
<div class="mini-circle"></div>
</span>
</div>
<footer></footer>
</div>
</div>
</main>
Welcome to SO!
As the appearing container is position: absolute no margin takes effect.
You need to work with the top attribute to place it properly.
Check this out: https://codepen.io/anon/pen/pGzVyL
For more informations click here: https://www.w3schools.com/css/css_positioning.asp
I have a cloud made with HTML/CSS and I'm trying to include some text in the center of it. But I'm having trouble positioning it and having it overlap over the cloud divs.
#cloud {
height: 230px;
margin: 40px;
position: relative;
width: 400px;
}
#cloud div {
border: solid 5px black;
}
#bottom_c {
background-color: #fff;
border-radius: 100px;
height: 150px;
position: absolute;
top: 100px;
width: 350px;
z-index: 0;
}
#right_c{
background-color: #fff;
border-radius: 100%;
height: 150px;
left: 140px;
position: absolute;
top: 40px;
width: 150px;
z-index: -1;
}
#left_c{
background-color: #fff;
border-radius: 100%;
height: 100px;
left: 50px;
position: absolute;
top: 70px;
width: 100px;
z-index: -1;
}
#cloud::before {
background-color: white;
border-radius: 50%;
content: '';
height: 100px;
left: 55px;
position: absolute;
top: 75px;
width: 100px;
z-index: 1;
}
#cloud::after {
position: absolute; top: 45px; left: 145px;
background-color: white;
border-radius: 50%;
content: '';
width: 150px;
height: 150px;
z-index: 1;
}
.text {
overflow: hidden;
position: absolute;
z-index: -2;
}
<div id="cloud">
<div id="bottom_c"></div>
<div id="right_c">
<p class="text">
this is some text
</p>
</div>
<div id="left_c">
</div>
</div>
Not entirely sure how to make it work, I thought the z-index would allow the text to take "priority" and show first, but it doesn't seem to be working. Do I need to insert the p tags inside another div? Any suggestions would be appreciated!
Remove the text element from its current nesting level. Just make it a sibling of the border divs. Still one overall container.
#cloud {
height: 230px;
margin: 40px;
position: relative;
width: 400px;
}
#cloud div {
border: solid 5px black;
}
#bottom_c {
background-color: #fff;
border-radius: 100px;
height: 150px;
position: absolute;
top: 100px;
width: 350px;
z-index: 0;
}
#right_c{
background-color: #fff;
border-radius: 100%;
height: 150px;
left: 140px;
position: absolute;
top: 40px;
width: 150px;
z-index: -1;
}
#left_c{
background-color: #fff;
border-radius: 100%;
height: 100px;
left: 50px;
position: absolute;
top: 70px;
width: 100px;
z-index: -1;
}
#cloud::before {
background-color: white;
border-radius: 50%;
content: '';
height: 100px;
left: 55px;
position: absolute;
top: 75px;
width: 100px;
z-index: 1;
}
#cloud::after {
position: absolute; top: 45px; left: 145px;
background-color: white;
border-radius: 50%;
content: '';
width: 150px;
height: 150px;
z-index: 1;
}
.text {
position: absolute;
top: 40px;
left: 135px;
z-index: 2;
}
<div id="cloud">
<div id="bottom_c"></div>
<div id="right_c"></div>
<div id="left_c"></div>
<p class="text">this is some text</p>
</div>
If you change your html to:
<div id="cloud">
<div id="bottom_c"></div>
<div id="right_c"></div>
<div id="left_c"></div>
</div>
<p class="text">
this is some text
</p>
and the text element in css to:
.text {
overflow: hidden;
position: absolute;
z-index: 2;
top:200px;
right:200px;
}
then it works.
so I have this code:
.background-image {
height: 700px;
width: 100%;
background: red;
}
.top {
margin-top: -85px;
position: relative;
height: 700px;
}
.top .circle {
width: 100%;
height: 700px;
overflow: hidden;
position: absolute;
top: 0;
left: 0;
margin: 0 auto;
z-index: 1;
}
.top .circle:before {
content: '';
position: absolute;
width: 200px;
height: 200px;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
border-radius: 50%;
box-shadow: 0px 0px 0px 9999px rgba(43, 54, 69, 0.75);
z-index: -1;
}
<div class="top">
<div class="background-image"></div>
<div class="circle"></div>
</div>
The result is overlay over the red background, with circle cut out in the middle of that. You can see results here: https://jsfiddle.net/erLqg448/
That code works great in Firefox and Chrome but in safari, that whole overlay seems to be missing. Any ideas?
Apparently safari has a problem with such a large value of spread-radius. But if you use a smaller value, like 99em it should cover your viewport and still render properly. Take a look at above snippet and updated jsFiddle
.background-image {
height: 700px;
width: 100%;
background: red;
}
.top {
margin-top: -85px;
position: relative;
height: 700px;
}
.top .circle {
width: 100%;
height: 700px;
overflow: hidden;
position: absolute;
top: 0;
left: 0;
margin: 0 auto;
z-index: 1;
}
.top .circle:before {
content: '';
position: absolute;
width: 200px;
height: 200px;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -100px;
border-radius: 50%;
box-shadow: 0px 0px 0px 99em rgba(43, 54, 69, 0.75);
z-index: -1;
}
<div class="top">
<div class="background-image"></div>
<div class="circle"></div>
</div>
I'm new in HTML, CSS. Also I'm still learn so please be understanding.
I'm trying to do some kind of art gallery which will be looks like this:
I create this squares with help of tutorial, but I want to upgrade thisand put an image instead squares, but I have no idea how to do this. Any tips ?
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background-color: #99CCFF;
}
.container {
max-width: 1070px;
padding: 0 30px;
margin: 0 auto;
}
.diamond {
width: 11.5%;
padding-bottom: 11.5%;
background-color: rgba(255, 255, 255, 0.3);
display: inline-block;
}
.diamond-big {
width: 25%;
padding-bottom: 25%;
background-color: rgba(255, 255, 255, 0.6);
display: inline-block;
}
.grid {
position: relative;
padding-bottom: 100%;
transform: rotate(45deg);
transform-origin: 39%;
}
.grid-section {
overflow: hidden;
padding-bottom: 200px;
}
#diamond1 {
position: absolute;
top: 25%;
left: 10.5%;
cursor: pointer;
}
#diamond2 {
position: absolute;
top: 25%;
left: 24%;
}
#diamond3 {
position: absolute;
top: 11.5%;
left: 37.5%;
}
#diamond4 {
position: absolute;
top: 38.5%;
left: 24%;
}
#diamond5 {
position: absolute;
top: 38.5%;
left: 51%;
}
#diamond6 {
position: absolute;
top: 52%;
left: 51%;
}
#diamond7 {
position: absolute;
top: 38.5%;
left: 64.5%;
}
#diamond8 {
position: absolute;
top: 65.5%;
left: 51%;
}
#diamond9 {
position: absolute;
top: 65.5%;
left: 64.5%;
}
<div class="container">
<section class="grid-section">
<div class="grid">
<div id="diamond1" class="diamond"></div>
<div id="diamond2" class="diamond"></div>
<div id="diamond3" class="diamond-big"></div>
<div id="diamond4" class="diamond-big"></div>
<div id="diamond5" class="diamond"></div>
<div id="diamond6" class="diamond"></div>
<div id="diamond7" class="diamond-big"></div>
<div id="diamond8" class="diamond"></div>
<div id="diamond9" class="diamond-big"></div>
</div>
</section>
</div>
If you want to make the images easy downloadable or don't want to use background-image in css, you can do something like this. I've added images inside the divs and added the following css:
.diamond {
width: 11.5%;
padding-bottom: 11.5%;
background-color: rgba(255, 255, 255, 0.3);
display: inline-block;
position:relative;
overflow:hidden;
}
.diamond img, .diamond-big img
{ position:absolute;
left:-25%;
top:-25%;
width:150%;
-ms-transform: rotate(-45deg); /* IE 9 */
-webkit-transform: rotate(-45deg); /* Chrome, Safari, Opera */
transform: rotate(-45deg);
}
.diamond-big {
width: 25%;
padding-bottom: 25%;
background-color: rgba(255, 255, 255, 0.6);
display: inline-block;
position:relative;
overflow:hidden;
}
this makes the images as large as the squares.
Full code snippet:
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background-color: #99CCFF;
}
.container {
max-width: 1070px;
padding: 0 30px;
margin: 0 auto;
}
.diamond {
width: 11.5%;
padding-bottom: 11.5%;
background-color: rgba(255, 255, 255, 0.3);
display: inline-block;
position:relative;
overflow:hidden;
}
.diamond img, .diamond-big img
{ position:absolute;
left:-25%;
top:-25%;
width:150%;
-ms-transform: rotate(-45deg); /* IE 9 */
-webkit-transform: rotate(-45deg); /* Chrome, Safari, Opera */
transform: rotate(-45deg);
}
.diamond-big {
width: 25%;
padding-bottom: 25%;
background-color: rgba(255, 255, 255, 0.6);
display: inline-block;
position:relative;
overflow:hidden;
}
.grid {
position: relative;
padding-bottom: 100%;
transform: rotate(45deg);
transform-origin: 39%;
}
.grid-section {
overflow: hidden;
padding-bottom: 200px;
}
#diamond1 {
position: absolute;
top: 25%;
left: 10.5%;
cursor: pointer;
}
#diamond2 {
position: absolute;
top: 25%;
left: 24%;
}
#diamond3 {
position: absolute;
top: 11.5%;
left: 37.5%;
}
#diamond4 {
position: absolute;
top: 38.5%;
left: 24%;
}
#diamond5 {
position: absolute;
top: 38.5%;
left: 51%;
}
#diamond6 {
position: absolute;
top: 52%;
left: 51%;
}
#diamond7 {
position: absolute;
top: 38.5%;
left: 64.5%;
}
#diamond8 {
position: absolute;
top: 65.5%;
left: 51%;
}
#diamond9 {
position: absolute;
top: 65.5%;
left: 64.5%;
}
<div class="container">
<section class="grid-section">
<div class="grid">
<div id="diamond1" class="diamond"><img src="http://placehold.it/400x400" alt="alter"/></div>
<div id="diamond2" class="diamond"><img src="http://placehold.it/400x400" alt="alter"/></div>
<div id="diamond3" class="diamond-big"><img src="http://placehold.it/400x400" alt="alter"/></div>
<div id="diamond4" class="diamond-big"><img src="http://placehold.it/400x400" alt="alter"/></div>
<div id="diamond5" class="diamond"><img src="http://placehold.it/400x400" alt="alter"/></div>
<div id="diamond6" class="diamond"><img src="http://placehold.it/400x400" alt="alter"/></div>
<div id="diamond7" class="diamond-big"><img src="http://placehold.it/400x400" alt="alter"/></div>
<div id="diamond8" class="diamond"><img src="http://placehold.it/400x400" alt="alter"/></div>
<div id="diamond9" class="diamond-big"><img src="http://placehold.it/400x400" alt="alter"/></div>
</div>
</section>
</div>
Try to add the property background-image to the diamond and diamond-big classes. For example:
.diamond {
width: 11.5%;
padding-bottom: 11.5%;
background-image: url("image.jpg");
background-color: rgba(255, 255, 255, 0.3);
display: inline-block;
}
If you don't see the image anyway, try to add height property too.
There are many ways to do this
One of the quickest is to swap out the <div> tags with <img> tags while keeping the class and id attributes
in your case you need to adjust some of you CSS to avoid unnecessary padding
here's a working example: (needs polishing)
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background-color: #99CCFF;
}
.container {
max-width: 1070px;
padding: 0 30px;
margin: 0 auto;
}
.diamond {
width: 11.5%;
padding: 0 auto;
background-color: rgba(255, 255, 255, 0.3);
display: inline-block;
}
.diamond-big {
width: 25%;
padding: 0 auto;
background-color: rgba(255, 255, 255, 0.6);
display: inline-block;
}
.grid {
position: relative;
padding-bottom: 100%;
transform: rotate(45deg);
transform-origin: 39%;
}
.grid-section {
overflow: hidden;
padding-bottom: 200px;
}
#diamond1 {
position: absolute;
top: 25%;
left: 10.5%;
cursor: pointer;
}
#diamond2 {
position: absolute;
top: 25%;
left: 24%;
}
#diamond3 {
position: absolute;
top: 11.5%;
left: 37.5%;
}
#diamond4 {
position: absolute;
top: 38.5%;
left: 24%;
}
#diamond5 {
position: absolute;
top: 38.5%;
left: 51%;
}
#diamond6 {
position: absolute;
top: 52%;
left: 51%;
}
#diamond7 {
position: absolute;
top: 38.5%;
left: 64.5%;
}
#diamond8 {
position: absolute;
top: 65.5%;
left: 51%;
}
#diamond9 {
position: absolute;
top: 65.5%;
left: 64.5%;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Pokręcone Gridy</title>
<link rel="stylesheet" type="text/css" href="css/main.css">
<script type="text/javascript" src="js/alert.js"></script>
</head>
<body>
<div class="container">
<section class="grid-section">
<div class="grid">
<img id="diamond1" src="http://images.fineartamerica.com/images-medium-large-5/blink-cat-square-art-michelle-wrighton.jpg" class="diamond">
<img id="diamond2" src="http://vastrevets.com/wp-content/uploads/2014/01/Cat-square-1-300x258.jpg" class="diamond">
<img id="diamond3" src="http://www.summitmobilevet.com/wp-content/uploads/2015/04/cat-square.jpg" class="diamond-big">
<img id="diamond4" src="http://1.bp.blogspot.com/-gMWmYwKZYZk/TvZFNMxEE0I/AAAAAAAAB1Q/Ka6cF95MCVA/s1600/mousecattoy1square.jpg" class="diamond-big">
<img id="diamond5" src="https://ae01.alicdn.com/kf/HTB13WWmIpXXXXbEXpXXq6xXFXXXy/DIY-Diamond-embroidery-font-b-Small-b-font-font-b-cat-b-font-square-drill-paste.jpg" class="diamond">
<img id="diamond6" src="http://fineartamerica.com/images/artworkimages/medium/1/orange-tabby-cat--square-jai-johnson.jpg" class="diamond">
<img id="diamond7" src="https://ae01.alicdn.com/kf/HTB1C339KVXXXXaGXpXXq6xXFXXX8/Needlework-Diamond-Embroidery-Home-Decoration-Diamond-Painting-Cross-Stitch-font-b-Laughing-b-font-Cat-Square.jpg" class="diamond-big">
<img id="diamond8" src="https://ae01.alicdn.com/kf/HTB1UsFCKpXXXXXPXXXXq6xXFXXXh/Diamond-embroidery-Three-font-b-small-b-font-font-b-cats-b-font-square-drill-paste.jpg" class="diamond">
<img id="diamond9" src="http://www.dhresource.com/0x0s/f2-albu-g1-M00-CD-F9-rBVaGVVN8-mAa_kSAACnesiYQsA716.jpg/diy-square-diamond-painting-cat-cartoon-animal.jpg" class="diamond-big">
</div>
</section>
</div>
</body>
</html>
The way I see it, you have two options:
Option 1: HTML and CSS (max-width)
You can just simply insert the img inside your div and set the max-width to 100%, like:
<div id="diamond2" class="diamond">
<img style="max-width: 100%" src="yourpicture.jpg">
</div>
If you do this, you have to make sure the divs are set to the right size for the picture (or at least the proportions), and use the max-width attribute.
Option 2: Using CSS
Set them as background on your CSS and use the right type of background-size (cover or contain):
#diamond6 {
background-image: url('yourpicture.jpg');
background-size: cover;
position: absolute;
top: 52%;
left: 51%;
}
I hope it helps!
Use background-image with background-size like
background-image: url('http://placehold.it/100');
background-size: 100% 100%;
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background-color: #99CCFF;
}
.container {
max-width: 1070px;
padding: 0 30px;
margin: 0 auto;
}
.diamond {
width: 11.5%;
padding-bottom: 11.5%;
background-color: rgba(255, 255, 255, 0.3);
display: inline-block;
background-image: url('http://placehold.it/100');
background-size: 100% 100%;
}
.diamond-big {
width: 25%;
padding-bottom: 25%;
background-color: rgba(255, 255, 255, 0.6);
display: inline-block;
}
.grid {
position: relative;
padding-bottom: 100%;
transform: rotate(45deg);
transform-origin: 39%;
}
.grid-section {
overflow: hidden;
padding-bottom: 200px;
}
#diamond1 {
position: absolute;
top: 25%;
left: 10.5%;
cursor: pointer;
}
#diamond2 {
position: absolute;
top: 25%;
left: 24%;
}
#diamond3 {
position: absolute;
top: 11.5%;
left: 37.5%;
}
#diamond4 {
position: absolute;
top: 38.5%;
left: 24%;
}
#diamond5 {
position: absolute;
top: 38.5%;
left: 51%;
}
#diamond6 {
position: absolute;
top: 52%;
left: 51%;
}
#diamond7 {
position: absolute;
top: 38.5%;
left: 64.5%;
}
#diamond8 {
position: absolute;
top: 65.5%;
left: 51%;
}
#diamond9 {
position: absolute;
top: 65.5%;
left: 64.5%;
}
<div class="container">
<section class="grid-section">
<div class="grid">
<div id="diamond1" class="diamond"></div>
<div id="diamond2" class="diamond"></div>
<div id="diamond3" class="diamond-big"></div>
<div id="diamond4" class="diamond-big"></div>
<div id="diamond5" class="diamond"></div>
<div id="diamond6" class="diamond"></div>
<div id="diamond7" class="diamond-big"></div>
<div id="diamond8" class="diamond"></div>
<div id="diamond9" class="diamond-big"></div>
</div>
</section>
</div>
*{
margin: 0;
padding: 0;
}
.container{
height: 638px;
width: 100%;
max-width: 100%;
position: absolute;
overflow: hidden;
background-position: center;
top: 0;
z-index: -1;
}
.container img{
width: 100%;
height: 638px;
}
.container #short-des{
background: rgba(0,0,0,.5);
height: 400px;
width: 500px;
position: relative;
}
<div class="container">
<img src="cover.jpg">
<div id="short-des">
</div>
</div>
i want short-des div to visible over image at the center i tried z-index but it not working. please help me out to fix this with reason so i will take these things in future
Put your div positioned absolute to overlap your image. Use left/top/right/bottom properties to set it's position.
It's position will be relative to closest non-static (absolute/relative/fixed) positioned element or <body>
#short-des,
#short-des2 {
position: absolute;
left: 90px;
top: 50px;
width: 50px;
height: 50px;
background-color: rgba(100, 250, 100, .6);
z-index: 7;
}
#short-des2 {
z-index: 8;
left: 100px;
top: 55px;
background-color: rgba(250, 100, 100, .7);
}
.wrapper {
margin: 50px;
position: relative;
}
<div class="wrapper">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150">
<div id="short-des"></div>
<div id="short-des2"></div>
</div>
You can add image as background of container div [.container] as
.container{
background: url('path/to/image'); // eg. 'cover.jpg'
background-repeat: no-repeat;
background-size: 100% 100%;
height: 638px;
width: 100%;
max-width: 100%;
position: absolute;
overflow: hidden;
background-position: center;
top: 0;
z-index: -1;
}
and remove the <img> from html
<div class="container">
<div id="short-des"></div>
</div>
Try this...
Just set position : absolute then set the location using top and left CSSproperties.
* {
margin: 0;
padding: 0;
}
.container {
height: 638px;
width: 100%;
max-width: 100%;
position: absolute;
overflow: hidden;
background-position: center;
top: 0;
z-index: -1;
}
.container img {
width: 100%;
height: 638px;
}
.container div#short-des {
background: rgba(0, 0, 0, .5);
height: 40px;
width: 50px;
top:40%;
left:50%;
position: absolute;
z-index:999;
}
<html>
<head>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<div class="container">
<img src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png">
<div id="short-des">
</div>
</div>
</body>
</html>
.container{
height: 638px;
width: 100%;
max-width: 100%;
position: absolute;
overflow: hidden;
background-position: center;
top: 0;
z-index: -1;
}
.box {
position: relative;
width: 638px;
height: 300px;
}
.box img{
width: 100%;
height: 500px;
}
.box #short-des{
background: rgba(0,0,0,.5);
height: 400px;
width: 500px;
position: absolute;
left: 50%;
top: 50%;
margin-top: -100px;
margin-left: -250px;
}
<div class="container">
<div class="box">
<div id="short-des">
</div>
<img src="http://www.slowtrav.com/blog/girasoli/IMG_6820.JPG">
<div id="short-des">
</div>
</div>
</div>
http://codepen.io/rizwanmughal/pen/KgZQRx