I have a gallery kind of display. What I'm trying to achieve is to put titles for those items within their display box.
Check jsfiddle for the scenario:
https://jsfiddle.net/xry7ezb9/5/
The problem is that the parent element uses bootstrap col class which creates padding on both sides of the element (which is, of course, considered part of the element size) and thus a child element takes that as the 100% width to adapt.
The result I'm trying to achieve is the second gallery item. But the way it is achieved is... "Hacky" (apologies for terminology) since i define the values in a hard-coded way and relying on the fact that Bootstrap does not change that. Also, I'm certain there is another way to achieve this.
The last div element has the correct width by itself but since i can't use absolute positioning to put it into correct place, I'm not sure, how i can apply this.
Also, not sure if 3rd tile approach is really viable (though it might be due to the fact, that gallery item height is hard-coded).
How should I approach this while keeping responsiveness in mind?
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col {
border: solid 1px #6c757d;
padding: 10px;
}
.gallery-item-container {
height: 200px;
max-height: 200px;
cursor: pointer;
}
.gallery-item-logo {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
border: unset;
border-radius: unset;
background: unset;
border: solid 1px #929292;
border-radius: 5px;
background-color:#fff;
}
.gallery-item-logo:hover{
background-color:#c7c7c7;
transition: 0.5s;
}
.gallery-item-logo > img {
max-height: 70%;
max-width: 90%;
}
.speaker-name, .item-title {
position: absolute;
text-align: center;
bottom: 0px;
left: 0px;
width: 100%;
z-index: 1000;
padding: 5px;
color: #fff;
background-color: rgba(0, 0, 0, 0.5);
}
.no-absolute {
/* position: absolute; */
text-align: center;
bottom: 0px;
left: 0px;
width: 100%;
z-index: 1000;
padding: 5px;
color: #fff;
background-color: rgba(0, 0, 0, 0.5);
}
.no-absolute-top-margin-test{
height: 15%;
margin-top: -30px;
}
/* Offsetting bootstrap col class padding on the parent (it expands parent body by 15px on each side thus children inherit that extra width) */
.col-padding-offset {
max-width: calc(100% - 30px);
margin-left: 15px;
max-height: 15%; // Separate this
height: 15%;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="gallery-item-container mb-3 col-lg-3 col-md-6 col-sm-6 col-xs-6">
<div class="gallery-item-logo" data-toggle="modal" data-target="#participant_modal_8">
<img class="img-fluid" src="https://vignette.wikia.nocookie.net/lotr/images/8/8d/Gandalf-2.jpg/revision/latest?cb=20130209172436">
<span class="icon-focus"></span>
</div>
<div class="item-title">
<p><b>test title</b></p>
</div>
</div>
<div class="gallery-item-container mb-3 col-lg-3 col-md-6 col-sm-6 col-xs-6">
<div class="gallery-item-logo" data-toggle="modal" data-target="#participant_modal_16">
<img class="img-fluid" src="https://vignette.wikia.nocookie.net/lotr/images/8/8d/Gandalf-2.jpg/revision/latest?cb=20130209172436">
<span class="icon-focus"></span>
</div>
<div class="item-title col-padding-offset">
<p><b>test title</b></p>
</div>
</div>
<div class="gallery-item-container mb-3 col-lg-3 col-md-6 col-sm-6 col-xs-6">
<div class="gallery-item-logo" data-toggle="modal" data-target="#participant_modal_11">
<img class="img-fluid" src="https://vignette.wikia.nocookie.net/lotr/images/8/8d/Gandalf-2.jpg/revision/latest?cb=20130209172436">
<span class="icon-focus"></span>
</div>
<div class="no-absolute no-absolute-top-margin-test">
<p><b>test title</b></p>
</div>
</div>
<div class="gallery-item-container mb-3 col-lg-3 col-md-6 col-sm-6 col-xs-6">
<div class="gallery-item-logo" data-toggle="modal" data-target="#participant_modal_2">
<img class="img-fluid" src="https://vignette.wikia.nocookie.net/lotr/images/8/8d/Gandalf-2.jpg/revision/latest?cb=20130209172436">
<span class="icon-focus"></span>
</div>
<div class="no-absolute">
<p><b>test title</b></p>
</div>
</div>
</div>
The padding is always 15px, so you can could do this:
.speaker-name, .item-title {
position: absolute;
text-align: center;
bottom: 0px;
left: 15px;
width: calc(100% - 30px);
z-index: 1000;
padding: 5px;
color: #fff;
background-color: rgba(0, 0, 0, 0.5);
}
Your fiddle example
Related
This is my sample output, as you can see here that the image is half.
The second photo provided is the output i'm trying to achieve.
I don't know what seems to be the problem here, but when i remove the class, "carousel-inner" the image output is complete, but when i put it back, it shows only half image.
this is my html code and i'm using bootstrap 4
<div class="carousel-inner">
<div class="carousel-item active">
<div class="row">
<div class="col-4">
<div class="customer-card">
<div class="customer-img">
<img src="assets/img/user-img/john.png" alt="customer image" class="">
</div>
<div class="customer-txt-area">
<p class="john">"With Finger Food, my birthday party was a real blast! Super finger food!"</p>
<h4><b>John Esacada</b></h4>
<small>Sydney</small>
</div>
</div>
</div>
</div>
</div>
</div>
.customer-card-parent{
margin-top: 41px;
width: 100%;
max-width: 964px;
margin-left: auto;
margin-right: auto;
}
.customer-card{
width: 100%;
max-width: 290px;
padding: 39px 0px 35px 0px;
border-radius: 5px;
background: #fff;
}
.customer-img{
position:absolute;
top: -55px;
left: 0;
right: 0;
width: 100%;
max-width: 100px;
height: 100px;
border-radius: 100%;
overflow: hidden;
margin-left: auto;
margin-right: auto;
border: 11px solid #fff;
background-color: #cecece;
}
.customer-img img{
width: 100%;
height: auto;
position: relative;
top: 21px;
transform: scale(1.4, 1.3);
}
.customer-txt-area .john{
font-size: 18px;
color: #696969;
margin: 0px;
padding-top: 40px;
padding-left: 15px;
padding-right: 18px;
line-height: 23px;
font-family: "MyriadPro";
}
.customer-img
{
position:absolute;
top: -55px;
left: 0;
right: 0;
width: 100%;
max-width: 100px;
height: 100px;
border-radius: 100%;
overflow: hidden;
margin-left: auto;
margin-right: auto;
border: 11px solid #fff;
background-color: #cecece;
}
you have to remove "overflow: hidden;" from the above code.
Just remove overflow: hidden; from the parent element, which is ".customer-img" in your case and remember to add padding of half the size of the image to ".customer-card" parent element .
.customer-img{
position:absolute;
top: -55px;
left: 0;
right: 0;
width: 100%;
top:-55px is pushing the image out of the card and since abolute position is used, height of card doesn't consider image height so use min-height or height for card.
.customer-card{
width: 100%;
min-height:300px;
max-width: 290px;
padding: 39px 0px 35px 0px;
border-radius: 5px;
background: #fff;
}
Try this solution
Add here
<div class="row">
Extra style
<div class="row" style="margin-top: 50px">
Just now, i managed to somehow "solved" the issue here without changing any css. I just added some classes to my carousel-inner.
as you can see in this photo, i added border class to my carousel-inner class in order to see the actual "height" and "width" of my div and it shows like this.
<div class="carousel-inner border ">
<div class="carousel-item active">
<div class="row">
<div class="col-4">
<div class="customer-card">
<div class="customer-img">
<img src="assets/img/user-img/john.png" alt="customer image" class="">
</div>
<div class="customer-txt-area">
<p class="john">"With Finger Food, my birthday party was a real blast! Super finger food!"</p>
<h4><b>John Esacada</b></h4>
<small>Sydney</small>
</div>
</div>
</div>
</div>
</div>
</div>
So, i tried adding some classes to my carousel-inner
<div class="carousel-inner border d-flex justify-content-center align-items-center">
<div class="carousel-item active">
<div class="row">
<div class="col-4">
<div class="customer-card">
<div class="customer-img">
<img src="assets/img/user-img/john.png" alt="customer image" class="">
</div>
<div class="customer-txt-area">
<p class="john">"With Finger Food, my birthday party was a real blast! Super finger food!"</p>
<h4><b>John Esacada</b></h4>
<small>Sydney</small>
</div>
</div>
</div>
</div>
</div>
</div>
and now it shows something like this.
I want to display images in my div. I display different images according to the condition (if moviePoster true).
I moviePoster I display it, but if it is false, I display a image that informed that the file is not found.
I don't know why but when I display these 2 types of image, the moviePoster image, exceeding the size of the dive.
This is a screen from the issue in my application
.list {
border: 1px solid grey;
display: flex;
margin: 30px;
height: 230px;
border-radius: 10px;
box-shadow: 1px 1px 12px #555;
}
.list-img {
// border: 5px solid red;
width: 20%;
}
img {
height: 100%;
width: 100%;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
<div class="list">
<div class="list-img">
<div *ngIf="moviePoster; else notFound">
<img src="https://image.tmdb.org/t/p/w200/{{moviePoster}}" alt="...">
</div>
<ng-template #notFound>
<img src="../../assets/not_found.jpg" alt="...">
</ng-template>
</div>
img is a default display: inline, so height and width refers to inner content.
Anyway set image width and height usually stretches image, and that's orrible.
I suggest on using a div with the image setted as background, so use something like that:
html:
...
<div
*ngif="..."
class="thumbnail"
style="background-image: url(https://...{{ moviePoster }})"
></div>
...
css:
.thumbnail{
background-size: cover;
background-position: center;
}
You should apply this class also to #notFound.
One thing missing: thumbnail div must have height and width expressed
You can do that in multiple ways via css, depending on how have you structured the card box.
Hope it helps.
i think this is what you want :
if the image is null then the default background will show.
UPDATE: i have made it more dynamic
.list {
display: flex;
flex-direction: column;
}
.list-item {
height: 150px;
overflow: hidden;
border-radius: 10px;
box-shadow: 0 0 3px 2px rgba(0,0,0,.5);
}
.list-item + .list-item {
margin-top: 10px;
}
.list-img {
width: 200px;
height: 150px;
transition: background .5s ease;
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
background-image: url(https://www.tourismselangor.my/wp-content/themes/Directory/images/noimage.jpg);
}
<div class="list">
<div class="list-item">
<div class="list-img" style="background-image: url(https://picsum.photos/200)"></div>
</div>
<div class="list-item">
<div class="list-img"></div>
</div>
<div class="list-item">
<div class="list-img" style="background-image: url(https://picsum.photos/200)"></div>
</div>
</div>
I'm trying to design product details and one of the requirements is to design product image like this
https://imgur.com/Q8psgf7
<div class="button-wrap divide-md">
<div class="row">
<div class="col-sm-12 col-xs-12">
<a href="{{ route('products') }}" class="productCategories radio-label" id="city1-button">
<label class="button-label #if($productCat == 0) chosen_productCategory #endif" for="product1-button">
<h1>{{ trans("public.allProducts") }}</h1>
</label>
</a>
</div>
</div>
#foreach ($products_cats as $product_cat)
<div class="row">
<div class="col-sm-12 col-xs-12">
<a href="{{ route('products_cat', $product_cat->id) }}" class="productCategories radio-label" id="city1-button">
<label class="button-label #if($productCat == $product_cat->id) chosen_productCategory #endif" for="product1-button">
<h1>{{ $product_cat->name }}</h1>
</label>
</a>
</div>
</div>
#endforeach
</div>
I tried using css like :
postion :relative
z-index ....etc
but couldn't make it.
No need for extra markup, you can use pseudo elements for this:
.image-wrap {
margin: 100px;
box-shadow: -10px 10px 10px rgba(0, 0, 0, 0.3);
max-width: 200px;
position: relative;
}
.image-wrap:before {
content: '';
display: block;
position: absolute;
top: -10%;
left: -10%;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, .4);
z-index: -1;
}
img {
display: block;
width: 100%;
height: auto;
}
<div class="image-wrap">
<img src="https://via.placeholder.com/200">
</div>
And using percentages for the top and left values of the :before makes it so the background box always stays relative to the size of the image if it gets smaller or larger due to responsive CSS.
From image attached it seems you want something like following.
.parent {
position: relative;
margin: 50px auto;
}
.parent div {
width: 100px;
height: 100px;
border: 1px solid #e1e1e1;
}
div.first {
background: grey;
}
div.second {
background-color: red;
position: absolute;
top: 20px;
left: 20px;
z-index: 3;
box-shadow: 0 4px 16px #333333;
}
<div class="parent">
<div class='first'/>
<div class="second"/>
</div>
I need some help, I need to code this image:
This is what I have so far:
I tried adding a margin-top, padding-top, tried all combinations of position relative and absolute, I just need some ideias on how to do it.
This is how my code is structured:
<div class="background-oficina">
<div class="container">
<div class="col-xs-12 text-center">
<img class="logo" src="logo.png" alt="Oficina de Redação">
</div>
</div>
</div>
This is the css for the two classes that I'm using:
.background-oficina {
background: #fff url("bg-texture.png");
}
.logo {
padding-top: 50px;
margin: 0 auto;
}
You could use an additional absolutely positioned element to which you assign the repeated background pattern and which you put behind the original element by using z-index: -1:
html, body {
margin: 0;
}
.background-oficina {
position: relative;
border: 1px solid #333;
border-bottom: none;
}
.bg-container {
position: absolute;
z-index: -1;
left: 0;
top;
width: 100%;
height: 120px; /* or whatever height is desired */
background: url("http://placehold.it/20x15/cff");
}
.text-center {
text-align: center;
}
.logo {
padding-top: 50px;
margin: 0 auto;
}
<div class="background-oficina">
<div class="bg-container"></div>
<div class="container">
<div class="col-xs-12 text-center">
<img class="logo" src="http://placehold.it/200x150/fb7" alt="Oficina de Redação">
</div>
</div>
</div>
Your trying this, you can set default height and width to parent div that consist of that logo then using position:absolute you can push that out of parent div, but don't add overflow:hidden to parent div or else it hides your image or element that you are trying to push outside parent div as hidden.
.background-oficina {
background: #fff url("https://via.placeholder.com/800x100/000") no-repeat;
box-shadow: inset 0 0 0 1000px rgba(255, 255, 255, 0.2);
background-size: 100% 100%;
width: 100%;
height: 100px;
position: relative; /*Add this*/
}
.logo {
padding-top: 50px;
margin: 0px auto;
position: absolute; /*Add this*/
bottom: -20px; /*Add this*/
}
<div class="background-oficina padding margin-bottom">
<div class="container">
<div class="col-xs-12 text-center margin-bottom">
<img class="logo" src="https://via.placeholder.com/50/ff2" alt="Oficina de Redação">
</div>
</div>
</div>
I have a row with two columns. I would like the column containing the .product-image empty div with background image (on the right) to have the same height as the column containing the .product-text div with text (on the left). The background image should cover the entire area of the right column.
I've created a codepen here: http://codepen.io/anon/pen/VemgQb
HTML:
<div class="container-fluid subpage-product">
<div class="row">
<div class="col-lg-6 col-md-6 col-xs-12 product-text">
<div class="product-icon">
<img src="https://s-media-cache-ak0.pinimg.com/736x/5a/dc/89/5adc89f4a0752dfec5c2f9ba625bfac5.jpg">
</div>
<h2>Meow Meow Meow</h2>
<p>Pelt around the house and up and down stairs chasing phantoms shove bum in owner's face like camera lens stare at ceiling.</p>
</div>
<div class="col-lg-6 col-md-6 col-xs-12 no-padding product-img" id="horse-racing-bg-img-01">
</div>
</div>
CSS (LESS):
#horse-racing-bg-img-01 {
background: url(http://i.imgur.com/C9xULnI.jpg) no-repeat;
background-size: cover;
}
.subpage-product .row {
overflow: hidden;
.product-text {
padding: 70px 100px;
text-align:center;
background-color: #000;
color: #fff;
}
.product-img {
height: 100%;
}
.product-icon {
height: 80px;
width: 80px;
display: block;
margin: 0 auto 0;
border-radius: 50%;
border: 1px solid white;
background-color: #fff;
img {
height: 50px;
width: 50px;
margin: 15px 15px 0 13px;
}
}
}