Css image absolute position on top of responsive image - html

How do I keep the balloon image position stick to the grid image as you resize it?
Balloon1 and B2 are actually inside grid 5 and 7 but if you resize left right, the Balloons will offside.
Do I need a special calc or javascript / jquery library for that?
Thanks.
updated fiddle
.container{
max-width:600px;
max-height:400px;
}
.image-container{
width:70%;
float:left;
position:relative;
}
.img-grid{
max-width:100%;
max-height:100%;
}
.balloon{
position:absolute;
left:30%;
top:50%;
}
.balloon2{
position:absolute;
left:60%;
top:15%;
}
Resize this area
<div class= "container">
<div class="image-container">
<img class="img-grid" src="https://image.ibb.co/hFUHdz/example18.png" />
<img class="balloon" src="https://image.ibb.co/b445WK/tkp_5_balloonpop.png"/>
<img class="balloon2" src="https://image.ibb.co/b445WK/tkp_5_balloonpop.png"/>
</div>
<div class="text-container">
</div>
</div>

Use media queries at say four points throughout the resize, i.e.
#media only screen and (max-width: 600px) {
img{width:60%;height:auto;}
}
Just play about with the image width.

You have to decrease size of the balloons when image gets smaller.
In order to do that you can set ballons width in percentages.
.container{
max-width:600px;
max-height:400px;
}
.image-container{
width:70%;
float:left;
position:relative;
}
.img-grid{
max-width:100%;
max-height:100%;
}
.balloon{
position:absolute;
left:30%;
top:50%;
width: 6%;
}
.balloon2{
position:absolute;
left:60%;
top:15%;
width: 6%;
}
Resize this area
<div class= "container">
<div class="image-container">
<img class="img-grid" src="https://image.ibb.co/hFUHdz/example18.png" />
<img class="balloon" src="https://image.ibb.co/b445WK/tkp_5_balloonpop.png"/>
<img class="balloon2" src="https://image.ibb.co/b445WK/tkp_5_balloonpop.png"/>
</div>
<div class="text-container">
</div>
</div>

Here is updated fiddle.
Hope this is what you were looking for. I have set the image width to 8% so as to resize when screen is resized.
.container{
max-width:600px;
max-height:400px;
}
.image-container{
width:70%;
float:left;
position:relative;
}
.img-grid{
max-width:100%;
max-height:100%;
}
.balloon{
position:absolute;
left:30%;
top:50%;
width: 8%;
}
.balloon2{
position:absolute;
left:60%;
top:15%;
width: 8%;
}
Resize this area
<div class= "container">
<div class="image-container">
<img class="img-grid" src="https://image.ibb.co/hFUHdz/example18.png" />
<img class="balloon" src="https://image.ibb.co/b445WK/tkp_5_balloonpop.png"/>
<img class="balloon2" src="https://image.ibb.co/b445WK/tkp_5_balloonpop.png"/>
</div>
<div class="text-container">
</div>
</div>

Related

How to put a div above an image inside another div?

How can I put a div with text, logo or any more stuff on the center of this banner, like the example?
<div class="banner">
<img src="img/banner2.jpg" width="100%" alt="Nasajon Sistemas">
</div>
Example :
My Page
Here there is an example you can fit to your needs:
.center{
text-align:center;
width:200px;
height:100px;
background-color:red;
position:absolute;
top: 50%;
left:50%;
margin-left:-100px;
margin-top:-50px;
}
.outter{
width:100%;
height: 500px;;
background-color:black;
}
<div class="outter">
<div class="center">
<h1>Mywebsite</h1>
</div>
</div>
https://jsfiddle.net/alexcuria/uunwbqyb/

div not fitting to its contents

So I have a div inside a div. The content in the child div needs to be text-aligned left and the child div itself needs to be centered within the parent div. My problem is, I can't get the child div to only be the width of its content so I can center it. It keeps stretching the length of the parent div. I've tried display:inline-block, inline, table. nothing is working. How do I get the child div to be centered within the parent, but have the child div content be aligned to the left?
Here is my code.
HTML:
<div class="gallery">
<div class="sub_gallery">
<a class="image" href="pic1.jpg"><img src="pic1.jpg"></a>
<a class="image" href="pic1.jpg"><img src="pic1.jpg"></a>
<a class="image" href="pic1.jpg"><img src="pic1.jpg"></a>
...
</div>
</div>
The CSS:
.gallery {
width:100%;
text-align:center;
}
.sub_gallery {
padding:6px;
overflow:auto;
text-align:left;
display:inline-block;
}
.image {
display:inline-block;
width:200px;
height:200px;
overflow:hidden;
position:relative;
margin:6px;
}
.image img {
position:absolute;
top:-10000px;
bottom:-10000px;
left:-10000px;
right:-10000px;
margin:auto;
width:100%;
}
EDIT:
Here is a simple diagram of what I want it to look like:
Diagram
This answer makes things quite different but try it. I am quite sure this will help because it centers the images perfectly on the page.
HTML:
<body>
<div class="gallery">
<div class="sub_gallery">
<center>
<img class="image" src="pic1.jpg">
<img class="image" src="pic1.jpg">
<img class="image" src="pic1.jpg">
...
</center>
</div>
</div>
</body>
CSS:
.gallery {
width:100%;
text-align:center;
}
.sub_gallery {
padding:6px;
overflow:auto;
text-align:left;
width:100%;
}
.image {
width:200px;
height:200px;
overflow:hidden;
position:relative;
margin:6px;
}
.image img {
position:absolute;
top:-10000px;
bottom:-10000px;
left:-10000px;
right:-10000px;
margin:auto;
width:100%;
}
I hope this was helpful.

Float Image to out of DIV

I am currently facing a problem in placing an image out of div. I want the image to be floated extreme right of screen irrespective of div screen size.
I built a DEMO for the problem that i am facing.
CSS:
.outer{
background:cyan;
position:relative;
width:700px;
height:475px;
}
.inner{
width:370px;
color:#fff;
position:absolute;
background:red;
top:35px;
}
Image shall look like as below as per solution
it may help you try this
.inner
{
width:100%;
color:#fff;
position:absolute;
background:red;
top:35px;
}
demo
another demo without inline style
.inner .col-sm-6:nth-child(1)
{
padding-top:10px;
width:20%;
float:left;
}
.anotherdiv
{
width:80%;
float:left;
padding:0;
}
.anotherdiv img{
widh:100%;
}
ijust make these changes in this
see demo here
You can see this DEMO
Snippet:
<div class="inner row">
<div class="col-xs-4 col-md-4 col-sm-4" style="">
<p>Some helper Text goes here and there</p>
</div>
<div class="col-xs-8 col-md-8 col-sm-8" style="">
<img src="http://placehold.it/500x400" style="width:100%;">
</div>
</div>

Positioning vertical center

I want to center these 4 images. Horizontally it is working but vertically it won't work. Does anybody knows how to solve this problem? At the moment I've got a black header/footer section with 4 images centered horizontally. Everything is scalable but not the height of the images.
Am doing it right?
HTML:
<section>
<div class="pic">
<img src="img.png" alt="Pic" />
</div>
<div class="pic">
<img src="img.png" alt="Pic" />
</div>
<div class="pic">
<img src="img.png" alt="Pic" />
</div>
<div class="pic">
<img src="img.png" alt="Pic" />
</div>
</section>
CSS:
body {
margin:0;
padding:0;
max-width: 100%;
max-height:100%;
}
section {
position:absolute;
top:5%;
bottom:5%;
left:0;
width:100%;
height:90%;
}
section img {
width:12.5%;
float:left;
margin-left:10%;
}
Assuming the width of the image equals the height of the image (like the code you gave has), you can just use margin-top of 50% - imageHeight. That would look like
section img {
width:12.5%;
margin-top:32.5%;
float:left;
margin-left:10%;
}
Demo
If they're not, you can use this pure CSS approach
I think its easier to wrap the images in a container and then center the container in the container's parent, in this case you could use an Article tag to wrap the images an then center that article in the section like this
HTML
<section>
<article>
<div class="pic">
<img src="img.png" alt="Pic" />
</div>
<div class="pic">
<img src="img.png" alt="Pic" />
</div>
<div class="pic">
<img src="img.png" alt="Pic" />
</div>
<div class="pic">
<img src="img.png" alt="Pic" />
</div>
</article>
</section>
CSS
html, body {
height: 100%;
width: 100%;
}
section {
top: 5%;
left: 0%;
width: 100%;
height: 90%;
/* strech */
overflow: hidden;
}
article {
width:80%;
height:40%; /* change this to set height */
/* CSS absolute center begin */
border: 2px solid #0000ff;
margin: auto;
position: absolute;
display: inline-block;
top: 0;
bottom: 0;
left:0;
right:0;
/* CSS absolute center end*/
}
.pic {
position: relative;
float: left;
width: 12.5%;
height: 100%;
margin-left: 10%;
}
.pic img{
position: relative;
width:100%;
height:100%;
}
Hope it help you
You can give the section position:relative; and then do a trick with the images.
The sample below makes them centered of the section, if you want to have the images spread out, but vertically aligned, you need to do this trick on the containing element (like a dive around the images in the section:
section {
position:relative;
top:5%;
bottom:5%;
left:0;
width:100%;
height:90%;
}
section img {
/*width:12.5%;
float:left;
margin-left:10%;*/
position:absolute;
top:50%;
margin-top:-25%;/* should be half the height of the image */
left:50%;
margin-left:-25%;/* should be half the width of the image */
}

What's wrong with my CSS , elements move and overlap when resizing window to smaller size?

Ok , so below is my CSS AND HTML code. I have been using percentage for the divs so that those divs can re-adjust to bigger screen sizes . The annoying thing is that when I resize the window to a smaller size on my computer , those elements keep moving till they overlap and I don't want that . How can I use percentages to make those divs re-adjust to bigger resolutions , yet not move when resizing the window to a smaller size based on the CSS and HTML I have below
Here is the CSS
body{
background:#F4F4F4;
background-size:100%;
width:100%;
height:100%;
margin:0 auto;
min-width:1300px;
min-height:750px;
}
.logo{
position:absolute;
left:40%;
top:5%;
}
.logo_homepage{
position:absolute;
left:4%;
top:5%;
}
.homepage_slogan{
position:absolute;
left:3%;
top:45%;
}
.search_box{
position:absolute;
left:30%;
top:30%;
width:35%;
height:50%;
min-width:35%;
min-height:50%;
}
.user_info{
position:absolute;
left:75%;
height:100%;
width:20%;
min-width:20%;
background:white;
}
.header{
position:absolute;
top:0px;
width:100%;
min-width:98%;
height:100px;
min-height:100px;
left:0;
background:#EB6A4A;
}
.slogan{
position:absolute;
top:60%;
left:40.5%;
}
.login{
position:absolute;
top:15%;
left:90%;
}
.whitebackground{
background:#FFFFFF;
}
#slides{
position:absolute;
top:20%;
width:50%;
background:transparent;
height:20%;
left:25%;
}
.socialfeeds{
position:absolute;
top:41%;
width:25%;
height:52%;
min-width:25%;
min-height:52%;
left:25%;
}
.heading{
position:absolute;
top:20%;
width:100%;
min-width:100%;
height:10%;
min-height:10%;
left:2%;
}
.bucket{
position:absolute;
top:18%;
left:20%;
width:13%;
min-width:13%;
}
.title{
position:absolute;
top:20%;
left:32%;
width:30%;
min-width:30%;
}
.feed_icons{
margin:20px;
}
.featured{
position:absolute;
top:30%;
width:30%;
min-width:30%;
background:transparent;
height:60%;
min-height:60%;
left:60%;
}
and the HTML
<body class="whitebackground">
<div class="header">
<div class="logo"><img draggable="false" src="/images/logo.png" /></div>
<div class="slogan"><img draggable="false" src="/images/slogan.png" /></div>
<div class="login"><img draggable="false" src="/images/login.png" /></div>
</div>
<div class="bucket">
<span class="feed_icons"><img draggable="false" src="/images/bucket.png"/></span>
</div>
<div class="title">
<span class="feed_icons"><img draggable="false" src="/images/title.png"/></span>
</div>
<div class="socialfeeds">
<span class="feed_icons"><img draggable="false" src="/images/social_feeds.png" width="100%" height="100%"/></span>
</div>
<div class="featured"><img draggable="false" src="/images/featured_list.png" width="100%" height="100%" /> </div>
<div class="footer"> <span style='margin-left:45%;'> COPYRIGHT 2013©</span></div>
</body>
Position: absolute pulls the elements out of the DOM rendering rules. The CSS as written tells the browser to always place these elements at X position no matter what size of the element or screen. A List Apart has an excellent article for getting a good grounding in how positining works: http://alistapart.com/article/css-positioning-101
Remove the positioning and instead use either the "display:" or "float:" properties. Things will begin to flow according to the DOM rendering rules.
In addition, make sure applied CSS classes have functional or semantic naming. Avoid using classes that make reference to design treatment since things like colors/big/small can and do change over time., ie, "whitebackground". The code is much better served using something like the "client-name" or .theme and then declaring the background color for that class or on the BODY tag.
HTML Mark-up
<body class="site-body">
<div class="header">
<div class="logo"><img draggable="false" src="/images/logo.png" /></div>
<div class="slogan"><img draggable="false" src="/images/slogan.png" /></div>
<div class="login"><img draggable="false" src="/images/login.png" /></div>
</div>
<div class="bucket">
<span class="feed_icons"><img draggable="false" src="/images/bucket.png"/></span>
</div>
<div class="title">
<span class="feed_icons"><img draggable="false" src="/images/title.png"/></span>
</div>
<div class="socialfeeds">
<span class="feed_icons"><img draggable="false" src="/images/social_feeds.png" width="100%" height="100%"/></span>
</div>
<div class="featured"><img draggable="false" src="/images/featured_list.png" width="100%" height="100%" /> </div>
<div class="footer"> <span style='margin-left:45%;'> COPYRIGHT 2013©</span></div>
</body>
CSS:
.header {
height: auto;
overflow: hidden; /* clears floated child elements */
width: 100%;
min-width: 98%;
}
.logo, .slogan, .login {
display: inline-block;
}
/* or...
.logo, .slogan, .login {
float: left;
} */
.slogan {
margin-left: 40.5%;
}
It's better to use media-queries here.
#media all and (max-width: 60%) and (min-width: 30%) {
..........whatever you want to do...................
}
for more info on media-queries visit: css-media-queries