I've got an image, which is about 600px wide, and several smaller images (a little over 100px each) that I need to position centered below the bigger image. Deal is, I need them all in a wrapper together, because I need them to scale relative to one another, rather than overlapping as the window is sized down. Right now, the smaller images shift according the the resizing, so they aren't staying in position relative to the bigger image. They also aren't positioned relatively because when I do so, the css centering no longer works.
Maybe a simpler way of putting it is this. I want these pictures all together in one div that is centered on the browser screen, so the pictures are responsive and stay in the same position/size relative to each other. The div is relative to the screen, and the pictures relative to the div. Inside the div is the big image on top, and 4 smaller images lined up underneath it.
I guess another way to put it is that I want them all the function responsively as if they were just one image, but I need them separate because I need to animate them separately.
http://codepen.io/kathryncrawford/pen/bVyeyL
<div id="wrapper">
<img id="logo" class="img-responsive copy" srcset="http://www.fillmurray.com/600/600"></img>
<div id="wrapperSig">
<img class="img-responsive signature" srcset="http://www.fillmurray.com/100/100"></img>
<img class="img-responsive signature" srcset="http://www.fillmurray.com/100/100"></img>
<img class="img-responsive signature" srcset="http://www.fillmurray.com/100/100"></img>
<img class="img-responsive signature" srcset="http://www.fillmurray.com/100/100"></img>
</div>
</div>
.copy{
opacity: 1;
position: absolute;
margin:auto;
top:0;
right:0;
bottom:0;
left:0;
}
#wrapper {
position: absolute;
margin: auto;
top:0;
right:0;
bottom:0;
left:0;
}
#logo {
position: absolute;
}
#wrapperSig {
display: inline;
position: absolute;
width: 420px;
margin: auto;
top:60%;
right:0;
bottom:0;
left:0;
}
.signature {
opacity: 1;
display: inline !important;
position: relative;
}
If I understand you correctly, you want the small images to drop down below the bigger one on small screens? Would this work by removing position absolute on everything but the wrappersig? http://codepen.io/jfoutch/pen/pjmEgq
.img-responsive {
display: block;
max-width: 100%;
height: auto;
}
.copy{
opacity: 1;
margin:auto;
top:0;
right:0;
bottom:0;
left:0;
}
#wrapper {
margin: auto;
top:0;
right:0;
bottom:0;
left:0;
}
#logo {
}
#wrapperSig {
display: inline;
position: absolute;
width: 420px;
margin: auto;
top:60%;
right:0;
bottom:0;
left:0;
}
.signature {
opacity: 1;
display: inline !important;
position: relative;
}
Related
I'm trying to get two images on top of each other, while also being centered both vertically and horizontally on screen. If I make them both positioned relatively, the first one is centered great, while the second one appears beneath the first.
#copy, #logo {
position: relative;
top: 50%;
transform: translateY(-50%);
margin-left: auto;
margin-right: auto;
}
So I added a wrapper and positioned that relatively and positioned the images absolutely. Now they stack on one another, but I lost my centering.
#wrapper {
position: relative;
top: 50%;
transform: tranlasteY(-50%);
margin-left: auto;
margin-right: auto;
}
#copy, #logo {
position: absolute;
}
You got to make html, body, the #wrapper and all the parent elements for the images to occupy all the screen, with height:100%. Set the positioning of the images absolute based on #wrapper with position:relative on it. And voilá, set the XY positioning margin to 50% (as you did) and translate(-50%) (as you did).
body,html{
padding:0;
height:100%;
}
#wrapper {
position: relative;
height:100%;
}
#copy, #logo {
opacity: 1;
position: absolute;
top:50%;
left:50%;
transform:translateY(-50%) translateX(-50%);
}
Pen
Obs: Great images btw
You can omit the wrapper and just use absolute positioning on the children elements, setting the margin to auto and the top/right/bottom/left to 0:
#copy, #logo {
opacity: 1;
position: absolute;
margin:auto;
top:0;
right:0;
bottom:0;
left:0;
}
<div id="wrapper">
<img id="copy" class="img-responsive" src="http://fillmurray.com/600/600"></img>
<img id="logo" class="img-responsive" src="http://fillmurray.com/500/500"></img>
</div>
I want to create responsive popup banner with close button here is my simple scenario:
<div class="banner">
<img src="...">
X
</div>
And my CSS:
.banner img{
max-width:100%;
max-height:100%;
position:absolute;
}
.close-btn{
position:absolute;
right:0;
z-index:2;
color:red;
background:#000;
padding:4px;
}
As you can see I stretch image depending on width and height.
Problem: I want close-btn to stick to the right side of the image and overlap it. To solve this the banner must be the same width as the image. If banner has position:absolute its width and height of course is 0.
Is it possible to achieve only with CSS?
Here is fiddle: http://jsfiddle.net/fjckls/qq590xz5/
I need image to be responsive to width and height
To make your image fully width AND height responsive, first off, you need to alter your units. You're currently using %'s which is all well and good, but for the 'fully height responsive' concept, the % units aren't much help.
Instead, you should look into using vh (view-height) and vw (view-width) units, since these are for the actual viewport that the user can see currently.
In order to position your 'x' over the top right of your image, you're going to have to alter your css slightly.
You could possibly include a css rule for your banner, first off. Something like:
.banner {
position:relative;
display:inline-block;
}
Whilst removing the 'position:absolute' rule from your image, since now your banner div will be the size of your image (not the default '100% of screen' that divs are set to originally).
This leaves us one problem, you haven't actually set where abouts you want the 'x' to appear vertically, so it will default to 'where it would position normally', which, in this case, would be below the image. To tackle this, you would need to add a top: or bottom: declaration to your 'x' class, and in my case, i've chosen to set it to the top (top:0;).
The overall fiddle can be shown here
or here:
.banner img {
max-width: 100vw;
max-height: 100vh;
}
.close-btn {
position: absolute;
right: 0;
top: 0;
z-index: 2;
color: red;
background: #000;
padding: 4px;
}
.banner {
position: relative;
display: inline-block;
}
<div class="banner">
<img src="http://sockets.hogwartsishere.com/media/book_covers/l-bunny.jpg" /> X
</div>
I have updated the link
http://jsfiddle.net/qq590xz5/3/
<div class="banner">
<div style="position:abolute;">
<img src="http://sockets.hogwartsishere.com/media/book_covers/l-bunny.jpg">
X
</div>
</div>
.banner img{
max-width:50%;
max-height:100%;
}
.close-btn{
position:absolute;
z-index:2;
color:red;
top:1%;
background:#000;
padding:4px;
}
Have a look
Thanks
try this..
Html
<div class="banner">
<img src="http://sockets.hogwartsishere.com/media/book_covers/l-bunny.jpg">
X
</div>
CSS
.banner{
position:relative;
width:200px;
}
img{
max-width:100%;
}
.close-btn{
position:absolute;
right:0;
top:0;
z-index:1;
color:red;
background:#000;
padding:4px;
}
Fiddle Demo
I found a solution that keeps the image centered horizontally and the x button on the top right of the image. It involves:
1) Making the .banner absolutely positioned, with margins from each window edge. This centers the entire .banner, however you might want to use fixed position if you need it to scroll along with the user's viewport.
It'll work as long as there aren't any other positioned elements as its parents.
.banner {
position: absolute;
top: 5%;
left: 25%;
right: 25%;
bottom: 5%;
}
2) Making a thing that sticks around the image, which will serve as a positioning guide for the little X.
<div class="shrinkwrap">
<img src="...">
X
</div>
.shrinkwrap {
/* shrink-wraps this div around its content;
as a side-effect, lets this div be centered with text-align: center; */
display: inline-block;
/* new positioning context! */
position: relative;
/* keeps the responsiveness */
max-width: 100%;
height: 100%;
}
3) Positioning the shrinkwrapper to always be in the center of the .banner.
.banner {
/* ... */
text-align: center;
}
.close-btn {
/* ... */
top: 0;
}
The finished version of this is here: http://jsfiddle.net/boxmein/qq590xz5/5/
.overlay{
position:absolute;
top:0;
left:0;
height:100%;
width:100%;
background:url(hex-shape.png) no-repeat center;
z-index:99999;
}
My background image is an overlay for the entire page. I would like to fill the rest of the page with white surrounding the overlay image but not within it.
I am using it to frame a picture in the middle of the screen.
The idea is the page can be a full color behind the background image and still be invisible because of the border or whatever gets put around the image.
.overlay{
position:fixed;
top:0;
left:0;
bottom:0;
right:0;
background: #{your_color} url(hex-shape.png) no-repeat center;
z-index:99999;
}
If you know the size of the picture, this is an easy way to center an image in the middle:
HTML:
<div id="container">
<img id="placekitten" src="http://placekitten.com/g/200/300">
</div>
CSS:
#placekitten {
position: absolute;
left: 50%;
top: 50%;
margin-top: -150px;
margin-left: -100px;
z-index: 9000;
}
#container {
height: 500px;
border: solid black 1px;
}
The key is to make the margin-top equal to -1 * height/2 and the margin-left equal to -1 * width/2. You do have to set these values manually for this to work, however.
FIDDLE
dont realy understand what you need but i think this will help
use stretch technique :
.overlay{
position:absolute;
top:0;
left:0;
bottom:0;
right:0;
background:url(hex-shape.png) no-repeat center;
z-index:99999;
}
play with the top, left, right, bottom values
I am stuck in making images inside background of a class responsive.The website url .
It would be very helpful if you could help me out i am using bootstrap and nivo slider.
The css and the html that i am using for the slider are given below.
The css:
.slider-wrapper {
width: 310px;
height: 650px;
background: url("images/iPhone.png") center center ;
background-size:cover;
}
.nivoSlider {
position:relative;
width:290px;
height:512px;
top:60px;
bottom:65px;
left:23px;
right:24px;
overflow: hidden;
}
.nivoSlider img {
position:absolute;
top:0px;
left:0px;
width:100%;
height: 100%
}
The html:
<div class="slider-wrapper ">
<div id="slider" class="nivoSlider">
<img src="" />
<img src="" />
</div>
</div>
And a screenshot of the above code (with additional html ) on a laptop:
Here is the website url. Try viewing it below 380px width as that's when the problem occurs.
I want the image to be visible properly at less than 380px.
I want the all the images to become smaller and be in the center and properly aligned below 380px but i get this:
.
I would be more than thankful if you could help me out
It's a little hard to debug without seeing the whole picture, but I think you need to be using max-widths like the code below. This will prevent your divs/images from becoming larger than you want, but will allow them to be smaller if necessary.
.slider-wrapper {
max-width: 310px;
max-height: 650px;
background: url("images/iPhone.png") center center ;
background-size:cover;
}
.nivoSlider {
position:relative;
max-width:290px;
max-height:512px;
top:60px;
bottom:65px;
left:23px;
right:24px;
overflow: hidden;
}
.nivoSlider img {
position:absolute;
top:0px;
left:0px;
max-width:100%;
height: auto;
}
Absolute positioned elements need to be put in a floated container to move responsively. The mobile content will move in sync with the screen shell if you put the absolute container into a floated one. I ran into this exact same problem on one of my projects - it's a surprisingly easy solution.
Pen:
http://codepen.io/staypuftman/pen/tFhkz
Note the pink absolute positioned element moves as you resize the screen while staying inline with the blue box. The whole blue box with the pink absolutely positioned element inside will float together as unit to any width.
HTML:
<div class="hero-background">
<div class="hero-text-area-container">
<h3 class="hero-text-effects">Eaters: Find Your Favorite Food Truck</h3>
</div>
<div class="iphone-backdrop">
<div class="hero-image-band-container"></div>
</div>
</div>
CSS (background colors are to show elements):
.hero-background {
background: #dedede;
height: 100%;
margin-top: 4em;
min-height: 20em;
min-width: 100%;
}
.hero-text-area-container {
background: #d6ffd1;
float: left;
margin: 0% 6%;
max-height: 25em;
padding-top: 11em;
position: relative;
vertical-align: middle;
width: 55%;
}
.hero-background .hero-text-area-container h3 {
background: #f7f7f2;
opacity: .8;
padding: 1em;
text-align: center;
}
.iphone-backdrop {
background: #d1e2ff;
float: left;
height: 120px;
max-width: 320px;
padding-top: 2em;
position: relative;
width: 100px;
}
.hero-image-band-container {
background: #ffd1d1;
height: 80px;
position: absolute;
width: 80px;
top: 13%;
left: 0;
bottom: 0;
right: 0;
}
Change the css in nivo-slider.css from:
.nivoSlider img {
position:absolute;
top:0px;
left:0px;
width:100%;
height:100%
}
To
.nivoSlider img {
position:absolute;
top:0px;
left:0px;
/* now this is the important things for your problem */
vertical-align: baseline !important;
max-width: none !important;
}
i found the answer.It was posted to me by a user.So I'm sharing it if anyone else gets into any trouble:
"So to not have all the things in the comments I post an answer.
The "problem" on screen-/ viewport widths of 380px and below has several issues.
On your outer <div> with the class slider-wrapper3 (it's the one which holds the iPhone as background image) you should use the following in your CSS:
.slider-wrapper3 {
background-size: contain; /* you use cover */
background-repeat: no-repeat;
/* keep the rest of your actual code */
}
and remove the width setting (width: 310px;) at least for your small screen layout!
By doing so you have then fixed the position and size of the container (and also the background image).
So you still need to adjust the image sizes (probably in your slider script, or wherever the image's dimensions come from)."
Try this:
#media(max-width: 380px) {
.nivoSlider{
position:relative;
width:94%;
height:378px;
top:85px;
bottom:0px;
left:8px;
overflow: hidden;
}
I have been strugglign for the last few horus trying to make it so that the background class will be centered in the website, but i have absolute position and fixed in my css for the inside of it because i need it done for a changing fading background image. But my problem is i cant get it centered in the site for example see in div.background i have margin 0 and it still isnt centered it just stays to the left i even tried but it doesnt work... How cani get the background div i made to be centered...
<div class="background">
<img src="images/back_1.jpg" width="990" height="660" alt="pic1" />
<img src="images/back_2.jpg" width="990" height="660" alt="pic2" />
<img src="images/back_3.jpg" width="990" height="660" alt="pic3" />
</div>
style
div.background {
margin:auto;
width: 990px;
position:absolute;
left:0px;
top:0px;
z-index:-1;
}
div.background img {
position:fixed;
list-style: none;
left:0px;
top:0px;
}
div.background ul li.show {
z-index:500
}
I think you want this:
div.background img {
position: fixed;
list-style: none;
left: 50%;
margin-left: -495px;
top: 0px;
}
left: 50% moves the left edge of the img to the center of the page, then margin-left: -495px; shifts it back to the left exactly the right amount so that it's centered.
This wouldn't work. What you should have is something like:
div.background {
position: absolute
top: 0;
left: 0;
width: 100%;
height: 100%;
background: no-repeat center center url('images/back_1.jpg');
}
and eliminate the individual <img> tags inside the div.
You can then use some javascript to swap the background images whenever, since CSS1 only allows a single background image (CSS3 allows multiples).
Did you try
#background {
margin: 0 auto;
width: 990px;
position:absolute;
top:0px;
z-index:-1;
}