I am trying to cut the top part of an image using css. But using overflow:hidden it automatically starts hiding it from the bottom to top, while I want to keep the bottom part but cut off the top. I see there are only x and y options for overflow.
So I tried it using clip, but this can only be applied when the position is set to absolute or fixed, which breaks my responsiveness (and site overall).
This is how one image looks:
And this is how I want it to look:
This is my html markup of one product tile:
<div class="col-md-3 col-lg-3 mb-80 mb-xs-40">
<div class="post-prev-img">
<a href="listing/product"><img src="cms/images/website/producten/categorien/product.jpg" alt="">
</a>
</div>
<div class="post-prev-title font-alt align-center">
product
</div>
<div class="post-prev-text align-center"></div>
<div class="post-prev-more align-center">
<i class="fa fa-info-circle"></i> Bekijk categorie
</div>
</div>
Is there an easy way to achieve this? I am not looking for big javascript methods, it would be great if this could be done with a couple of lines of css.
.post-prev-imgbefore img {
border: solid 1px red; /* TO SEE RESULT... */
}
.post-prev-img {
overflow: hidden;
}
.post-prev-img img {
border: solid 1px red; /* TO SEE RESULT... */
}
.post-prev-img a {
height: 120px; /* Your height... */
position: relative;
overflow: hidden;
display: block;
}
.post-prev-img a img {
position: absolute;
bottom: 0;
}
<h1>BEFORE:</h1>
<div class="col-md-3 col-lg-3 mb-80 mb-xs-40">
<div class="post-prev-imgbefore">
<a href="listing/product"><img src="https://embed.gyazo.com/eb965662ca8fabb1de523e61c16cfe83.png" alt="">
</a>
</div>
<div class="post-prev-title font-alt align-center">
product
</div>
<div class="post-prev-text align-center"></div>
<div class="post-prev-more align-center">
<i class="fa fa-info-circle"></i> Bekijk categorie
</div>
</div>
<h1>AFTER:</h1>
<div class="col-md-3 col-lg-3 mb-80 mb-xs-40">
<div class="post-prev-img">
<a href="listing/product"><img src="https://embed.gyazo.com/eb965662ca8fabb1de523e61c16cfe83.png" alt="">
</a>
</div>
<div class="post-prev-title font-alt align-center">
product
</div>
<div class="post-prev-text align-center"></div>
<div class="post-prev-more align-center">
<i class="fa fa-info-circle"></i> Bekijk categorie
</div>
</div>
you can still use overflow: hidden , make the image, position: absolute and set bottom: 0, this way the top will overflow but will be hidden. remember for absolute the parent should be position: relative.
so
.image_container {
overflow: hidden;
position: relative;
}
.image {
bottom: 0;
positon: relative
}
You could try another approach
Firstly you set a div with a defined measures and a
.myDiv{
width:50%;
height:300px;
background-image:url('url_here');
}
And this way you can play with the background properties as background-size. I am not sure if this could solve your problem but in my opinion is the easiest way to work with images.
What about transform the image inside the overflow:hidden-container, bro/sis? :)
.post-prev-img {
height: 250px;
overflow: hidden;
}
.post-prev-img img {
transform: translateY(-40px)
}
Bootply-link (you should use that, too)
Related
I have issues with my text over my images. The text I have is working when it's in desktop, at least on my computer resolution. But the issue is when I scale it back it doesn't keep up with the images so to say. Any idea how to do so or what is wrong?
HTML:
<div class="col-4 text-center image-capsule mx-auto">
<section class="posters-section">
<a href="/" class="movie-link pop">
<p class="poster-date">Test</p>
<img class="img-fluid poster" data-toggle="popover" src="${app.movie[0].poster}">
</a>
</section>
<h5 class="mt-3">${app.movie[0].title}</h5>
</div>
CSS:
.image-capsule {
width: 33%;
position: relative;
}
.posters-section {
position: relative;
}
.poster {
position: relative;
}
.poster-date {
margin: -5% 26%;
font-weight: bold;
z-index: 100;
background-color: #9c0000;
position: absolute;
width: 51%;
text-align: center;
}
I had an issue similar to this. I fixed this issue by using bootstraps text-center class on the text. This kept them centered in the div holding the picture which kept them together with a picture. Here is an example of what I did.
<div class="margin-intercept shrink-to-necessary-size">
<a href="350_project.html">
<img src="images/IMG_2579.JPG" width="350" height="350">
</a>
<h3 class="picwidth text-center">350 Project</h3>
</div>
This made the text stay centered under the image no matter how the screen shrunk.
First of all, I'm not really good with CSS but I'm trying to make the <img> height equals the width of it using only CSS.
I'm also using bootstrap as shown below, so the width of each column is responsive.
#import 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css';
.album .album_photo .photo_link img {
width: 100%;
}
<div class="album">
<div class="col-xs-3">
<div class="album_photo">
<a href="#" class="photo_link">
<img src="someurl" />
</a>
</div>
</div>
<div class="col-xs-3">
<div class="album_photo">
<a href="#" class="photo_link">
<img src="someurl" />
</a>
</div>
</div>
</div>
This is how it looks like right now:
and this is what I'm trying to achieve:
Take a look at this pen, you'll know how to do that using padding-bottom trick:
Code pen
.album_photo {
position: relative;
padding-bottom: 100%;
overflow: hidden;
}
img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
Consider using image as background in conjunction with background-size: cover.
I like this method. It makes the content of the column (in this case .album_photo) position: relative, sets the inner wrapper of the element ('.photo_link img') position: absolute; with a height of 100%. To keep the shape of the column, you use a pseudo-element that has a padding-top: 100%. The reason why this works is because percentage based padding is always relative to the width of the element. Thus with a padding of 100%, it will always be just as tall as it is wide. You can use the same method to create ratio based container sizes too (e.g. 3:1 ratio for slideshows having absolutely positioned slides). It's a neat trick.
#import url(https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css);
.album_photo {
position: relative;
overflow: hidden;
}
.photo_link img {
position: absolute;
top: 0;
left: 0;
}
.album_photo:after {
content: '';
display:inline-block;
vertical-align: top;
width: 100%;
height: 0;
padding-top: 100%;
}
<div class="container">
<div class="album">
<div class="col-xs-3">
<div class="album_photo">
<img src="//placehold.it/300x200" />
</div>
</div>
<div class="col-xs-3">
<div class="album_photo">
<img src="//placehold.it/300x200" />
</div>
</div>
<div class="col-xs-3">
<div class="album_photo">
<img src="//placehold.it/300x200" />
</div>
</div>
<div class="col-xs-3">
<div class="album_photo">
<img src="//placehold.it/300x200" />
</div>
</div>
</div>
</div>
try this
img{
aspect-ratio:1;
}
https://developer.mozilla.org/en-US/docs/Web/CSS/aspect-ratio
You can scale the images in any way, by simply applying a width & height. For example, You can say
.full-width-height { width: 100%; height: 100%; }
You can also use min-width, max-width, min-height and max-height.
However, you will run into aspect ratio issues with this.
You have two options that will keep aspect ratios in check using CSS and
.auto-width { width: auto; height: xxx; }
.auto-height { width: xxx; height: auto; }
Bootstrap provides a responsive class you can use as well. The class is img-responsive which you can read about here. This class is often used with center-block helper class.
you want your "album_photo" class to have a width and height of 100%, because those will fill the space in the parent element which has a class of "col-xs-3"
CSS:
.album_photo {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
set margin and padding to 0 and you will see that the img fits nicely in the parent element.
I have an image in which I need to put a button over, the problem is that I don't know how to place the button and automatically re-size and position it when making the browser smaller, right now I have the button in place, but when I re-size the browser to get smaller the button moves, I tried using percentages in the css buy doesn't work, what can I do?
<div id="discover" class="container-fluid">
<div class="row-fluid">
<div class="col-lg-12 col-sm-12 col-xs-12 col-md-12 withimg">
<img id="discoveryour" src="img/x.png" class="img-responsive">
</div>
</div>
<div class="row-fluid">
<div id="bttnimg" class="col-lg-12 col-sm-12 col-xs-12 col-md-12">
<form id="start" method="post" action="x.php">
<button class="btn-primary">text</button>
</form>
</div>
</div>
</div>
Css:
.withimg {
width: 100%;
overflow:hidden;
padding: 0px;
margin: 0px;
}
#discover{
position: relative;
}
#bttnimg{
float: left;
position: absolute;
left: 62%;
top: 25%;
max-width: 750px;
}
Ah, the good old "how to overlay stuff on top of a responsive image -- responsively" question.
A little tricky, but not too bad. The tricky bit is how to make the stuff's vertical position responsive when the image size changes.
Fear not, here's one simple way to do this:
HTML:
<div class="img-wrapper">
<img class="img-responsive"
src="http://lorempixel.com/output/people-q-c-1200-400-4.jpg">
<div class="img-overlay">
<button class="btn btn-md btn-success">Button</button>
</div>
</div>
CSS:
.img-wrapper {
position: relative;
}
.img-responsive {
width: 100%;
height: auto;
}
.img-overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
text-align: center;
}
.img-overlay:before {
content: ' ';
display: block;
/* adjust 'height' to position overlay content vertically */
height: 50%;
}
The img-overlay:before pseudo-class handles the vertical positioning job by pushing the img-overlay div down from the top of the image. In this example, the top of the button will always be 50% down the image (change the height: 50% attribute if you want the button higher or lower).
jsfiddle
To make the button size responsive to window width, you can create a new class for your button. Let's call it btn-responsive (this replaces btn-md in the example above). Then use #media queries to adjust the btn-responsive attributes for different window widths. Something like this:
.btn-responsive {
/* matches 'btn-md' */
padding: 10px 16px;
font-size: 18px;
line-height: 1.3333333;
border-radius: 6px;
}
#media (max-width:760px) {
/* matches 'btn-xs' */
.btn-responsive {
padding: 1px 5px;
font-size: 12px;
line-height: 1.5;
border-radius: 3px;
}
}
and so forth for other screen widths.
In case you're wondering how to do this with bootstrap 5 (like me), there are new classes that do the trick. For instance, I did this to put a button floating right top over the image (I also use font-awesome but you can use any text/icon you like for the button):
<div class="card">
<img class="card-img-top img-thumbnail" src="someimage.png" alt="alt text">
<div class="card-img-overlay">
<a href="#" class="btn btn-outline-warning btn-sm float-end"
data-bs-toggle="popover" data-bs-content="Edit image" data-bs-trigger="hover focus">
<i class="far fa-edit"></i>
</a>
</div>
<div class="card-body">
<h5 class="card-title">Some title</h5>
<p class="card-text">Some text</p>
</div>
</div>
Check out the official bootstrap documentation for more info.
I have to ask if there's a possibility to replace form tag into another DIV? Then you can just use position: absolute for button. I created fiddle to show how https://jsfiddle.net/1x1pjwk7/
First, here's an example I'm trying to achieve:
Here's the code I'm using to achieve that
HTML:
<div class="card demo-card-header-pic" style="margin:15px;">
<div style="background-image:url(https://pbs.twimg.com/profile_banners/6253282/1431474710/web_retina)" valign="bottom" class="card-header color-white no-border"></div>
<div class="avatar">
<img src="http://pbs.twimg.com/profile_images/2284174872/7df3h38zabcvjylnyfe3_bigger.png" style="border-radius:50px;">
</div>
<div class="card-content">
<div class="card-content-inner">
<div>
<p><b>****</b> wants to know what you think of him!</p>
</div>
<div>
<span class="text-muted" style="float:left;">Asked two days ago</span>
<span style="float:right;" class="text-muted"> 5 comments</span>
</div>
</div>
</div>
<div class="card-footer">Footer</div>
</div>
CSS:
.demo-card-header-pic .card-header
{
height: 40vw;
background-size: cover;
background-position: center;
}
.avatar
{
border-radius: 50px;
}
.card > .avatar
{
position: relative;
top: -40px;
left:5px;
}
.text-muted {
color: #777;
}
My question is how do I get rid of all the white space that is between the header of the card and the text? I tried using position:absolutebut that would mess up anytime the display was changed, even when using percentages.
A quick solution would be to give .card-content a negative margin-top value. I do agree that it's not the most elegant solution, but it get's the job done. Also adding a clear:both to the footer will prevent the overlay of both DIVs that you have at the moment
CSS:
.card-content{
margin-top: -40px;
}
.card-footer{
clear: both;
}
just remove margin form your main div and also if you want to remove body default white space then use following css on body
body{
margin:0;
padding:0;
}
So I have this issue with positioning and aligning thumbnails. I want to put fixed width and height on a div but as I am using Bootstrap, I've put col-md and col-xs for responsiveness, and now I can't figure out how to fit every image no matter how big it is to be a fixed width and height. Ive tried percentage and px, but then it loses its mobility and responsiveness and stays fixed on that width. Here is a picture of the problem http://postimg.org/image/n4tnblczd/ . I would be very thankfull on some advice how to resize big pictures to fixed width and heights but to remain it's responsiveness.
Before asking question suggest as giving your sample code. I think you want to know the process of html structure.
Use below html code for bootstrap support. col-md and col-sm in div class. img class will be "img-responsive" . It will get bootstrap.min.css
<div class="col-md-6 col-sm-6 col-xs-12 text-left">
<img src="/images/choose-us.png" class="img-responsive">
</div>
Use this I think it will solve your problem.here is screenshot I applied using my css with different image size.
Below snippet code not displaying exact style because of bootstrap css link.
.thumbnail{
padding: 0px;
border-radius: 0px;
position: relative;
border: 1px solid #222;
}
.thumbnail img{
height: 347px;
}
.drzac{
margin-top: 30px;
}
.overlay{
display: block;
transition: all 0.3s;
-webkit-transition: all 0.3s;
background-color: rgba(50, 200, 235, 0.5);
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
cursor: pointer;
font-size: 2em;
text-align: center;
}
<div class="col-xs-6 col-md-4">
<div class="thumbnail">
<img src="http://www.it4gen.com/wp-content/uploads/2013/02/learnindoorgrowing.com_-460x345.png" class="img-responsive">
<div class="centered"><i class="fa fa-search"></i></div>
</div>
</div>
<div class="col-xs-6 col-md-4">
<div class="thumbnail">
<img src="http://www.totalcableusa.com/images/choose-us.png">
<div class="centered"><i class="fa fa-search"></i></div>
</div>
</div>
<div class="col-xs-6 col-md-4">
<div class="thumbnail">
<img src="http://www.totalcableusa.com/images/choose-us.png">
<div class="centered"><i class="fa fa-search"></i></div>
</div>
</div>