Hiding overflow on a column with gutters - html

I am trying to set up a grid of thumbnails for blog posts using Bootstrap 4.
The size of the columns are col-md-6. Inside each of the columns is an anchor with a background photo, and a black -> transparent gradient overlay.
It all works fine, however, the gradient overlay is expanding past the width of the container, as you can see from the image below.
Markup:
<div class="container homeSection">
<div class="row">
<div class="col-md-6 dualBlogCallout">
<a href="#">
<div class="img-holder border-radius-15">
<div class="dualGradient"></div>
<img src="assets/img/beachPlaceholder.png" class="img-fluid w-100" alt="Blog Alt"/>
</div>
</a>
</div>
<div class="col-md-6 dualBlogCallout">
<a href="#">
<div class="img-holder border-radius-15">
<div class="dualGradient"></div>
<img src="assets/img/beachPlaceholder.png" class="img-fluid w-100" alt="Blog Alt"/>
</div>
</a>
</div>
</div>
</div>
CSS:
.dualBlogCallout{
color: white;
position: relative;
width: 100%;
bottom: 0;
left: 0;
z-index: 5;
}
.dualBlogCallout a{
overflow: hidden;
}
.dualGradient{
background-image: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,1));
position: absolute;
left: 0;
bottom: 0;
opacity: 1;
width: 100%;
height: 300px;
pointer-events: none;
z-index: 1;
}
Here is my desired result:
How can I get the absolutely positioned gradient to just remain within anchor with no overflow, and without using bootstrap 4 no-gutter class?

Add a rule in your css:
.img-holder { position: relative; }
I think your issue is that .dualGradient is positioned absolutely, but the nearest parent that has a position set is the .dualBlogCallout.
By default, anything that has position: absolute will traverse up the markup to find the nearest element that has a position explicitly set.

position: relative; is missing on your img-holder class. Here is a solution displaying your code.
Note: I added the border radius class because that was not included in the original post
.img-holder {
position: relative;
}
.dualBlogCallout{
color: white;
position: relative;
width: 100%;
bottom: 0;
left: 0;
z-index: 5;
}
.dualBlogCallout a{
overflow: hidden;
}
.dualGradient{
background-image: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,1));
position: absolute;
left: 0;
bottom: 0;
opacity: 1;
width: 100%;
height: 300px;
pointer-events: none;
z-index: 1;
}
.border-radius-15 {
border-radius: 15px;
overflow: hidden;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container homeSection">
<br><br>
<div class="row">
<div class="col-md-6 dualBlogCallout">
<a href="#">
<div class="img-holder border-radius-15">
<div class="dualGradient"></div>
<img src="https://via.placeholder.com/200x100" class="img-fluid w-100" alt="Blog Alt"/>
</div>
</a>
</div>
<div class="col-md-6 dualBlogCallout">
<a href="#">
<div class="img-holder border-radius-15">
<div class="dualGradient"></div>
<img src="https://via.placeholder.com/200x100" class="img-fluid w-100" alt="Blog Alt"/>
</div>
</a>
</div>
</div>
</div>

Related

Display content in the card when hover

I have a card item as you see in the picture, opacity is 0.5:
When I hover I want to display some information on it like in the picture again:
So here is my example;
.card-img {
width: 100%;
border-radius: calc(0.3rem - 0px);
}
.card-img-top {
width: 100%;
border-radius: 32px;
opacity: 0.5;
}
.card-img-top:hover {
opacity: 1;
}
<div class="col-md-6">
<div class="card">
<a href="#">
<img class="card-img-top img-raised" src="img/banner-1.png" alt="Open Project 1">
<div class="banner-content">
Description
</div>
<a class="mb-2 mt-2 text-center small-xl" href="#">Check More Details</a>
</a>
</div>
</div>
So what I am trying to achieve in this example, when I hover I want to display Description (banner-content) and I want to set the opacity to 1 which I am already doing.
You can use + selector wicth select the adjacent sibling. More on mdn
.card{
position:relative;
}
.card-img {
width: 100%;
max-width:150px;
border-radius: calc(0.3rem - 0px);
}
.card-img-top {
border-radius: 32px;
opacity: 0.5;
width:150px;
}
.card-img-top:hover {
opacity: 1;
}
.banner-content{
position:absolute;
top:0;
left:0;
display:none;
}
.card-img-top:hover + .banner-content{display:block;}
<div class="col-md-6">
<div class="card">
<a href="#">
<img class="card-img-top img-raised" src="https://via.placeholder.com/50" alt="Open Project 1">
<div class="banner-content">
Description
</div>
<a class="mb-2 mt-2 text-center small-xl" href="#">Check More Details</a>
</a>
</div>
</div>
Step 1: I make a .top-layout class with opacity: 0 to keep it hide by default.
Step 2: Use .card:hover .top-layout selector in CSS to set what style you want when the card item is hover.
.card {
width: 100%;
border-radius: calc(0.3rem - 0px);
}
.card:hover .top-layout {
opacity: 0.5 !important;
}
.top-layout {
opacity: 0;
position: absolute;
bottom: 0;
text-align: center;
width: 100%;
}
.card-img-top {
width: 100%;
border-radius: 32px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="col-md-6">
<div class="card">
<a href="#">
<img class="card-img-top img-raised" src="https://image.freepik.com/free-vector/comic-colorful-frame-background_52683-71995.jpg" alt="Open Project 1">
<div class="top-layout">
<div class="banner-content">
Description
</div>
<a class="mb-2 mt-2 text-center small-xl" href="#">Check More Details</a>
</div>
</a>
</div>
</div>
Put a Adjacent Sibling Selector when you hover on img and display the content .
+ is used here which selects the first .banner-content element that is placed immediately after .card-img-top element .
Find more info here about combinators
.card {
position: relative;
}
.banner-content {
position: absolute;
top: 20px;
left: 20px;
display:none;
}
.card-img {
width: 100%;
border-radius: calc(0.3rem - 0px);
}
.card-img-top {
width: 400px;
height:200px;
border-radius: 32px;
opacity: 0.5;
}
.card-img-top:hover {
opacity: 1;
}
.card-img-top:hover + .banner-content {
display: block;
}
<div class="col-md-6">
<div class="card">
<a href="#">
<img class="card-img-top img-raised" src="https://pixy.org/src/477/4774988.jpg" alt="Open Project 1">
<div class="banner-content">
I am a new coder.<br> Happy to meet : )
</div><br>
<a class="mb-2 mt-2 text-center small-xl" href="#">Check More Details</a>
</a>
</div>
</div>

How do I get one div on top of my other div?

I'm trying to get the div with the product name amount price and total to the top of the div it's nestled in, but changing the position isn't working. Stuff like vertical alignment didn't work for me either. I made a screenshot of the page, the buttons are in the right place, it's just the sort of table that has to move to the top of the screen. This has to contain all kinds of products later on.
this is the html:
<div class="checkout">
<div class="container-fluid" style="position: absolute; bottom: 0;">
<!-- Added products overview-->
<div class="checkoutTable">
<div class="row">
<div class="col-4">Product Name</div>
<div class="col-2">Amount</div>
<div class="col-3">Price</div>
<div class="col-3 ">Total</div>
</div>
<hr style="background-color:white;">
<div class="row">
<div class="col-4">Product Name</div>
<div class="col-2">Amount</div>
<div class="col-3">Price</div>
<div class="col-3 ">Total</div>
</div>
</div>
<!-- -->
<!-- Buttons -->
<div class="row">
<a class="checkoutBtn" href="">
<div class="col-12 checkoutBtn">
<i class="fa fa-shopping-cart"></i> Checkout
</div>
</a>
</div>
<div class="row">
<a class="addDiscountBtn" href="#">
<div class="col-6-xs addDiscountBtn">
% Add Discount
</div>
</a>
<a class="cancelBtn" href="#">
<div class="col-6-xs cancelBtn">
<i class="fa fa-ban"></i> Cancel
</div>
</a>
</div>
</div>
</div>
This is the css:
.checkout{
background-color: #22303e;
height: calc(100vh - 50px);
color: white;
font-size: 13px;
}
.checkoutBtn{
background-color: #0090e3; height: 50px;
text-align: center;
line-height: 50px
}
.addDiscountBtn{
background-color:#f8ac59; height: 50px;
text-align: center;
line-height: 50px
}
.cancelBtn{
background-color: #ed5565; height: 50px;
text-align: center;
line-height: 50px
}
a.checkoutBtn{
width: 100%;
color: white;
}
a.addDiscountBtn{
width: 50%;
color: white;
}
a.cancelBtn{
width: 50%;
color: white;
}
a:hover{
text-decoration: none;
opacity: 0.9;
}
.checkoutTable{
vertical-align:top;
}
For container-fluid, do not use any inline styling like you are using style="position: absolute; bottom: 0;"
Example
<div class="checkout">
<div class="container-fluid"></div>
You are placing your div
<div class="checkoutTable">
in parent div
<div class="container-fluid" style="position: absolute; bottom: 0;">
And here the style= "bottom: 0;" that is making everything in it to go at the bottom of the page.
<div class="checkoutTable">
<!--content-->
</div>
<div class="container-fluid" style="position: absolute; bottom: 0;">
<!--content-->
</div>
there is more than one solution for this issue
you can add position like
.Class {
position : absolute;
top : 0;
}
.Class {
position :fixed;
top : 0;
}

How to vertically fix navigation arrows?

I have a modal album which shows images with different sizes. My pbolem is that how to style the navigation arrows, so that they appear at the middle of the page, no matter what is the size of the image. Here is my code:
<div class="row img-box">
<div class="col-1">
<span #click="nextImg(-1)" class="nav-arrow">❮</span>
</div>
<div class="col-9">
<h1>Modal comes here</h1>
<img class="img-fluid modal-img" :src=" getImgUrl(currentMediaUrl)">
</div>
<div class="col-1">
<span #click="nextImg(1)" class="nav-arrow">❯</span>
</div>
</div>
And here is the relevant css:
.modal-img {
max-height: 1080px;
}
.img-box {
display: flex;
align-items:center;
}
.nav-arrow {
font-size: 3em;
position: absolute;
top: 50%;
}
But whatever I tweak the CSS can not get the desired effect. Hence the question.
Use position fixed
.modal-img {
max-height: 1080px;
}
.img-box {
display: flex;
align-items:center;
justify-content: center;
}
.nav-arrow {
font-size: 3em;
position: fixed;
top: 120px;
}
.nav-left {
left: 10px;
}
.nav-right {
right: 10px;
}
<div class="row img-box">
<div class="col-1">
<span #click="nextImg(-1)" class="nav-arrow nav-left">❮</span>
</div>
<div class="col-9">
<h1>Modal comes here</h1>
<img class="img-fluid modal-img" src="https://via.placeholder.com/500C/O https://placeholder.com/">
</div>
<div class="col-1">
<span #click="nextImg(1)" class="nav-arrow nav-right">❯</span>
</div>
</div>
you need to apply transform: translateY(-50%) on arrow container's, in order to put the arrows in the center.
.nav-arrow {
font-size: 3em;
position: absolute;
top: 50%;
transform: translateY(-50%)
}
or simply, remove position: absolute; top: 50%;
Does this works for you? I have added the bootstrap class align-items-center and some padding to spans
.modal-img {
max-height: 1080px;
}
.nav-arrow {
font-size: 3em;
position: relative;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row img-box align-items-center">
<div class="col-1 ">
<span #click="nextImg(-1)" class="nav-arrow pt-5 d-inline-block">❮</span>
</div>
<div class="col-9 text-center">
<h1>Modal comes here</h1>
<img class="img-fluid modal-img" src="https://via.placeholder.com/100/O https://placeholder.com/">
</div>
<div class="col-1">
<span #click="nextImg(1)" class="nav-arrow pt-5 d-inline-block">❯</span>
</div>
</div>

Portfolio hover overlay not staying in image size

For my portfolio site I am making I have it so when you hover over the portfolio image it overlays the title and category. My problem is the overlay section is picking up the margin and padding for the spacing of the images in the grid. I cant get it to be whatever the portfolio image size is without removing the gutter between the images.
Example below:
Not sure how to fix this and any help would be appreciated.
.thumbnail {
padding: 0px !important;
margin-bottom: 25px;
border: none;
border-radius: 0;
display: block;
}
.thumbnail img {
width: 100%;
height: 100%;
margin-bottom: 0px;
display: block;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
padding: 0px 0px 0px 0px;
transition: .5s ease;
background-color: rgba(136, 24, 38, 0.6);
}
.thumbnail:hover .overlay {
opacity: 1;
height: 100%;
width: 100%;
}
.text {
color: white;
font-size: 20px;
position: absolute;
width: 70%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<section id="work" class="bg-grey">
<div class="container-fluid text-center">
<h2>MY WORK</h2>
<!--<h4>What we have created</h4>-->
<div class="row text-center">
<div class="col-md-4 col-sm-6 col-xs-12">
<a href="http://www.google.com/">
<div class="thumbnail">
<img src="images/portfolio-img1.jpg" alt="PORTFOLIO NAME">
<div class="overlay">
<div class="text">
<h4>PORTFOLIO NAME</h4>
<p>category</p>
</div>
</div>
</div>
</a>
</div>
<div class="col-md-4 col-sm-6 col-xs-12">
<a href="http://www.google.com/">
<div class="thumbnail">
<img src="images/portfolio-img1.jpg" alt="PORTFOLIO NAME">
<div class="overlay">
<div class="text">
<h4>PORTFOLIO NAME</h4>
<p>category</p>
</div>
</div>
</div>
</a>
</div>
<div class="col-md-4 col-sm-6 col-xs-12">
<a href="http://www.google.com/">
<div class="thumbnail">
<img src="images/portfolio-img1.jpg" alt="PORTFOLIO NAME">
<div class="overlay">
<div class="text">
<h4>PORTFOLIO NAME</h4>
<p>category</p>
</div>
</div>
</div>
</a>
</div>
</div>
</div>
</section>
When you use a absolute positioned element, always set the respective relative, position element. Let me know if you have any issues with the output.
The only CSS change is to the below class. Where I have added the property position: relative.
.thumbnail {
padding: 0px !important;
position: relative;
margin-bottom: 25px;
border: none;
border-radius: 0;
display: block;
}
So your absolute positioned div with class overlay will be positioned with respect to the div with class thumbnail
.thumbnail {
padding: 0px !important;
position: relative;
margin-bottom: 25px;
border: none;
border-radius: 0;
display: block;
}
.thumbnail img {
width: 100%;
height: 100%;
margin-bottom: 0px;
display: block;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
padding: 0px 0px 0px 0px;
transition: .5s ease;
background-color: rgba(136, 24, 38, 0.6);
}
.thumbnail:hover .overlay {
opacity: 1;
height: 100%;
width: 100%;
}
.text {
color: white;
font-size: 20px;
position: absolute;
width: 70%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<section id="work" class="bg-grey">
<div class="container-fluid text-center">
<h2>MY WORK</h2>
<!--<h4>What we have created</h4>-->
<div class="row text-center">
<div class="col-md-4 col-sm-6 col-xs-12">
<a href="http://www.google.com/">
<div class="thumbnail">
<img src="http://lorempixel.com/100/100/" alt="PORTFOLIO NAME">
<div class="overlay">
<div class="text">
<h4>PORTFOLIO NAME</h4>
<p>category</p>
</div>
</div>
</div>
</a>
</div>
<div class="col-md-4 col-sm-6 col-xs-12">
<a href="http://www.google.com/">
<div class="thumbnail">
<img src="http://lorempixel.com/100/100/" alt="PORTFOLIO NAME">
<div class="overlay">
<div class="text">
<h4>PORTFOLIO NAME</h4>
<p>category</p>
</div>
</div>
</div>
</a>
</div>
<div class="col-md-4 col-sm-6 col-xs-12">
<a href="http://www.google.com/">
<div class="thumbnail">
<img src="http://lorempixel.com/100/100/" alt="PORTFOLIO NAME">
<div class="overlay">
<div class="text">
<h4>PORTFOLIO NAME</h4>
<p>category</p>
</div>
</div>
</div>
</a>
</div>
</div>
</div>
</section>

Can any tell me what I am doing wrong?

I am trying to position a div to the left of the screen and I am also trying to make it work on any screen resolution and browser.
Here's my code below:-
#Biography {
background: #ffffff ;
text-align: center ;
text-transform: uppercase ;
color: #fff ;
padding: 5em 0;
width: 100%;
font-family: 'Conv_Lato-Regular',Sans-Serif;
margin: 0;
}
#info {
left: -10px;
float: left;
top: -80px;
position: relative;
color: #000;
}
<div id="Biography">
<div class="container">
<div class="tittle">
</div>
<div id="info">
<div class="col-md-8">
<div class=" wow bounceInDown" data-wow-delay="0.5s">
<div class="view view-fifth" style="height: 20%">
<img src="images/Dan.jpeg" alt="" style="height:80%; width:100%">
<h4> NAME</h4>
<h5> sean</h5>
<h4> OCCUPATION</h4>
<h5> Computer Programmer,Software Developer,Student</h5>
</div>
</div>
</div>
</div>
The problem is that the #info div is not fully to the left. I don't know what I am doing wrong.
You need to use 'position:absolute' instead of 'position:relative' to be located fully to the left in this case.
#info {
position: absolute;
left: 0px;
top: 0px;
color: #000;
}