Making an image responsive in a slider - css

My first slide on this page, Promotion slide wasn't responsive...I added
max-width: 100%; height: auto
to the css. It works But now it adds too much space below the image when viewing on mobile device. It also makes the title disappear. How do I make this image responsive, but get rid of the space below?
http://new.921thefrog.com/index.php/test-promo-slider/
Here is the rest of the code
.promo_slider_wrapper { margin:10px 0; position:relative; }
.promo_slider { height:235px; overflow:hidden; position:relative; }
.promo_slider img {margin:0; padding:0; max-width: 100%; height: auto }
promo_slider .panel {
overflow:hidden;
width:100%;
height:100%;
position: absolute;
top: 0;
left: 0;
}

In order to center the image you can apply this on the img elements:
img {
position:absolute;
width: 100%;
height: auto;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
}
But still you will need some js if H > W because in that case the height should be 100% and the width auto
// EDIT
I just took a look at the page source code
<div class="promo_slider auto_advance" style=" height:418px;">
the height should be set to auto, not 418px

Related

CSS: How can I make a 1:1 div that is 100% of its parents width or height, whichever is smaller?

This pen probably explains my problem best:
http://codepen.io/anon/pen/xwQpLy?editors=110
I'm using the following trick to keep the box constrained to a 1:1 ratio:
.squarebox {
position: relative;
width: 100%;
}
.squarebox::before {
padding-bottom: 100%;
content: "";
display: block;
}
.content {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
But, I'd like the box to always fill the parent's width or height, whichever is smaller. In the above example, the box only ever fills the parent's width.
Do you mean like this?:
http://codepen.io/anon/pen/yYQpqp?editors=110
The parent needs to be position:relative, the .content div needs to be width:100%; height:100%; as well as position:relative with top, right, bottom and left set to 0.
I stripped out the squarebox div.
.squarebox {
position: relative;
width: 100%;
}
.content {
width:100%;
height:100%;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background:orange;
}

How to Center an image on top of another image using CSS?

I wish to achieve the following effect, regardless browser (re)size:
The images are set to be flexible, so, each of them as a max-width declared as:
100%.
http://jsfiddle.net/rgdrqbg4/
The css:
img {
max-width: 100% !important;
vertical-align: middle;
}
.home-video {
position: relative;
width: 57.291666666667%;
}
.video-placeholder {
position: relative;
left: 0;
top:0;
}
.play-video {
position: absolute;
left: 32.545454545455%;
top: 22.508038585209%;
}
Can someone please point some directions, or name some common used techniques to overlay two images while keep them absolute centered, regardless the viewport width?
A common technique is to set top and left to 50% and set margin-top and margin-left negative half of the height and width of your image.
Try this:
.play-video {
position: absolute;
top: 50%;
left: 50%;
margin-top: -90px;
margin-left: -97px;
}
Working JSFiddle sample: http://jsfiddle.net/rgdrqbg4/1/
UPDATE
You can also set top, left, right, and bottom to 0 and set margin to auto for it to auto calculate the margin needed to center the image.
.play-video {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
margin: auto;
}
Working JSFiddle sample: http://jsfiddle.net/rgdrqbg4/5/
This will only work if the image inside is smaller than the image that is wrapping it.
UPDATE
You are setting width for .home-video. At some point in the viewport, the container has more width than the image so the black box is centering accoring to the container, not to the parent image. To make the .home-video container have the same width as its larger image you can use this:
I added a width of 30% to the black box so it can shrink with the larger image too.
.home-video{
display: inline-block;
}
.play-video {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: 30%;
margin: auto;
}
And remove the width you set before.
Working JSFiddle sample: Working JSFiddle sample: http://jsfiddle.net/rgdrqbg4/9/
img {
max-width: 100% !important;
vertical-align: middle;
}
.home-video {
position: relative;
width: 57.291666666667%;
}
.video-placeholder {
position: relative;
left: 0;
top:0;
}
.play-video {
position: absolute;
left: 32.545454545455%;
top: 25.508038585209%;
width: 34%;
height: 40%;
}
<div class="home-video">
<img class="video-placeholder" src="http://lorempixel.com/570/320/" alt="video"/>
<img class="play-video" src="http://lorempixel.com/194/180/cat/" alt="play this video"/>
</div>
Do you mean like this? You were on the right track.
.play-video {
position: absolute;
top:20%;
height:inherit;
left:28%;
width:40%;
margin:0 auto;
}
http://jsfiddle.net/rgdrqbg4/7/

How to make Nivo Slider 100% height of the browser?

I am working on a website using Nivo Slider here: Website Demo
The problem is, the slider section won't do 100% height following the browser's height. How can I do that?
I have been inspecting and found this css code:
.nivoSlider {
position:relative;
width:100%;
height:auto;
overflow: hidden;
left:0;
margin-top:100px;
}
According to my CSS knowledge, we can change the height:auto; to height:100% to make the slider 100% height. Alas, it does not work!
What am I missing here?
UPDATE
I found that the image of the sliders is taking over the size, which is written here:
.nivoSlider img {
position: absolute;
top: 0px;
left: 0px;
max-width: none;
max-height: 100%; // I ADDED THIS TO MAKE 100% HEIGHT AND IT WORKS!!!
}
nevertheless, the image is being stretched now, how can I make the image cut, instead of stretched?
Look at the following class. You have assigned 900px height.
.nivoSlider:after {
content: '';
background: transparent url(../../images/parallax_slider/pattern.png) repeat top left;
position: absolute;
height: 900px;
left: 0;
top: 0;
width: 100%;
z-index: 5;
}

CSS Change Height

so I'm using the following code to change the contents of a div:
document.getElementById("boxed").innerHTML = document.getElementById("aboutus").innerHTML;
And the following is the CSS code behind the div "boxed":
.boxed
{
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
width: 90%;
min-height: 90%;
height:auto;
top:50%;
background-color:#F5F5F5;
}
How can I keep the div centered vertically while at the same time allowing for vertical resizing based on the content within? I don't want to use overflow; I want the div itself to change size when I click a button that executes the Javascript code.

Dynamic div height with respect to the window

The structure of my html is
<body>
<div class="divHead"></div>
<div class="divBody"></div>
</body>
What I want to do is give a fixed height to the divHeader, let's say 100px, and let the divBody expand to the end of the page exactly, without scroll bars for the browser.
So, if the user's window is 1000px, the body will be 900px and etc...
If i set the divBody height to 100%, it will take the 100% of the body, which means will create a scroll bar in the page.
Thanks in advance,
You could use absolute positioning: FIDDLE: http://jsfiddle.net/Z4vNN/2/
.divHead {
position: absolute;
top: 0;
left: 0;
right: 0;
height: 100px;
background-color: red;
}
.divBody {
position: absolute;
top: 100px;
left: 0;
right: 0;
bottom: 0;
background-color: green;
overflow: auto;
}
.divBody {
height: calc(100% - 100px);
}
#crush is certainly right, but if absolute positioning messes up other page elements you can avoid it by just having the elements displayed as blocks : http://jsfiddle.net/kF5wQ/
#header {
height:100px;
width:100%;
background:red;
display:block;
}
#container {
height:100%;
width:100%;
background:blue;
display:block;
overflow:visible;
}

Resources