I'd like to make two clickable images, one for video and one for PDF. They would be intersecting, and the PDF button is behind the Video button, just like in the image below:
So far, I haven't come across a similar solution on the internet, but I'd like to know if it's possible to create it without any interruptions, where both are easily clickable, and how I could do so.
A combination of position absolute and z-index will do the needy:
#video {
left: 100px;
top: 75px;
width: 250px;
height: 150px;
z-index: 10;
background: lightblue;
}
#pdf {
left: 300px;
top: 25px;
width: 75px;
height: 100px;
z-index: 1;
background: red;
}
.tile {
position: absolute;
display: flex;
align-items: center;
justify-content: center;
}
<div id = 'video' class = 'tile'>VIDEO</div>
<div id = 'pdf' class = 'tile'>PDF</div>
Use position relative and absolute on your video and pdf respectively and wrap them inside a container that uses position :relative aswell
This should do the trick :
.container {
/* What you need */
position : relative;
/* the code below is only for this example */
width : 300px;
margin-top : 150px;
}
.video {
/* What you need */
position : relative;
z-index : 2;
/* the code below is only for this example */
width : 300px;
height : 300px;
display : flex;
align-items : center;
justify-content : center;
text-align : center;
background-color : red;
}
.pdf {
/* What you need */
position : absolute;
top : -100px; /* change value to desired position */
right : -100px; /* change value to desired position */
z-index : 1;
/* the code below is only for this example */
width : 150px;
height : 200px;
display : flex;
align-items : center;
justify-content : center;
text-align : center;
background-color : blue;
}
<div class="container">
<div class="pdf">pdf</div>
<div class="video">video</div>
</div>
Related
It's a strange position when you overlap the picture.
<img id = "ganttIn" src = 'ganttBackground.png'><br>
<div id = 'chartBar0' style = '
float:left;
position : absolute;
width : 10%;
height : 20px;
background-color : #D4F4FA;
display : inline-block;
'>
<\div>
<\img>
I want
#ganttIn{
position: relative;
top : 20px;
left : 40px;
/*margin: 20px auto 40px auto;*/
width : 80%;
height : 25px;
z-index: 1;
text-align: left;
}
I want to make two pictures superimposed into a gantt chart. That's why Bar wants to align to the left. But #chartBar is a central alignment, not a left-hand alignment It also has a strange location #chartBar is slightly downwards rather than overlaps with the illustration. Can I see why this is happening?
Here's a quick fix. Not sure if this is what you really want though.
<div class="wrapper">
<img id="ganttIn" src="ganttBackground.png"/>
<div id="chartBar0"></div>
</div>
css (add the z-index: 2; to the one you need on top)
.wrapper{
position: relative;
top : 20px;
}
#ganttIn{
position: absolute;
/*left: 40px;*/ enble this if you need
width: 80%;
height: 25px;
}
#chartBar0{
position: absolute;
width: 10%;
height: 20px;
background-color: #D4F4FA;
}
I want to place an image inside div such that it fits completely. Now it just clips the image if it's more than the width of the div containing it (image_div).
Below is the code,
<form>
<div className="form_fields">
<span className="required">Viewpoint</span>
<a>anchor tag</a>
<div className="image_div">div containing image
<img src="somelink"/>
</div>
</div></form>
form {
flex-grow: 1;
display: flex;
flex-direction: column;
.form_fields {
padding: $padding $gutter $padding $gutter;
background-color: #fff;
position: relative;
top: 0px;
left: 0px;
overflow: auto;
flex-grow: 1;
.image_div {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 105px;
height: 105px;
img {
display: block;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
}}}
How can I place the complete image inside the div containing it? Could someone help me with this? Thanks.
you have put className in the div like this <div className="image_div">
the className is not an attribute the right attribute is just class so you should put it as <div class="image_div"> and <div class="form_fields">
If you're looking to maintain the ratio of the image so that it doesn't appear stretched (as it doesn't seem to be clear whether that's the case or not), there is an alternative option to using the image as a background-image:
img {
width:auto;
height:auto;
max-width:105px;
max-height:105px;
}
<img src="https://via.placeholder.com/150x100">
This is originally 150x100 but is reduced down to 105 (the max-width) x 70 as per the above css.
You can give your image_div a background-image with the URL of the src that's in your example.
image_div {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 105px;
height: 105px;
background-image: url('some-link');
}
Just ensure that you're paths are correct, as in some scenarios the path (if you're hosting the image) may differ between how you would write in on your page and in your css file.
I am trying to center an image (the "Coca" of Coca Cola in my fiddle example) that is within an absolute element .itemDisplay which has no fixed width.
I believe the no fixed width is and issue as it seems to stop the image from centering.
There are alot of answers for centering within a absolute element but I can't find any that are for multiple columns rather than just the left 50%, etc answers. .itemDisplay sits within a div called .parentItem that is 32% of the screen with some padding and margins and there are 3 per row.
All 3 column will have it's own image, but I've only done the first one as an example.
When the div containing the coca image is hovered it currently displays a hidden div with cola with the image centered which works correctly, my only issue is centering the coca image.
I have tried all answers and can't seem to get it to work.
Any ideas!?
https://jsfiddle.net/se23vvwu/
Your parent elements need to be relative and have the size of it's children. For that, if you can't have a fixed width, you can use width: fit-content;.
Then I applied left: 0; and right: 0; for the absolute element.
Here is the result (you still need to accomodate the hover state):
#shopShelves {
width : 100%;
padding : 15px;
max-width : 100%;
margin : 0 auto;
}
.parentItem {
height : 200px;
background-color : #e7e7e7;
float : left;
margin-left : 1px;
margin-bottom : 1px;
position: relative;
}
.parentItem a {
position: relative;
width: 100%;
height: 100%;
display: inline-block;
}
.parentItem:hover .hoveredItem {
opacity : 1;
z-index : 1;
}
.parentItem:hover .itemDisplay {
opacity : 0;
}
.I33 {
width : 33.2%;
}
.displayCenter {
position : relative;
width : 33.2%;
background-color : #F00;
}
.parentItem:hover {
opacity : 1;
}
.itemDisplay {
opacity: 1;
transition: opacity 0s 0.2s;
position: absolute;
display: block;
width: fit-content;
left: 0;
right: 0;
margin: 0 auto;
}
.hoveredItem {
opacity : 0;
margin-bottom : 0;
}
.imgcenter {
display : block;
margin : auto;
max-width : 280px;
float : none;
position : relative;
}
width: fit-content; has some compatibility issues with IE. But I'm pretty sure there are workarounds. Some people use display: table;
More browser specific properties:
width: intrinsic; /* Safari/WebKit uses a non-standard name */
width: -moz-max-content; /* Firefox/Gecko */
width: -webkit-max-content; /* Chrome */
You might have to do a little more research.
Hope this helps!
Here's a simple example:
<div class = "has-scrollbar">
<div class = "long"></div>
<div class = "overlay"></div>
</div>
.has-scrollbar {
width: 200px;
height: 100px;
overflow-y: scroll;
position: relative;
}
.long {
height: 200px;
width: 50px;
background: blue;
}
.overlay {
width: 100%;
height: 100%;
background: red;
opacity: 0.5;
position: absolute;
top: 0;
}
JsFiddle
The red overlay should completely fill the parent container. The height of .long is not known in advance. The .has-scrollbar div should still be scrollable (and not covered).
Any solution using position: fixed on .overlay will not likely work. The real-world scenario is far more complex. Consider the position of .has-scrollbar within the body to also not be known in advance.
So you don't know about long, but seems like you do control has-scrollbar, so you can make overlay fixed and position it in the same place as has-scrollbar:
.overlay {
height: 100px;
margin-top: 8px; /* just to compensate for body margin in the example */
pointer-events: none; /* mouse events will pass through */
position: fixed;
width: 200px;
}
Updated JSFiddle.
I want an out put similar to this Image..!
following is what i've tried to do.JSfiddle
P.S: I cannot edit the structure of the content.
Since you can't edit the HTML, you can't use floating properly, which would be the perfect solution.
But then you can use absolute positioning:
div {
width: 500px;
min-height: 100px; /* image height */
position: relative;
text-align: justify;
}
img {
width:100px;
position: absolute;
top: 0;
right: 0;
}
p:first-child {
max-width: 400px; /* wrapper width - image width */
}
Demo