I am newbie in bootstrap and I have one problem.
<div class="container">
<div class="col-md-4 col-sm-6 col-xs-6">
<a href="">
<div class="box">
aaa
</div>
<div class="hover">
<div class="text">bbb</div>
</div>
</a>
</div>
<div class="col-md-4 col-sm-6 col-xs-6">
<a href="">
<div class="box">
aaa
</div>
<div class="hover">
<div class="text">bbb</div>
</div>
</a>
</div>
<div class="col-md-4 col-sm-6 col-xs-6">
<a href="">
<div class="box">
aaa
</div>
<div class="hover">
<div class="text">bbb</div>
</div>
</a>
</div>
<div class="col-md-4 col-sm-6 col-xs-6">
<a href="">
<div class="box">
aaa
</div>
<div class="hover">
<div class="text">bbb</div>
</div>
</a>
</div>
</div>
.box {
background-color: red;
height: 60px;
}
.hover {
position: absolute;
top: 0;
background: none repeat scroll 0% 0% rgba(20, 245, 43, 0.5);
width: 100%;
}
FIDDLE: https://jsfiddle.net/ocqpsvvc
Why if I use "width: 100%" for div.hover then background is outside of tag a? Background for div.box is ok.
I don't want use width with pixels or modify % because I would have modify this for all responsive layouts.
You are not taking into account the 15px bootstrap default padding.
add width: calc(100% - 30px); to make up for the padding. the calc is saying, make the width 100% minus 30px for the 15px right and 15px left. this will solve your issue.
see fiddle: https://jsfiddle.net/DIRTY_SMITH/ocqpsvvc/5/
Your problem is with the bootstrap "col" elements.
By default, these have padding on them, you will need to remove the padding.
E.G.
<div class="col-md-4 col-sm-6 col-xs-6" style="padding:0;">
EDIT:
Or add another class to the element so that css can remove the padding which will be cleaner.
E.G.
<div class="col-md-4 col-sm-6 col-xs-6 removePad">
.removePad{padding:0;}
Related
I have been trying to get 3 images to be responsive using bootstrap columns. They seem to be responsive, but the problem is that the images overlap except for the last column which remains being normal.
<div class="row">
<div class="col-sm-2 offset-sm-3">
<img class="img-responsive" src="../assets/images/roy-creates-categories-02.png">
</div>
<div class="col-sm-2">
<img class="img-responsive" src="../assets/images/roy-creates-categories-02.png">
</div>
<div class="col-sm-2">
<img class="img-responsive" src="../assets/images/roy-creates-categories-02.png">
</div>
</div>
I would like all 3 columns to like the one all the way on the right.
I've tried adding class "img-responsive" & "img-fluid" and neither have worked.
I'm using bootstrap 4.0.
The images are overflowing their container. The image on the right is full height but it is overflowing its container. Using the bootstrap '.col-2' means that you are limiting the column widths based on the window width. You could use background css rules instead of img elements to ensure containment or coverage of images or you could just use .col-auto instead of .col-2 with .justify-content-center provided you have appropriately sized images.
All three examples are in the snippet.
.row {
min-height: 150px;
}
.col-auto {
background-color: green;
}
.col-sm-2 {
background-color: red;
}
.bg-image {
width: 100%;
height: 100%;
background-image: url("https://picsum.photos/100");
background-position: center;
background-size: contain;
background-repeat: no-repeat;
}
.bg-image.bg-image--cover {
background-size: cover;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div class="row justify-content-center">
<div class="col-auto">
<img class="img-fluid" src="https://picsum.photos/100">
</div>
<div class="col-auto">
<img class="img-fluid" src="https://picsum.photos/100">
</div>
<div class="col-auto">
<img class="img-fluid" src="https://picsum.photos/100">
</div>
</div>
<div class="row">
<div class="col-sm-2 offset-sm-3">
<div class="bg-image"></div>
</div>
<div class="col-sm-2">
<div class="bg-image"></div>
</div>
<div class="col-sm-2">
<div class="bg-image"></div>
</div>
</div>
<div class="row">
<div class="col-sm-2 offset-sm-3">
<div class="bg-image bg-image--cover"></div>
</div>
<div class="col-sm-2">
<div class="bg-image bg-image--cover"></div>
</div>
<div class="col-sm-2">
<div class="bg-image bg-image--cover"></div>
</div>
</div>
Want to keep the image and div below at the same width.
Works fine until I get to around 545px to 575px window size. The .header changes width proportion only at col-md-12. Is there a way to keep the same aspect ratio?
SCREENSHOT
CODEPEN
HTML
<div class="container">
<div class="row">
<div class="first-column col-md-4 col-sm-6 col-xs-12">
<img class="img-responsive" src="https://unsplash.it/500">
<div class="header">header</div>
</div>
<div class="second-column col-md-4 col-sm-6 col-xs-12">
<img class="img-responsive" src="https://unsplash.it/500">
<div class="header">header</div>
</div>
<div class="third-column col-md-4 col-sm-6 col-xs-12">
<img class="img-responsive" src="https://unsplash.it/500">
<div class="header">header</div>
</div>
<!--END ROW-->
</div>
<!--END CONTAINER-->
</div>
CSS
.first-column{background-color: #c0c0c0}
.second-column{background-color: #808080}
.third-column{background-color: #778899}
.header{
background-color:rgba(45,44,89,0.7);
width: 100%;
color: #ffffff;
position: relative;
bottom: 40px;
padding-top: 10px;
padding-bottom: 10px;
text-align: center;
}
The bootstrap .img-responsive class has a max-width:100%; but it doesn't set the width.
So add a width to the class.
.img-responsive {
width: 100%;
}
https://codepen.io/rickydam/pen/XarXYX
Here the image is getting very small. and i also want to align image in centre .pLEASE tell some solution so that image is in centre and is shown in original size. I'm using bootstrap.
<div class="container" style="height: 100%;">
<div class="col-sm-4 col-md-4 col-lg-4"></div>
<div class="col-sm-4 col-lg-4" style="height: 100%;display: table;">
<a href="machine1.php" style="display : table-cell;vertical-align: middle;">
<img src="ft/text.png" class="img-responsive" style="min-width:660px;">
</a>
</div>
<div class="col-sm-4 col-md-4 col-lg-4 ">
</div>
.body-wrapper {
background: url('slide2_2.png');
background-size: cover;
height:100%;
}
html, body{
height:100%;
margin:0;
padding:0;
color:white;
}
a:hover{
text-decoration: none;
}
.img-responsive{
float: left;
}
Wnat imag to be in vertcal and horizontal centre and image size is 1366* 635
I am not sure what you want here
Try this if you want the image in the center
https://jsfiddle.net/0fcpr65u/4/
<div class="container" style="height: 100%;">
<div class="col-sm-4 col-md-4 col-lg-4"></div>
<div class="col-sm-4 col-lg-4" style="text-align:center">
<a href="machine1.php">
<img src="http://webneel.com/wallpaper/sites/default/files/images/01-2014/2-flower-wallpaper.preview.jpg" class="img-responsive" style="width:200px;margin: auto;">
</a>
</div>
</div>
remove float from the image css
EDIT:
I f you want it to be at the center of the page
add width & height to parent div make there position relative
Add this to the image
width: 200px;
position: absolute;
top: calc(50% - 100px);
left: calc(50% - 100px);
or you can use vertically-align property by using display:table
If you want the original size of the image use this
<div class="container" style="height: 100%;">
<div class="col-sm-4 col-md-4 col-lg-4"></div>
<div class="col-sm-4 col-lg-4" style="height: 100%;display: table; width:100%">
<a href="machine1.php" style="display:table-cell;vertical-align: middle;text-align: center;">
<img src="http://webneel.com/wallpaper/sites/default/files/images/01-2014/2-flower-wallpaper.preview.jpg">
</a>
</div>
<div class="col-sm-4 col-md-4 col-lg-4 ">
</div>
Else use flex
by adding this css in parent div
.parent {
display: flex;
justify-content: center;
align-items: center;
}
https://jsfiddle.net/ws4n0kh0/
try this.
<div class="container" style="height: 100%;">
<div class="col-sm-4 col-md-4 col-lg-4"></div>
<div class="col-sm-4 col-lg-4" style="height: 100%;display: table; width:100%">
<a href="machine1.php" style="display:table-cell;vertical-align: middle;text-align: center;">
<img src="https://www.cs.cmu.edu/~chuck/lennapg/len_std.jpg">
</a>
</div>
<div class="col-sm-4 col-md-4 col-lg-4 ">
</div>
Also removed img-responsive from CSS.
I am trying to remove a space between 2 elements in my html page.
I set margin-left:0px; but it does not work.
Here is the code:
<div class="row">
<div class="col-lg-6 col-md-6 col-xs-6 thumb">
<div class="thumbnail" href="#">
<img class="img-responsive" src="https://scontent-arn2-1.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/13687120_1671928519797295_1730075489_n.jpg?ig_cache_key=MTMwOTc1OTU2NDk2NjUzNzE2NQ%3D%3D.2" alt="">
</div>
</div>
<div class="col-lg-6 col-md-6 col-xs-6 thumb">
<ul class="bullet-remover">
<li class="item">
<div class="media">
<div class="media-body">
<h3 class="media-heading"><strong>Luisa Martine</strong></h3>
😍😍😍🙌😌👌👏👏👏😏😏
</div>
</div>
</li>
</ul>
</div>
</div>
As you can see, there is a space between image and ul tag.
I have tried to remove the left margin with:
.bullet-remover{
list-style-type: none;
margin-left: 0px;
}
But it does not work?
I can see that you have some custom padding to your bullets. So one option is to cancel out the padding-left and padding-right of the ".thumb"
One more issue. please don't leave out the ".container" around your ".row". Those two are perfect & made for each other.
container adds left and right padding which will be cancelled by the rows, so there won't be any scrollbar in the page
Option 2:
if you are fine with the column gutter spaces,
Then your bullet remover should be as follows
.bullet-remover{
padding:0;
margin:0;
list-style:none;
}
Check the snippet
.thumb {
/*padding-left: 0 !important;
padding-right: 0 !important;*/
}
.bullet-remover
{
list-style:none;
padding:0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="row">
<div class="col-lg-6 col-md-6 col-xs-6 thumb">
<div class="thumbnail" href="#">
<img class="img-responsive" src="https://scontent-arn2-1.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/13687120_1671928519797295_1730075489_n.jpg?ig_cache_key=MTMwOTc1OTU2NDk2NjUzNzE2NQ%3D%3D.2" alt="">
</div>
</div>
<div class="col-lg-6 col-md-6 col-xs-6 thumb">
<ul class="bullet-remover">
<li class="item">
<div class="media">
<div class="media-body">
<h3 class="media-heading"><strong>Luisa Martine</strong></h3>
😍😍😍🙌😌👌👏👏👏😏😏
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
This question already has answers here:
Bootstrap 3 CSS image caption overlay
(5 answers)
Closed 7 years ago.
I am trying to display overlay text on the Image using Bootstrap. I refereed the Stack Overflow Question and Answer. But Overlay is not fit into Image. I don't know What I have missed in that Answer
What I have tried Fiddle Here
Thank You
HTML
<div class="container">
<div id="DivOurProducts" class="row">
<div class="col-lg-3 col-md-3 col-xs-3 col-sm-3 wrapper">
<a href="/Article/Overview/1">
<div class="fixOverlayDiv">
<img alt="offer banner1" class="category-banner img-responsive" src="http://placehold.it/300x300">
<div class="OverlayText">Text Here</div>
</div>
</a>
</div>
<div class="col-lg-3 col-md-3 col-xs-3 col-sm-3 wrapper">
<a href="/Article/Overview/2">
<div class="fixOverlayDiv">
<img alt="offer banner1" class="category-banner img-responsive" src="http://placehold.it/300x300">
<div class="OverlayText">Text Here</div>
</div>
</a>
</div>
<div class="col-lg-3 col-md-3 col-xs-3 col-sm-3 wrapper">
<a href="/Article/Overview/3">
<div class="fixOverlayDiv">
<img alt="offer banner1" class="category-banner img-responsive" src="http://placehold.it/300x300">
<div class="OverlayText">Text Here</div>
</div>
</a>
</div>
<div class="col-lg-3 col-md-3 col-xs-3 col-sm-3 wrapper">
<a href="/Article/Overview/4">
<div class="fixOverlayDiv">
<img alt="offer banner1" class="category-banner img-responsive" src="http://placehold.it/300x300">
<div class="OverlayText">Text Here</div>
</div>
</a>
</div>
</div>
</div>
CSS
.fixOverlayDiv{
width:100%;
padding:0px;
}
.OverlayText{
background-color: #000;
bottom: 0;
color: #fff;
left: 0;
opacity: 0.5;
position: absolute;
width: 100%;
}
I found an Answer. I have missed Position = "relative" for Parent Div
CSS
In fixOverlayDiv class added Position = "relative"
.fixOverlayDiv{
position: relative;
width:100%;
padding:0px;
}
Updated Fiddle Here
Do you want to change the css class to .OverlayText{
background-color: #000;
bottom: 20%;
color: #fff;
left: 25%;
opacity: 0.5;
position: absolute;
width: 50%;
}