Display images relative on another resized image - html

I'm creating a quiz editor.
User should be able to put check box on image
I have a div who represent a zone
inside, there is an image
on the image there are check box.
image may have any size, i don't know the size of image
check box should be positioned relative to the image
image should be center on the zone
I need something dynamic, screen should be resizable
i have the following code:
HTML
<div class="boundary" >
<div class="mycomponent">
<div class ="container">
<img style="display: block; max-height: 100%; max-width: 100%; margin-left: auto; margin-right: auto;" src="image.jpg" >
<img style="left: 20.3501%; top: 44.448%; display: block; position: absolute;" id="imgi0" src="uncheck.png">
<img style="left: 52.7185%; top: 35.7171%; position: absolute;" id="imgi1" src="uncheck.png">
<img style="left: 82.0456%; top: 31.3517%; position: absolute;" id="imgi2" src="uncheck.png">
</div>
</div>
</div>
CSS
.boundary
{
left: 0px;
display: block;
position: absolute;
right: 0px;
bottom: 50px;
top: 75px;
background-color: aquamarine;
}
.mycomponent
{
height: 43%;
width: 89.29%;
top: 26.78%;
left: 5.496%;
overflow-y: hidden;
overflow-x: hidden;
position: absolute;
padding: 0px;
text-align: center;
border-color:#000000;
border-style: solid;
background-color: beige;
}
.container
{
display: inline-block;
position: relative;
overflow: hidden;
}
jsfiddle : http://jsfiddle.net/jlogan/91p06yjm/
This code works fine on chrome and safari but failed in firefox and ie9+
any clue ?
Thansk a lot

I updated and cleared your fiddle to make it clearer. You can give your class "mycomponent" max-height instead of height.
.container{
max-height: 43%; // You had "height:43%";
width: 89.29%;
top: 26.78%;
left: 5.496%;
overflow-y: hidden;
overflow-x: hidden;
position: absolute;
padding: 0px;
text-align: center;
border-color:#000000;
border-style: solid;
background-color: beige;
}
Working fiddle
It's working for me in every browser, even if you resize the window.

Related

hide the images going outside the div

bgpattern, illustratewoman class images should be hidden outside the div but the image is visible outside the card div also. For me, the images only should be displayed inside the div but not outside. Box class image should display on the inner and outer side of the div.
CSS even though I tried overflow: hidden for card class but it hides all the images going outside but for me, box image should not be hidden I tried to add for bgpatternimg, illustratewoman it doesn't work.
card {
position: absolute;
background-color: white;
height: 70vh;
width: 130vh;
border-radius: 3%;
position: relative;
margin: auto;
top: 15vh;
}
.bgpatternimg {
overflow: hidden;
position: absolute;
left: -70vh;
top: -30vh;
width: 120vh;
}
.illustratewoman {
overflow: hidden;
position: absolute;
bottom: 10vh;
left: -10vh;
width: 60vh;
height: 50vh;
}
.boximg {
position: absolute;
width: 22vh;
bottom: 4vh;
left: vh;
overflow: visible;
}
<div class="card">
<div class="left">
<div class="bgpattern">
<img class="bgpatternimg" src="images/bg-pattern-desktop.svg" alt="bgpattern">
</div>
<div class="illustratewoman">
<img class="illuswoman" src="images/illustration-woman-online-desktop.svg" alt="illustratewoman">
</div>
<div class="box">
<img class="boximg" src="images/illustration-box-desktop.svg" alt="">
</div>
</div>
you're positioning absolute which means it'll make the position relative to the nearest static/relative positioned parent or grandparent. you're better off using another strategy without absolute positioning, then make your widths and heights 100%
change style file
hello you should change the style to this code
.card{
position:absolute;
background-color: white;
height:70vh;
width:130vh;
border-radius: 3%;
position:relative;
margin:auto;
top:15vh;
}
.bgpattern {
overflow: hidden;
position: absolute;
left: -70vh;
top: -30vh;
width: 120vh;
}
.illustratewoman {
width: 60vh;
position: absolute;
bottom: 10vh;
left: -10vh;
overflow: hidden;
}
.box {
position: absolute;
width: 22vh;
bottom: 4vh;
left: 28vh;
}

How to fix the position of elements to a page?

I have this image currently. The circle, the close image, and get your quotes image. (see below)
Correct image layout
I can't get all elements to be fixed together so when I change the size of the screen the elements move together instead of separately across the page. (see below)
Incorrect image layout
I have looked into the positioning of each element, but I maybe misunderstanding something, or my code is messy. Please see below:
HTML:
<body>
<!--Thanks for visiting image-->
<div id="thanks-for-visiting-img-bg" class="thanks-for-visiting-bg">
<div id="thanks-for-visiting-img-container" class="thanks-for-visiting-img-container">
<img src="../images/thanks_for_visiting_img.png" alt="Thanks for visiting" id="thanks-for-visiting-img" class="thanks-for-visiting-img">
</div>
</div>
<!--Get Quotes button-->
<div>
<img src="../images/btn.png" alt="Get Your Quotes" id="get-quotes-btn" class="get-quotes-btn">
</div>
<!--Close button-->
<div>
<img src="../images/close_green.png" alt="Close Thanks For Visiting image" id="close-btn" class="close-btn">
</div>
</body>
</html>
CSS:
/*CONTAINER*/
.thanks-for-visiting-img-container {
width: 550px;
height: 550px;
z-index: 2147483647;
left: 0px;
right: 0px;
margin: auto;
top: 0px;
bottom: 0px;
display: block;
outline: none;
max-width: none;
max-height: none;
position: fixed !important;
cursor: default !important;
}
/*IMAGE BACKGROUND*/
.thanks-for-visiting-bg {
display: block;
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
/*z-index: 2147483647;*/
overflow: auto;
background-color: rgb(0, 0, 0);
opacity: 0.83;
}
/*-- GET QUOTES BUTTON --*/
.get-quotes-btn {
cursor: pointer;
position: absolute;
background-color: rgba(0, 0, 0, 0);
background-repeat: no-repeat;
background-size: cover;
width: 288px;
height: 49px;
border-radius: 0px;
z-index: 2;
right: 0px;
bottom: auto;
left: -20px;
top: 425px;
margin: auto;
display: block;
}
.close-btn {
cursor: pointer;
position: absolute;
right: 50%;
bottom: 100px;
left: 65%;
top: 80px;
}
.thanks-for-visiting-img-container and .thanks-for-visiting-bg has to be fixed because the bg class' CSS doesn't work without it and the img container has to be fixed because the page will need to scroll underneath it. Can anyone help?
You can put all the div tags (Get Quotes, the image and the close button) in another div tag and then, add this CSS class to that new div tag:
.mainClass {
display: flex;
flex-direction: column;
}

Image size to fit in fixed size div

I have div of fixed size height:45px and width:60px and no other css to div. This div used to show the image uploaded by customer. I want to give the dimensions of image so that the uploaded image will be fit in given div perfectly. I need to give the optimized size so that image will look good in div. First logic I tried to give the image with 45 by 60, 90 by 120 like.
What is the correct way to solve this.Please guide.Thanks in advance.
div {
width: 160px;
height: 145px;
overflow: hidden;
border: 1px solid black;
}
div img {
width: 100%;
min-height: 100%;
}
<div>
<img src="https://i.stack.imgur.com/aFYTl.jpg?s=328&g=1"/>
</div>
Best thing is the following:
#div-to-contain-image img {
display: block;
height: auto;
min-width: 100%;
width: 100%;
}
This will render the image the best as possible. If you need to cover the containing div entirely, you could do the following:
#div-to-contain-image img {
display: block;
height: 100%;
width: 100%;
}
I have multiple solution for you image thumbnail setting. Maybe it will be helpful for you.
Solution #1:
Image vertical and horizontally center inside div
.thumb-container {
position: relative;
width: 60px;
padding-bottom:45px; /* padding is using for the height of image */
margin: 0px;
overflow: hidden;
border: 1px solid black;
}
.thumb-img {
position: absolute;
width: 100%;
height: 100%;
border-radius: 0px;
padding: 0px;
overflow: hidden;
border: 0px;
}
.thumb-img img {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: auto;
max-width: 100%;
}
HTML
<div class="thumb-container">
<div class="thumb-img"><img src="https://placeholdit.imgix.net/~text?txtsize=47&txt=500%C3%97900&w=80&h=50"></div>
</div>
View on Jsfiddle https://jsfiddle.net/5az8u7bj/
Solution #2: Image vertical and horizontally center width:100% inside div fully cover image box no white space
.thumb-container {
position: relative;
padding-bottom:45px;
margin: 0px;
overflow: hidden;
border: 1px solid black;
width:60px;
}
.thumb-img {
position: absolute;
width: 100%;
height: 100%;
border-radius: 0px;
padding: 0px;
overflow: hidden;
border: 0px;
}
.thumb-img img {
position: absolute;
top: 0;
bottom: 0;
left: -100%;
right: -100%;
height:100%;
margin: auto;
width: auto;
}
HTML
<div class="thumb-container">
<div class="thumb-img"><img src="https://placeholdit.imgix.net/~text?txtsize=47&txt=500%C3%97900&w=500&h=200"></div>
</div>
View on JSfiddle https://jsfiddle.net/2d6x3fn6/1/
Maybe these solution will be helpful for you

How to resize to fit and center image in a position absolute div?

I need an image to be resized to fit in inside a div. This div must, necessarely, no matter what, be an position: absolute; div. Apart from the image have 100% from its greatest dimension, it should be centered in the other way.
I could resize to fit it, but can't center. I tried to make it inline and use vertical-align, but it didn't work.
Since code worth more than words, check my fiddle example.
This is the code from the jsfiddle:
CSS:
.relative {
width: 400px;
height: 400px;
position: relative;
<!-- Next is not important, only to display better -->
display: block;
background-color: green;
border: 3px solid yellow;
margin-bottom: 10px;
}
.absolute {
position: absolute;
top: 20px;
bottom: 20px;
left: 20px;
right: 20px;
background-color: red;
}
img {
max-width: 100%;
max-height: 100%;
width: auto;
height: auto;
}
HTML:
<div class="relative">
<div class="absolute">
<img src="http://upload.wikimedia.org/wikipedia/commons/1/15/Cat_August_2010-4.jpg"/>
</div>
</div>
<div class="relative">
<div class="absolute">
<img src="http://us.123rf.com/400wm/400/400/pashok/pashok1101/pashok110100126/8578310-vertical-shot-of-cute-red-cat.jpg"/>
</div>
</div>
you may put the image to background instead of an img tag.
<div class="absolute">
<img src="//upload.wikimedia.org/wikipedia/commons/5/52/Spacer.gif">
</div>
.absolute {
background-image: url(http://upload.wikimedia.org/wikipedia/commons/1/15/Cat_August_2010-4.jpg);
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
however, if you can set a fixed height for the div, you can use this:
.absolute { line-height:360px; }
.absolute img { vertical-align:middle; }
Only for semi-new browsers:
img {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
Absolutely position all the things!
transform still needs browser prefixes I hear. -webkit- works for me.
http://jsfiddle.net/rudiedirkx/G9Z7U/1/
Maybe I did not understand the question…
.absolute {
position: absolute;
top: 20px;
bottom: 20px;
left: 20px;
right: 20px;
background-color: red;
line-height:350px; //new
}
img {
position:relative;
display:inline-block; // new
vertical-align:middle; // new
max-width: 100%;
max-height: 100%;
width: auto;
height: auto;
}

How do you set a div's location to be centered when we don't know the screen size?

I want to set the position of a div at the center of the page without using JavaScript; using only CSS.
The div is a form with a background picture.
How should I do it when I can't use javascript to get screen size?
div.login {
position: absolute;
background-repeat: no-repeat;
background-attachment: fixed;
background-image: url("Images/01.jpg");
width: 500px;
height: 270px;
}
This should give you all you need: http://www.wpdfd.com/editorial/thebox/deadcentre3.html
<div id="horizon" style="background-color: transparent; text-align: center; position: absolute; top: 50%; left: 0px; width: 100%; height: 1px; overflow: visible; visibility: visible; display: block">
<div id="content" style="background-color: red; margin-left: -125px; position: absolute; top: -10px; left: 50%; width: 250px; height: 20px; visibility: visible">
<span style="color: white;">This box stays in the absolute center.</span>
</div>
</div>
The above code is a stripped down version of the linked example. It creates a <div> that is always in the exact center of the page. (Both vertically and horizontally.)
It's a simple and clean method for elements who's dimensions are known, as your question seems to be referring to.