EDIT: This was my issue
bootstrap 4 center-block unable to center
I cannot for the life of me figure out how to properly align this image inside a bootstrap column. You can see how there is a big whitespace gap to the right of the image between the border of the image and the padding for the div column the image is in.
I have a row with 3 columns. I want the 2 images to be properly aligned in the page. this would be more easily accomplished if this awkward whitespace did not appear.
For now, I've added the below as a (not-so) quick fix.
.right-img {
padding-left: 45px;
}
I have tried several avenues including
class="center-block"
and removing
float-left
from the show-image class and flexbox and display-block and all the align properties and ensuring I have a container above the row.
I would really appreciate it if someone could help with the issue.
Here is the HTML:
<div class="container">
<div class="row">
<div class="col-lg-5 show-image">
<img class="img-responsive rounded head-img" src="{{ url_for('static', filename='#') }}" alt="Image Failed to Load">
<div class="hover-buttons">
<button type="submit" class="btn btn-danger btn-sm">Why Join?</button>
<button type="submit" class="btn btn-danger btn-sm">How It Works</button>
</div>
</div>
<div class="col-lg-2" id="with-container">
<h1 class="my-4 text-center">WITH</h1>
</div>
<div class="col-lg-5 show-image right-img">
<img class="img-fluid rounded head-img" src="{{url_for('static', filename='#')}}" alt="Image Failed to Load">
<div class="hover-buttons left-buttons">
<button type="submit" class="btn btn-danger btn-sm">Why Join?</button>
<button type="submit" class="btn btn-danger btn-sm">How It Works</button>
</div>
</div>
</div>
</div>
And here is the styling:
div {
border: 1px dashed red;
}
.head-img {
width: 400px;
height: 287px;
}
#with-container {
display: flex;
justify-content: center;
align-items: center;
}
div.show-image {
position: relative;
float: left;
}
div.show-image:hover img{
opacity:0.5;
}
div.show-image:hover .hover-buttons {
display: inline-block;
}
.hover-buttons {
position: absolute;
display:none;
}
div.show-image .hover-buttons {
top: 75%;
left: 12%;
}
div.show-image .left-buttons {
top: 75%;
left: 19%;
}
You could apply the following bootstrap helper class to the parent div:
text-center
Which should horizontally align the image for you. The full div class structure should look like the following:
<div class="col-lg-5 show-image text-center">
Further reading: https://v4-alpha.getbootstrap.com/utilities/typography/#text-alignment
Related
I tried lots of methods to get the button below each image from ngFor loop in angular 10 but it populates the button next to the image not in each image it's showing as a list I attached the image output also. This is the code that I tried.
CSS
.container {
position: relative;
text-align: center;
}
.original {
width: 250px;
height: 250px;
float: left;
margin: 1.66%;
transition-duration: 0.3s;
border-radius: 15px;
}
Html
<ng-container *ngFor="let img of imageData">
<div class="container">
<img class="original" [alt]="img.Name"
src="https://localhost:44349/{{img.ImagePath}}"
width="350" height="350"/>
</div>
<button type="submit" (click)="deleteImage(img.Id)" class="btn btn-danger"><i
class="far fa-trash-alt"></i>
Remove
</button>
</ng-container>
Try this markup, move the closing div after the button element:
<ng-container *ngFor="let img of imageData">
<div class="container card">
<img class="original" [alt]="img.Name"
src="https://localhost:44349/{{img.ImagePath}}"
width="350" height="350"/>
<button type="submit" (click)="deleteImage(img.Id)" class="btn btn-danger"><i
class="far fa-trash-alt"></i>
Remove
</button>
</div>
</ng-container>
with new css class using flexbox:
.card {
display: flex;
flex-direction: column;
}
UPDATE
according to some css classes like btn, btn-danger I presume bootstrap used.
You can wrap the whole thing inside a div with these classes:
<div class="d-flex flex-wrap">
General info and docs
Stackblitz demo
I'm trying to achieve this behavior:
images are img-fluid, cause they need to scale across Bootstrap breakpoints
the layout must always be like the mockup, both when images are small or large (button doesnt need to scale)
Since elements can't span across divs, I tried putting the button in the first column and setting it to position: absolute + many variants of props, but no way I could get the result I need.
I don't need to use 2 cols at any cost, as long as it is all inside a row, i can do anything, this is just my attemp
Some attempts:
Starting point without button:
<div class="row py-3">
<div class="col">
<img src="https://fakeimg.pl/693x678" class="img-fluid">
</div>
<div class="col">
<img src="https://fakeimg.pl/693x678" class="img-fluid">
</div>
</div>
Attempt 1:
<div class="row py-3">
<div style="position: absolute" class="text-center h-auto" style="position: absolute; left: 0; right: 0;">
<a class="btn btn-success text-white px-5">Hi guys</a>
</div>
<div class="col">
<div class="w-100">
<img src="https://fakeimg.pl/693x678" class="img-fluid mr-3">
<img src="https://fakeimg.pl/693x678" class="img-fluid ml-3">
</div>
</div>
</div>
Attempt 2:
<div class="row py-3">
<div class="col">
<a class="btn btn-success text-white px-5" style="position: absolute; left: 0; right: 0;">Hi guys</a>
<img src="https://fakeimg.pl/693x678" class="img-fluid">
</div>
<div class="col">
<img src="https://fakeimg.pl/693x678" class="img-fluid">
</div>
</div>
And many others ...
Something like this
.row {
position: relative;
}
a {
position: absolute;
bottom: 10%;
left: 50%;
transform: translateX(-50%);
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col">
<img src="https://fakeimg.pl/693x678" class="img-fluid">
</div>
<div class="col">
<img src="https://fakeimg.pl/693x678" class="img-fluid">
</div>
<a class="btn btn-success text-white px-5">Hi guys</a>
</div>
HTML:
<div class="row some-row">
<div class="col">...</div>
<div class="col">...</div>
<a class="btn some-btn"></a>
</div>
CSS:
.some-row {
position: relative;
}
.some-btn {
position: absolute;
bottom: 30px;
margin: 0 auto;
}
This solution makes the assumption that your button is placed inside the first column as per your own attempt. In this case, all you need for the button to be placed in the middle of the two columns is to use parentWidth - 0.5 * buttonWidth. A combination of left and transform achieves that:
Example:
document.querySelector(".btn").addEventListener("click", function () {
[].forEach.call(document.querySelectorAll("img"), function (img) {
img.src = "https://placehold.it/693x500";
});
});
body {
overflow-x: hidden;
}
.btn {
position: absolute;
left: 100%;
transform: translateX(-50%);
z-index: 2;
bottom: 15%;
}
<link type = "text/css" rel = "stylesheet" href = "https://cutt.ly/Twe8un2"/>
<div class = "row">
<div class = "col">
<img src = "https://placehold.it/693x300" class = "img-fluid">
<a class = "btn btn-danger text-white">Custom Button</a>
</div>
<div class = "col">
<img src = "https://placehold.it/693x300" class = "img-fluid">
</div>
</div>
Here is a pen i did using a grid layout to replicate your mockup.
I used Grid because they make it easy to superpose elements and to organise a 2d layout.
.grid-container {
display: grid;
grid-template-rows : min-content 150px 20%;
grid-template-columns : 45% 5% 5% 45%;
justify-items: center;
align-items: center;
width: max-content;
height: max-content;
}
The images only need one row but to position the button as desired I made 3. The 150px one being for the button. For the images i just need to span them accross the 3 rows.
For the column, as i need the button to be centered above the images, i made 4 of them. Each image span the 2 outside columns respectively and the button the 2 'inside' columns.
.img1 {
grid-row: 1/4;
grid-column: 1/3;
}
.img2 {
grid-row: 1/4;
grid-column: 3/5;
}
.button1 {
grid-row: 2/3;
grid-column: 2/4;
}
Obviously you can adjust the pourcentages and sizes to fit your need more precisly.
Note : The row you were talking about would be the grid container in this example.
Currently I'm creating a product box with two columns near each other, left one have the product image and right one product description.
The main problem is, I'm trying to make the product description the same height as the image, but after few tries I didn't get close to solve it, because it needs to be responsive. I tried a lot of solutions but still stuck, the closest one was using media queries and apply height to the .product-det but seems like it's not the good way.
I have create a Bootply as a demo.
The blue border must reach the bottom of the wrapper.
HTML
<div class="container">
<div class="col-xs-6">
<div class="col-xs-12 padding-15 margin-b-15 border-default padding-t-0 padding-b-0">
<div class="row">
<div class="col-xs-12">
<div class="row">
<div class="col-xs-4 col-sm-3 nopadding">
<img class="img-responsive" src="http://placehold.it/250x250">
</div>
<div class="col-xs-8 col-sm-9 border-l-default">
<div class="row"> <h4 class="col-xs-10 margin-t-15 text-ellipsis">Article pokeball superpotion lighting boltubertext pokemon pikachu</h4>
<div
class="col-xs-2 padding-t-15"> <span class="pointer pull-right">
<i class="glyphicon glyphicon-remove"></i>
</span>
</div>
<div class="product-det col-xs-12 line-h-35">
<div class="row">
<div class="col-xs-4">ITEMID</div>
<div class="col-xs-4">
<div class="input-group">
<input class="form-control" placeholder="qnt" type="text"> <span class="input-group-btn">
<button class="btn btn-secondary" type="button">
<span class="glyphicon glyphicon-refresh"></span>
</button>
</span>
</div>
</div>
<div class="col-xs-4"><span class="pull-right">3.203 €</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="">Right content</div>
</div>
CSS
.text-ellipsis {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.padding-15 {
padding: 15px;
}
.padding-t-15 {
padding-top: 15px;
}
.margin-b-15 {
margin-bottom: 15px;
}
.border-default{
border: 1px solid #e0e0e0;
}
.padding-t-0 {
padding-top: 0px;
}
.padding-b-0 {
padding-bottom: 0px;
}
.nopadding {
padding: 0;
}
.line-h-35 {
line-height: 35px;
}
.border-l-default {
border-left: 1px solid blue;
}
Try the following:
Html:
<div class="row row-eq-height">
<!--The div columns you want them to be same height should be here-->
</div>
CSS:
/*
Row with equal height columns
*/
.row-eq-height {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
you can try javascript to do this. because bootstrap col is changing width overtime when you change your devices. I like it, it typeless and you can put the class in your image wrap and your product descript wrap like so:
var st = $('.squarethis').width();
$('.squarethis').css({'height':st+'px'});
$('.sameheight').css({'height':st+'px'});
.wrapper{
background:#ccc;
width:100%;
height:100%;
display:flex;
flex-wrap:wrap;
flex-direction:row;}
.prodImage{
width:30%;
background:red;}
.prodDesc{
width:70%;
background:green;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<div class="prodImage squarethis"></div>
<div class="prodDesc sameheight"></div>
</div>
it will apply on your bootstrap. try to input this.
let me explain what happened:
$('.squarethis').css({'height':st+'px}); it will make your image always square, and it don't care what devices you using.
$('.sameheight').css({'height':st+'px'}); and this thing will make your next bootstrap col following the height of your previous col.
don't forget to input a class in your image wrapper and description wrapper
I'd suggest you to look at bootstrap v4 which comes with awesome features, like flexbox grid.
It does just what you need - example:
#foo{
background-color: aqua;
height: 300px;
}
#bar{
background-color: yellow;
}
<link href="https://cask.scotch.io/bootstrap-4.0-flex.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-sm-6" id="foo">foo</div>
<div class="col-sm-6" id="bar">bar</div>
</div>
</div>
JSFiddle
You can tune this cell (product description) using plain css. Just a little modify class .border-l-default:
.border-l-default {
border-left: 1px solid blue;
height: 100%;
position: absolute;
right: 0;
}
bootply
Try to change the text ellipsis like that, it is a bit rude because i didn't use bootstrap classes, but it works fine to me:
.text-ellipsis {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-bottom: 71px;
}
Try to set min-height in different mediaquery
.border-l-default {
border-left: 1px solid blue;
min-height: 135px;
I WANT IT TO BE LIKE THIS
http://www.patient-experience.org/Images/Stock-Art/For-Patients.aspx
I want to make a responsive thumbnail image with a button on it , and the button should take the size of the image inside the thumbnail .
I am using bootstrap 3 , and using these classes for the above above div.
img-responsive, img-thumbnail, btn , btn-block . !!
can someone please help me ?
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
<div class="col-md-12"> <img src="http://www.patient-experience.org/Images/Stock-Art/For-Patients.aspx" class="img-thumbnail">
<button class="btn btn-block">submit</button></div>
Here you go:
https://jsfiddle.net/59m0nyfq/1/
<img src="http://www.patient-experience.org/Images/Stock-Art/For-Patients.aspx" class="img-responsive">
<button class="btn btn-block" style="display: inline-block;
position: absolute; bottom: 0; left: 0;
width: 100%; height: 20%; opacity: 0.5; background-color:red; color:#fff;">submit</button>
You can do it with positioning. You need to wrap them with a div and add the img-thumbnail to that div too.
<div class="col-md-12">
<div class="img-thumbnail" style="position: relative;">
<img src="http://www.patient-experience.org/Images/Stock-Art/For-Patients.aspx" class="img-thumbnail">
<button class="btn btn-block" style="display: inline-block; position: absolute; top: 0; left: 0; width: 100%; height: 100%;">submit</button>
</div>
</div>
In this case, the button will overlap your image, so you should add opacity for it.
Here is a working DEMO.
By using Twitter Bootstrap 3.2.0 and a very nice snippet, I've created a menu-box with multiple choices.
For each menu item there is a label and a short description, as shown in figure below:
You could find an example with the code on JSfiddle.
Now, I'd like to:
Align menu-item content on middle (regarding the vertical-alignment);
Align the submit button on bottom-right.
Someone can suggest me how to do that?
1. Align menu-item content on middle (regarding the vertical-alignment):
I've recently used this excellent tutorial by #beaver82minimit that allows to create equal height columns bootstrap style: http://www.minimit.com/articles/solutions-tutorials/bootstrap-3-responsive-columns-of-same-height
You can use it like this:
<div class="container container-xs-height">
<div class="row row-xs-height">
<div class="col-xs-6 col-xs-height"></div>
<div class="col-xs-3 col-xs-height col-top"></div>
<div class="col-xs-2 col-xs-height col-middle"></div>
<div class="col-xs-1 col-xs-height col-bottom"></div>
</div>
</div>
With the class col-middle you can center your content vertically.
2. Align the submit button on bottom-right
a) Add class bottom-right to the button and remove the wrapping <p>
<button type="button" class="btn btn-primary btn bottom-right" style="margin: 20px 0 0 0;"><span class="glyphicon glyphicon-log-in"></span> Submit</button>
b) Add this to your stylesheet:
.bottom-right {
position: absolute;
right: 0;
bottom: 0;
}
To prevent tab content to overlap with button, add padding-bottom to tab-content div:
div.bhoechie-tab-content{
background-color: #ffffff;
padding-left: 20px;
padding-top: 10px;
padding-bottom: 54px;
}
Here is a demo: http://jsfiddle.net/LaBZP/3/
List-group-item vertical aligning middle:
.text-center {
display: table;
width: 100%;
}
.text-center > div {
display: table-cell;
vertical-align: middle;
}
Add divs under list-group-item to markup:
<a href="#" class="list-group-item idp-group-item text-center">
<div>
<strong>Label B</strong><br/>Label B Desc
</div>
</a>
Demo: http://jsfiddle.net/LaBZP/4/