I have a header image that stopped resizing after I placed it in a CSS wrapper. I specified the width of the wrapper, b/c I want the navigation to the right to be directly above the white space area below - flushed to the right.
How can I set the width of the wrapper in which I place an image but maintain the responsiveness (image responds to resizing)?
HERE's the URL; http://www.insidemarketblog.com/
Here's the code:
HTML
<div id="header">
<div class="wrap">
<span class="menu_control">≡ Menu</span>
<ul class="nav"><li class="page_item page-item-35">ABOUT US</li></ul>
<h1 id="site_title"><a href="http://www.insidemarketblog.com"><img id="thesis_logo_image" src="http://www.insidemarketblog.com/wp-content/uploads/2014/03/logo_header1.png" alt="Inside Market Strategy" width="400" height="87" title="click to go home" />
</a></h1>
</div>
</div>
CSS:
.wrap {
width: 1000px;
margin: 0 auto;
border: 1px solid #000;
position: relative;
}
You need to make the image flex too:
img {
display: block;
width: 100%;
height: auto;
}
I believe you have two issues here:
1st, Your .wrap is 1000px in width. please make it 100%
2nd, your img css should have a max-width: 400px; and width:100%
This way you will have your img exactly the way you want it.
Here is the css:
.wrap {
width: 100%;
margin: 0 auto;
border: 1px solid #000;
position: relative;
}
img {
width: 100%;
max-width: 400px;
height: auto;
}
See it in Action: http://jsfiddle.net/salota8550/59LKP/
Related
I want to display an image on the webpage. The image is long enough having fixed height. So, when someone checks responsiveness by decreasing screen-size it should remove the extra size from that div(which is happening).
I don't know the particular term. So, I will try to explain. it should be shown from the centre point. If image is "abcdefgh". Assume 'a','b'... all are grid number. The default behaviour when screen size will be relatively half is "abcd", but I want to display "cdef".
I gave overflow: hidden to remove extra image out of div. I tried margin-left, margin-right both auto. But, it is only required when the image is less than div size.
img {
display: block;
margin-left: auto;
margin-right: auto;
}
<!DOCTYPE html>
<html>
<body>
<div style="border:4px solid black; height:200px;overflow:hidden;text-align:center;">
<img src="https://mdbootstrap.com/img/Photos/Slides/img%20(130).jpg" alt="Paris" style="width:100%;height:200px;">
</div>
</body>
</html>
You can add object-fit: cover to 'crop' the image responsively
I used object-fit: cover;, this works.
img {
display: block;
margin-left: auto;
margin-right: auto;
object-fit: cover;
}
<!DOCTYPE html>
<html>
<body>
<div style="border:4px solid black; height:200px;overflow:hidden;text-align:center;">
<img src="https://mdbootstrap.com/img/Photos/Slides/img%20(130).jpg" alt="Paris" style="width:100%;height:200px;">
</div>
</body>
</html>
Only object-fit: cover will not work. It also needs width and height values. For best practice give height value. Please this value should not in percentage(%). And give image width: 100% and height: 100%. It will work.
.parentDiv {
border: 4px solid black;
width: 80%;
height: 250px;
margin: 0 auto;
}
img {
display: block;
object-fit: cover;
width: 100%;
height: 100%;
}
<div class="parentDiv">
<img src="https://mdbootstrap.com/img/Photos/Slides/img%20(130).jpg" alt="Paris"><div>
Please check this link: jsfiddle
You can set fixed size for image an use object-fit: cover in css.
.wrapper {
border: 4px solid black;
height: 200px;
overflow: hidden;
text-align: center;
}
.img {
display: block;
margin-left: auto;
margin-right: auto;
width: 100%;
object-fit: cover;
}
<div class="wrapper">
<img class="img" src="https://mdbootstrap.com/img/Photos/Slides/img%20(130).jpg" alt="Paris">
</div>
I have a banner image that's wider than it is tall. I have a container div that displays different sizes of images, and for the banner style, I need it to stretch and/or squash to fill the parent div in both directions. I've looked at object-fit:fill, but it only seems to stretch the image horizontally - it doesn't do anything about making it fill the div vertically.
A working example is here; code looks like this:
.tile {
position: relative;
float: left;
margin: 10px;
border: 4px solid green;
height: 400px;
}
.deal {
width: 342px;
background: #ffffff;
}
.tileImage.promo {
object-fit: fill;
}
<div class="tile deal hsNational active">
<img class="tileImage promo" src="https://cdn.pixabay.com/photo/2015/12/13/09/42/banner-1090835_960_720.jpg" height="200px">
</div>
What am I doing wrong? (I've tried the various values for object-fit, and none of them do what I need.) The image should be squished horizontally and stretched vertically to completely fill the area inside the green border.
Define dimensions for the image, then object-fit works:
.tile {
position: relative;
float: left;
margin: 10px;
border: 4px solid green;
height: 400px;
}
.deal {
width: 342px;
background: #ffffff;
}
.tileImage.promo {
object-fit: fill; /* also try 'contain' and 'cover' */
width: 100%;
height: 100%;
}
<div class="tile deal hsNational active">
<img class="tileImage promo" src="https://cdn.pixabay.com/photo/2015/12/13/09/42/banner-1090835_960_720.jpg">
</div>
More details here: Why isn't object-fit working in flexbox?
I have pure CSS image slider which I want to have positioned (margin:auto) with text underneath. Slider images are absolutely positioned as they are stacked. I can't figure out how to position divs around it all. I have content and wrapper divs with relative position. Image size should be responsive (therefore max-width:100%) but wrapper or content divs can be exact size. Or maybe they don't need to either?
This is what I am after:
And this is what I managed so far: www.jsfiddle.net/1qxxnxbf/1/
If your image slider is a carousel, you can't make it responsive without js. If you give your slider a height in the css, you can adjust it in the js to make it responsive.
The only other thing you can do is maintain an aspect ratio. So in your example you have 350x220 images. so If you get your padding-bottom on your .slider class to 62.857% (roughly 220/350) you get a variable height based on the width. If your width grows/shrinks, the height will grow/shrink as well.
http://jsfiddle.net/1qxxnxbf/2/
Edit: I just noticed that none of your code around the slider is responsive. Why are you trying to make the slider responsive?
Checkout this design
https://jsfiddle.net/jalayoza/zvy87dcv/9/
HTML code
<div class="content">content
<div class="wrapper">wrapper
<div class="slider">
<img src="https://placeimg.com/350/220/any" class="slide" alt="slide1">
<img src="https://placeimg.com/350/220/nature" class="slide" alt="slide2">
<img src="https://placeimg.com/350/220/abstract" class="slide" alt="slide3">
</div>
<!-- text should go underneath the image -->
<div class="text">
<div class="text_left">
left text
</div>
<div class="text_right">
right text
</div>
</div>
</div>
</div>
CSS code
.content {
width: 500px;
background: #fff;
margin: auto;
}
.wrapper {
max-width: 400px;
position: relative;
background: purple;
margin: auto;
padding:10px;
}
.slider {
margin: auto;
left: 0;
right: 0;
max-width: 100%;
position: relative;
padding-bottom: 62.857%;
}
.slide {
max-width: 400px;
margin: auto;
position: absolute;
opacity: 0.5;
width: 100%;
}
.text {
max-width: 100%;
position: absolute;
background: transperant;
opacity: 0.9;
bottom:10px;
width: 95%;
}
.text_left {
max-width: 50%;
background: #fff;
float: left;
text-align: left;
padding:5px;
}
.text_right {
max-width: 50%;
background: #fff;
float: right;
text-align: right;
padding:5px;
}
Hope you will like this design
I have looked around a lot for a solution to this but I can't seem to find one.
I have an image that I need to display within a certain set of dimensions. It must be no more than 100% of the width of the container: fine. But when I try to faux crop it to 50% of the container; it is scaled.
An example of the 100% width: http://i.stack.imgur.com/WTisJ.png
And an example of the problem when it is set to only 50% of the container: http://i.stack.imgur.com/J01sF.png
The code:
CSS:
.shopcontent{
margin-top: 120px;
}
.product{
margin: 2px;
display: block;
height: 250px;
width: 300px;
border: 2px solid #7f8c8d;
border-radius: 10px;
overflow: hidden;
}
.prodimg{
max-width: 100%;
max-height: 50%; (The problem line!)
border: 0px solid white;
border-radius: 10px;
}
.prodimgcont{
overflow: hidden;
}
HTML:
<div class="shopcontent">
<div class="product">
<span class="prodimgcont">
<img src="http://u.danmiz.net/xqz" class="prodimg"></img>
</span>
<p>This is a test</p>
</div>
</div>
Thanks for any help: I really have tried to find a way of doing this but nothing seems to work!
If I understand your problem correctly you could achieve the desired cropping effect like so:
HTML
<div class="img_container">
<div class="cropper">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQQWvNeCn17lshW3c9Z4PLXlTZe6GPf2oiNrLZQft1nPgld1WYb" />
</div>
</div>
CSS
.img_container {
width:300px;
height:250px;
}
.img_container .cropper {
width:50%;
height:50%;
overflow:hidden;
}
.img_container .cropper img {
width:200%;
height:200%;
}
You use the .cropper div to set the desired 50% width and add overflow:hidden, then set the child img tag to width:200% (100% of grandparent width)
Fiddle: http://jsfiddle.net/6hjL0pat/3/
EDIT:
Updated fiddle with your use case
First of all, your img tag should be self closing. so replace
<img src="http://u.danmiz.net/xqz" class="prodimg"></img>
with
<img src="http://u.danmiz.net/xqz" class="prodimg" />
To your problem. I'd advice you to give the dimensions to the container (change that spanto div by the way) and then assign your image as a background-image, because it is more useful for scaling images, especially with background-size: cover.
HTML
<div class="shopcontent">
<div class="product">
<div class="prodimgcont"></div>
<p>This is a test</p>
</div>
</div>
CSS
.shopcontent{
margin-top: 120px;
}
.product{
margin: 2px;
display: block;
height: 250px;
width: 300px;
border: 2px solid #7f8c8d;
border-radius: 10px;
overflow: hidden;
}
.prodimgcont{
display: block;
max-width: 100%;
height: 50%;
max-height: 50%;
border: 0px solid white;
border-radius: 10px;
background-image: url(http://u.danmiz.net/xqz);
background-size: cover;
overflow: hidden;
}
I created a JSfiddle to show you how to do it.
This is one way to do it.
Let me know if you absolutely need to use an img tag. There is a solution for that too. In any case: you need to assign the dimensions you want to the container of the image, not the image itself - because the image needs to be cut off.
Please note, that background-size: cover won't work in IE8 and lower, unless you use a polyfill.
I have a div that should always be in the center of the browser. now there's an image that will always be in the middle of the browser. but problem is that a div is 960px wide and but the picture is 1263px. how do I solve the problem? what I still need is dead as soon as the browser window smaller, should come scrollbars only at 960px. I know that I could theoretically solve anything, if I image Tell css as a background-image integrate the. but that does not work, unfortunately, because I really need the img tag
#header-bottom {
height: 1245px;
background: red;
width: 960px;
margin: 0 auto;
}
.header-bottom-wrapper {
position: relative;
width: 960px;
margin: auto;
height: 545px;
}
<div id="header-bottom">
<div class="header-bottom-wrapper">
<img src="http://dummyimage.com/1263x545/000/fff">
</div>
</div>
http://jsfiddle.net/UcLnD/
Try with this:
#header-bottom {
height: 1245px;
background: red;
width: 960px;
margin: 0 auto;
overflow: hidden;
}
.header-bottom-wrapper{
position: relative;
width: 960px;
margin: auto;
height: 545px;
}
.header-bottom-wrapper img {
margin-left: -152px;
}
Im not sure what you mean by not using Css for your fix. But does the image need to stay the same size? If you want the image to resize based upon browersize add this to your Css:
.header-bottom-wrapper img {width:100%;}
#header-bottom {
height: 1245px;
background: red;
width: 960px;
margin: 0 auto;
}
.header-bottom-wrapper {
position: relative;
width: 960px;
margin: auto;
height: 545px;
}
.header-bottom-wrapper img {width:100%;}
<div id="header-bottom">
<div class="header-bottom-wrapper">
<img src="http://dummyimage.com/1263x545/000/fff">
</div>
</div>
you can use negative margin to virtually reduce space needed by image.
<div class="clipimg">
<img src="imagetoowide-1000px" />
</div>
.clipimg {
width:500px;
text-align:center;
}
clipimg img {
margin:0 -50%;
}
Tune negative margin for both right/left and text-align.
Example here centers image and clips sides
examples : http://codepen.io/gc-nomade/pen/hjyEv/