image keeps sliding out of frame - html

I have an image inside a div container that's inside another container like so:
<div className='container'>
<div className='imageContainer'>
<img src='whatever' />
</div>
</div>
I want the imageContainer to stay within the container, but keep the image inside that container to the same size.
I added css so now when the screen's width decreases, the image slides out of frame.
.imageContainer {
border: 1px solid black;
width: 100%;
overflow: hidden;
}
Before I added this css the image would shrink in size to fit inside the imageContainer which is fit inside the outer container.
Is it possible to have the image stay in place inside the container and not shrink in size or width, rather just be cut off on one side?
For example if I would decrease the screen width the image's lefthand side would stay in place while it's righthand side is continuously cropped.
I couldn't find anything to help with my particular css issue, so if anybody knows a solution that would be greatly appreciated.
.imageContainer {
border: 1px solid black;
width: 100%;
overflow: hidden;
}
<div class='container'>
<div class='imageContainer'>
<img src='https://via.placeholder.com/2560x1440' />
</div>
</div>

Check if you added your overflow: hidden in correct place
.imageContainer {
border: 2px solid purple;
padding: .3rem;
width: 100%;
}
.container {
max-width: 600px;
border: 2px solid red;
padding: .3rem;
}
.container--crop {
overflow: hidden; /* add overflow: hidden to upper parent container */
}
<p>Not cropped</p>
<div class='container'>
<div class='imageContainer'>
<img src='https://dummyimage.com/700x400/000/fff' />
</div>
</div>
<p>Cropped container</p>
<div class='container container--crop'>
<div class='imageContainer'>
<img src='https://dummyimage.com/700x400/000/fff' />
</div>
</div>

Add height to your css:
.imageContainer
{
border: 2px solid black;
width: 100%;
height:100px;
overflow: hidden;
}
Check the link: jsfiddle.net/majidliaquat/zfqjxd35/8

Related

Css cut right side of an image

I have a div with a width of ~ 200px and a height of 145px, inside that div I place an Image which has a height of 145px but a width of 210px, how can I cut 10px from the right side of the Image so that the Image fits into the Content of the div?
Use overflow:hidden for the div.The part of image portion ouside the div will be not be visible
<div style="width:200px;height:145px;overflow:hidden;border: 1px solid green;">
<img src="http://via.placeholder.com/210x145" style="width:210px; height:145px;border: 1px solid red;">
</div>
.container {
width: 200px;
height: 145px;
overflow: hidden;
}
<div class="container">
<img src="https://images-na.ssl-images-amazon.com/images/M/MV5BMzU5ODI0NDE4MF5BMl5BanBnXkFtZTYwMTE2MTI2._V1_SY154_SX210_AL_.jpg">
</div>
For Fit Image:
img {
width:100%;
//dont need height
}
For Cut Image
div {
overflow:hidden;
}
.cut-text {
text-overflow: ellipsis;
overflow: hidden;
width:25px;
height: 1.2em;
white-space: nowrap;
}
<h2>text-overflow: ellipsis:</h2>
<div class="cut-text">Hello world!</div>

How to make "child" div DON'T overflow by itself and uses it's parent div's padding to render?

First, my codes
HTML:
<div class="div parent">
Title
<div class="div child">
<div class="overflowed">
</div>
</div>
</div>
CSS:
.div {
border: 1px solid #000000;
padding: 10px;
overflow: auto;
}
.parent {
max-height: 100px;
}
.overflowed {
min-height: 150px;
}
Sorry I am not good at describe things about webpage designing, so if I describe something incorrectly, please tell me, thanks :)
How to make child div render like this, and it's bottom border always have margin to it's parent's bottom border?
By the way, "Title" in HTML line 2 will change it's height by different screen resolution, so it can't be limited by max-height property.
jsFiddle here: https://jsfiddle.net/dj3ydshf/
You where almost there. I think this is what you are looking for:
.div {
border: 1px solid #000000;
padding: 10px;
overflow: auto;
}
.parent {
max-height: 200px;
}
/* set overflow y-scroll */
/* and give this element a max-height or height */
.child {
overflow: y-scroll;
max-height: 50px;
}
<div class="div parent">
tuitit
<div class="limit">
<div class="div child">
SSSS
<br> SSSS
<br> SSSS
<br> SSSS
<br> SSSS
<br> SSSS
<br>
</div>
</div>
</div>

Scrollable text over image HTML/CSS

Currently I can not find a solution that is responsive and scrollable to put text on an image. I need the height to be flexible and the width at 100%. I tried to use position:relative; and css background images with no luck. When I use position: relative; there is a space at the top of the image and the only way to delete it is negative margins which I think is not sustainable it there are multiple posts. css backgrounds does not show the full image unless you set dimensions and when is responsive you cant set dimensions. I dont think I can use position absolute because it would not scroll. so I dont not know what to use.
I have this HTML code here:
<div class="post">
<span><a>Posted By Adam</a></span>
<img width="100%" src="uimg/adam-levine-600.jpg">
</div>
Use position: absolute; and add a spacer for the nav:
http://jsfiddle.net/ryanpcmcquen/p3bes5xq/
.nav {
height: 100px;
width: 100%;
position: fixed;
background-color: #21A7F0;
text-align: center;
z-index: 10;
color: #ffffff;
}
.spacer {
height: 105px;
}
.post span {
position: absolute;
color: #ffffff;
text-shadow: 1px 1px 2px #000000;
}
.post img {
width: 100%;
}
<div class="nav">nav bar</div>
<div class="spacer"></div>
<div class="post"> <span><a>Posted By Adam</a></span>
<img src="//fillmurray.com/880/450" />
</div>
<div class="post"> <span><a>Posted By Adam</a></span>
<img src="//fillmurray.com/880/260" />
</div>
<div class="post"> <span><a>Posted By Adam</a></span>
<img src="//fillmurray.com/880/194" />
</div>

how to make a div responsive with respect to the image

Hi I am trying to develop a web page. In that I am supposed to place an image at the center of the page. Below that image I placed an div so that by clicking on that div certain items will be displayed.My problem is that when the size of the window reduced the image will become responsive,but not that div. I want to make both of them responsive.Here is my code
index.html
<div class="container">
<div class="row">
<div class="col-lg-12" style="top:-125px;">
<img id="i1" class="img-responsive" src="img/2.png" height="600" width="600" alt="">
<div style="padding-left:45%;top:-250px;">
<div id="triangle-up"></div>
</div>
</div>
</div>
</div>
this is my css
#triangle-up {
position: absolute;
bottom:0;
left: 46%;
padding: 5px;
width: auto;
height: auto;
border-left: 60px solid transparent;
border-right: 60px solid transparent;
border-bottom: 67px solid grey;
}
.container
{
position: relative;
}
Please help me to solve this issue..
Use CSS to set up width of your div to 100% and max-width as pixels amount that you don't want your div to grow any larger than.

More CSS woes: how to stack divs inside another div, and have them all behave?

Fiddle here: http://jsfiddle.net/csaltyj/mbnWm/
<style type="text/css">
#container {
border: 2px solid #000;
position: absolute;
width: 20em;
}
.box {
background: transparent;
position: absolute;
border: 1px solid #0f0;
}
</style>
<div id="container">
<div class="box">
<p>X</p>
<p>Taller than the other two.</p>
</div>
<div class="box">
<p> Y</p>
</div>
<div class="box">
<p> Z</p>
</div>
</div>
This is not working. They overlap fine, but there are issues. The goal is to:
Get the #container to properly wrap around the children divs.
Have the .box divs fill (width & height) the parent #container (so the green borders should reach all the way out to the thick black border).
This must be possible, I'm just having a hard time with positioning. (that and floats seem to be the toughest parts of CSS)
Thanks for any help.
The problem you have here is that anything that is position: absolute; is removed from flow. Thus, #container can never contain the .boxes. In this cause you will need to set height and width on #container and make sure the .boxes can never expand beyond it. You requested they fill the #container, so I've done that here: http://jsfiddle.net/X3EJ6/
Note though that because width and height are set to 100% the borders will not work correctly. You will need to set explicit values or use box-sizing and set it to border-box (this is not support in IE < 8).
<style type="text/css">
#container {
border: 2px solid #000;
position: absolute;
width: 20em;
height: 10ex;
overflow: hidden;
}
.box {
background: transparent;
position: absolute;
border: 1px solid #0f0;
width: 100%;
height: 100%;
}
</style>
<div id="container">
<div class="box">
<p>X</p>
<p>Taller than the other two.</p>
</div>
<div class="box">
<p> Y</p>
</div>
<div class="box">
<p> Z</p>
</div>
</div>
How to make children auto fit parent's width only with CSS?