Image card hover effect width issue - html

In the code below, I have an image card with a hover effect. On hover, I'd like the black box to cover the complete image by default. In the code below, the black box does not cover the complete image unless the title or description text wraps two a second line.
What is the best way to get the black box to fill the complete width of the parent element ".page-card" even without content inside of it? I have tried:
width: 100%, flex direction, clears, table hacks, and many other tips I found without any luck. Any help would be appreciated.
Quick note: for .page-card figcaption I'm using an image on the site so the cover properties are needed.
.page-card {
overflow: hidden;
text-align: left;
margin-top: 30px;
}
.page-card a {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 2;
}
.page-card * {
-webkit-box-sizing: border-box;
box-sizing: border-box;
-webkit-transition: all 0.35s ease;
transition: all 0.35s ease;
}
.page-card img {
object-fit: cover;
width: 100%;
}
.page-card figcaption {
position: absolute;
top: calc(77%);
height: 100%;
background-color: black;
/* the site uses an image here I filled it with black for the code snip */
background-size: cover;
border-top: 1px solid #333;
margin-right: 15px;
padding: 35px 25px 65px;
color: white;
}
.page-card:hover figcaption,
.page-card.hover figcaption {
top: 0px;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<!--Example 1 not spanning dark hover color 100% width-->
<div class="row d-flex flex-row">
<figure class="col-md-6 col-xl-4 page-card">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/331810/sample45.jpg" width="880" height="640">
<figcaption>
<h1>Title</h1>
<p>Descrition</p>
<button type="button" class="btn btn-outline-light itm-space">Learn More</button>
</figcaption>link
</figure>
</div>
<!--Example 2 does cover 100% width when text wraps to a second line-->
<div class="row d-flex flex-row">
<figure class="col-md-6 col-xl-4 page-card">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/331810/sample45.jpg" width="880" height="640">
<figcaption>
<h1>Title</h1>
<p>Descrition Text that continues to wrap to a second line and fills the complete width like I want it to by default</p>
<button type="button" class="btn btn-outline-light itm-space">Learn More</button>
</figcaption>
</figure>
</div>
</div>

You need to give to give to the "hover" div width :100%:
.page-card figcaption {width:100%}
When an element is given position:absolute is no longer a "block" element with default widh 100%.
Once you do it, you may notice it takes more room than the image below. That is becouse the image parent has padding and you are not using the rule box-sizing:border-box If you add this to the top of you css sheet it should solve your problem.
* {box-sizing:border-box}

Adding:
.page-card figcaption {width:100%}
resolved the width issue but created 30px of overflow because the parent elements padding was not being respected with absolute positioning.
.page-card figcaption {clip-path: inset(0px 30px 0px 0px)}
The code above will clip the overflow.

Related

Bootstrap button is overlapping text

I'm making a card/grid layout using wells in bootstrap. My problem is that the button needs to always be positioned on the bottom of the well at all times with the well having a fixed height. The button is at the bottom but is also overlapping the text.
body {
background-color: #5C67B6;
}
html,
body {
height: 100%;
padding-top: 70px;
}
.btn-purple {
color: #fff;
background-color: #5C67B6;
border-color: #5C67B6;
position: absolute;
bottom: 30px;
left: 50%;
margin-left: -140px;
}
.btn-purple:hover,
.btn-purple:focus,
.btn-purple:active,
.btn-purple.active,
.open>.dropdown-toggle.btn-purple {
color: #fff;
background-color: #4b5496;
border-color: #4b5496;
}
.customClass {
width: 700px;
max-width: 100%;
margin: 0px auto;
}
.well {
min-height: 280px;
height: auto;
overflow-wrap: break-word;
word-wrap: break-word;
hyphens: auto;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container content-sm customClass">
<div class="row">
<div class="col-sm-6 col-xs-12">
<div class="well">
<img class="center-block" src="https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon#2.png" style="border-radius: 50%;" height="80" width="80">
<h3 style="text-align: center;">Test123</h3> <p>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</p>
<i class="fa fa-sign-in" aria-hidden="true"></i> Join server!
</div>
</div>
</div>
</div>
Make sure to click show full page. The button is overlapping some of the text. What would I need to do to make it so where the text positions itself so where it avoids contact with the button? Changing the height fixes it somewhat, but it needs to stay at this height.
If you wanted each of your well class height to be fixed, You need to move each of your btn-purple class outside of your well class as well. Also, To retain the look of your current layout, Place some of your css property from your well class to your col-sm-12 class (parent container)
Here is a sample jsfiddle to guide you: https://jsfiddle.net/u7ecv316/1/
Note: I've place a col-item class in col-sm-12 then place the btn-purple outside of well class. I've also override the css properties of well class too.
Hope this will guide you well

How to fit IMG in parent DIV where its height is not set?

I have this situation: I want to make a IMG height to be fit with its parent DIV where no height is set. This is the sample code:
.box_NewsList {
width: 100%;
background: #ffa;
overflow: hidden;
display: inline-block;
}
.box_NewsList>img {
height: 100%;
display: inline-block;
}
.box_NewsPreview {
padding: 15px;
width: auto;
}
.box_NewsPreview>.tit_News {
font-size: 1.5rem;
line-height: 1.5rem;
position: relative;
margin: -15px 0 15px;
padding: 15px 0 0;
background: transparent url(../imgs/main_menu_hover.png) no-repeat top left;
}
<div class="box_NewsList">
<img class="pull-left" src="mypicture.jpg">
<div class="box_NewsPreview">
<h1 class="tit_News">MyTitle</h1>
<div class="txt_Abstract">
<p>Long text abstract here</p>
</div>
<button class="btn btn-default btn-rounded pull-right">READ</button>
</div>
<div class="clear"></div>
</div>
How can I make the img height to fit the height of div with box_NewsPreview class?
.box_NewsPreview>.txt_Abstract p{color:#7e7e7e;font-family:Roboto, sans-serif;font-size:1rem;font-weight:300;text-align:justify;}
If I add a height value in box_NewsList like height:300px; it works fine.
If I set height:auto, height:initial, height:inherit or I don't add any height value in that class then I get the IMG in its full size instead of resizing in its parent height.
I think the easiest way to acheive what you want is to use a little jQuery. I dont think it is possible with pure CSS
I have made an example where i set position: relative; on .box_NewsList and position: absolute; on .box_NewsList>img
and the this little script to loop through the images and give padding to the text:
$('.box_NewsList').each(function() {
var imageWidth = $(this).find('img').width();
$(this).find('.box_NewsPreview').css('padding-left', imageWidth + 15);
});
Here is a fiddle
try
<div class="box_NewsList">
<div class="box_NewsPreview">
<img class="pull-left" src="mypicture.jpg" stretch="fill">
<h1 class="tit_News">MyTitle</h1>
<div class="txt_Abstract"><p>Long text abstract here</p></div>
<button class="btn btn-default btn-rounded pull-right">READ</button>
</div>
<div class="clear"></div>
</div>
It looks like <img> was inside news_list not news_preview.
I added stretch to the img, so no matter what it will always stretch to the size of the div :)

CSS auto height and width suggestion

I have an image and div. I want to show the overlay div when hovering on the main image. Basically, the overlay div will be hidden and it will be shown only on hovering. The div should be same height and width like the image <div class="image">.
HTML:
<div class="image">
<figure><img src="one.jpg"></figure>
</div>
<div class="overlay">
<p class="description">
Some description goes here
</p>
</div>
If I managed to understand your question, you want to make an element appear over another one and to cover it fully. Here's how I would do it. Put the overlay inside a div with the image to force them to have the same size and make the overlay visible when the parent is hovered.
HTML
<div class="hoverable fillme" id="example">
<figure>
<img src="one.jpg" alt="one" />
</figure>
<div class="overlay">Some description goes here</div>
</div>
CSS
#example {
width: 200px;
height: 200px;
}
.fillme {
position: absolute;
}
.fillme>* {
position: absolute;
top: 0px;
left: 0px;
}
.fillme *{
width: 100%;
height: 100%;
margin: 0px;
padding; 0px;
}
.overlay {
visibility: hidden;
background-color: #5555FF;
z-index: 100;
}
.hoverable:hover .overlay{
visibility: visible;
}
http://jsfiddle.net/do8byofd/1
If you want to do it with the exact HTML structure you have, you can't. There's no way to set the overlay to have the size of the element before it without some JavaScript.

Link width on div with background image

I have the following html:
<div class="container">
<a href="url here">
<div class="logo">
<h1>Name</h1>
</div>
</a>
</div>
and css:
.container {
width: 20%;
}
.logo {
background: url(images/ui-sprite.svg) no-repeat 0 0;
text-indent: -9999px;
height: 30px;
width: 150px;
margin: 25px 0;
}
The issue I have is with linking the logo (background image). At the moment the link area you can hover over is the full width of the container div, despite the fact that the logo class has a defined width. Any ideas here on best practice with linking of background images?
Thanks
Found this to be ultimately useful, and less markup too!
http://ran.ge/2012/04/03/css-trick-turning-a-background-image-into-a-clickable-link-take-2/

Fixed image in a div

I'm trying to make 3 <div> boxes with a fixed height and width of 500px;
I'm trying to take 3 different images and have them fit inside the <div> boxes
I've tried to fit an image off tumblr lets say, or imgur and most images will fit to a random size, but some don't stretch the full of the <div> box.
So I have;
<div class="row">
<div class="col-md-4 portfolio-item">
<div class="caption">
<div class="caption-content">
<i class="fa fa-search-plus fa-2x">tstmkr</i>
</div>
</div>
<img src="http://goo.gl/2GDUPT" class="img-responsive" alt="" />
<!-- </a> -->
</div>
</div>
#portfolio .portfolio-item .portfolio-link .caption .caption-content {
position: absolute;
top: 50%;
width: 100%;
height: 20px;
margin-top: -12px;
text-align: center;
font-size: 20px;
color: #fff;
}
#portfolio .portfolio-item .portfolio-link .caption .caption-content i {
margin-top: -12px;
}
Don't put the image in the <div> directly.
Put it as a background-image, than set background-size: cover;
This way, the image will stretch to cover full <div> box, as you want.
You need to apply width:100% to your img tag if you want it to take up 100% of its parent.
style="width:100%;"
Or give it an id and create a width:100% for it in the style sheet.
http://jsfiddle.net/jGyr2/
Is that what you are looking for?
Based on what you have asked it actually sounds like this fiddle here demonstrates what you are wanting
http://jsfiddle.net/jGyr2/1/