Bootstrap - Badge in Img mantain responsive - html

I need a badge within an img - independently from the window size - So far I have in my html following code (btw. I'm using Angular - but framework should be irrelevant):
.icon-container {
display: inline-block;
position: relative;
}
troop-level-badge {
position: absolute;
bottom: 2px;
left: 2px;
}
`
<div class="container row" *ngIf="img">
<div class="col-md-1">
<div class="icon-container">
<img class="rounded" [src]="img" width="40" height="auto">
<span class="badge badge-dark troop-level-badge">6</span>
</div>
</div>
</div>`
so far the result looks like this (as expected):
But when i resize the window the badge breaks out of the div. Does
someone know how i can contain the badge within the img even by resizing the window?

Your troop-level-badge rule isn't valid. There is a missing point. So replace troop-level-badge with .troop-level-badge and it should work like the following. To display the badge on the right side you need to set right:2px; instead of left:2px;:
.icon-container {
display:inline-block;
position:relative;
}
.troop-level-badge {
bottom:2px;
position:absolute;
right:2px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<div class="container row" *ngIf="img">
<div class="col-md-1">
<div class="icon-container">
<img class="rounded" src="https://placehold.it/100x100" >
<span class="badge badge-dark troop-level-badge">6</span>
</div>
<div class="icon-container">
<img class="rounded" src="https://placehold.it/75x75" >
<span class="badge badge-dark troop-level-badge">6</span>
</div>
<div class="icon-container">
<img class="rounded" src="https://placehold.it/50x50" >
<span class="badge badge-dark troop-level-badge">6</span>
</div>
</div>
</div>

Related

how to give proper alignment for div

here is my code, I need to display a page with 3 images one is on the left and other two on the right side but all images are displaying in the same line, they are not displaying in order that I
List item
have given. please help me in solving these.
.leftAlign {
float: left;
}
.rightAlign {
float: right;
margin: 10px;
}
.rightOrder{
float: right;
margin: 10px;
}
.primary-button {
background-color: #109bd5;
color: white;
}
<div class="about-content">
<h4 mat-dialog-title>Hello World</h4>
<div mat-dialog-content>
<div class='leftAlign'>
<h4>IMAGE1</h4>
<img src="assets/images/image1.png">
</div>
<div class='rightAlign'>
<h4>IMAGE2</h4>
<img src="assets/images/image2.png">
</div>
<div class='rightOrder'>
<h4>ICON</h4>
<img src="assets/images/icon_img.png">
</div>
</div>
<div mat-dialog-actions align="end">
<button mat-button mat-dialog-close class="mat-button primary-button">close
</button>
</div>
</div>
<div style="display:flex;justify-content:space-between;">
<div>
<!-- This will be left aligned -->
<img src="https://via.placeholder.com/150?text=1" alt="image 1">
</div>
<div>
<!-- This will be right aligned -->
<div>
<img src="https://via.placeholder.com/150?text=2" alt="image 2">
</div>
<div>
<img src="https://via.placeholder.com/150?text=3" alt="image 3">
</div>
</div>
</div>
Please have look at this, if you are using Bootstrap, I will recommend using it instead of giving inline style.

Bootstrap Columns Order

So I have footer section on the website I'm currently building, and the problem is order of them showing. I want to social icons be above ©
Have a look: footer
html:
<div id="footerbot">
<div class="container">
<div class="row">
<div class="col-md-6">
<h5 class="fbh">©2018 - Appo, All Right Reserved</h5>
</div>
<div class="col-md-6">
<img src="img/facebook.png" href="#">
<img src="img/twitter.png" href="#">
<img src="img/dribble.png" href="#">
<img src="img/gplus.png" href="#">
<img src="img/youtube.png" href="#">
</div>
</div> <!-- end of row -->
</div>
css:
#footerbot {
background-color: rgba(34, 48, 71, 0.8);
}
#footerbot img {
display: block;
float: right;
top: 50%;
padding-top: 35px;
padding-left: 15px;
}
#footerbot h5 {
color: #00FFF0;
line-height: 100px;
}
I tried to add class 'order-md-6' to each div with col-md-6, but first of all it didn't work, and secondly it broke layout - it 'pushed' both elements to center. Is it even possible in bootstrap4? I also have a problem centering these items u can see on image I've upload. I'm struggling with this for 2hours and I have no idea how to get this done. I would appreciate any help. Thanks
Bootstrap 4 uses flexbox to position the columns in their rows so you can add the following to your CSS to the control the order of the columns:
.col-md-6:last-child {
order: -1;
}
Not sure if what you provided is the full code sample of your footer or not, but if that's your full html, you're missing a closing tag.
Also, assuming all you want are the icons to go above the copyright line and centered, try this:
#footerbot .socialIcons {
text-align: center;
}
<div id="footerbot">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="socialIcons">
<img src="img/facebook.png" href="#">
<img src="img/twitter.png" href="#">
<img src="img/dribble.png" href="#">
<img src="img/gplus.png" href="#">
<img src="img/youtube.png" href="#">
</div>
<h5 class="fbh">©2018 - Appo, All Right Reserved</h5>
</div>
</div> <!-- end of row -->
</div>
</div>

CSS Vertical Align and fancyBox

I am working on a photo gallery(using fancyBox and PHP) for my photography page, and I can't figure out how to make the vertical align for my image gallery to be centered. I currently have placed mock images(from my own gallery) to figure out the layout, and I will then replace them with a PHP query to fill up the gallery with all my content automatically. I have also given each row a (temporary) different color to simply visualize the layout, as well as having a 12 division layout bar at the top for easier handling. The way I currently have my HTML and CSS code set up is as follows:
HTML:
<div class="gallery">
<div class="row row-one">
<div class="col-lg-4">
<a data-type='image' data-fancybox=landscape data-caption=caption href='images/photography/fres/burnaby_mountain.jpg'><img class='img-responsive' src='images/photography/thumbs/burnaby_mountain.jpg'></a>
</div>
<div class="col-lg-4">
<a data-type='image' data-fancybox=landscape data-caption=caption href='images/photography/fres/lions_gate.jpg'><img class='img-responsive' height="500px" src='images/photography/thumbs/lions_gate.jpg'></a>
</div>
<div class="col-lg-4">
<a data-type='image' data-fancybox=landscape data-caption=caption href='images/photography/fres/bubbles.jpg'><img class='img-responsive' src='images/photography/thumbs/bubbles.jpg'></a>
</div>
</div>
</div>
CSS:
.gallery {
display: table;
}
div .row-one {
background-color: red;
display: table-row;
vertical-align: middle;
}
.col-lg-4 {
display: table-cell;
}
As you can see, I have nested the columns inside rows(I did not include the other rows' CSS code, as they're the same except for the background-color attribute, with the intention of automating the gallery later through PHP queries) and rows inside a div container called gallery. From other examples I've seen through looking up for a solution, I've seen people give the main container the display attribute of table, and rows the attribute display: table-row, and lastly the column the table-cell attribute. I have tried this, as well as many other combinations of CSS attributes and have not found a way to center the gallery.
For a better visualization of what I would like to achieve
Thank you for your help, and excuse the lengthy question. I have been searching for a long time and it now feels like something in my code is faulty. I am fairly new to HTML/CSS and although most of my site is working as intended, this is the last bit I need to get it up and running.
Something like this?
.gallery {
display: flex;
height: 30%;
/* flex-direction:column; */
}
.box {
border: 1px solid white;
background: red;
display: flex;
justify-content: center;
flex: 1;
padding: 10px;
}
.inner-box {
align-self: center;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="gallery">
<div class="box">
<div class="inner-box">
<a data-type='image' data-fancybox=landscape data-caption=caption href='images/photography/fres/burnaby_mountain.jpg'><img class='img-responsive' src='https://i.kinja-img.com/gawker-media/image/upload/t_original/bhjivrw2chm9um9yrrmy.jpg'></a>
</div>
</div>
<div class="box">
<div class="inner-box">
<a data-type='image' data-fancybox=landscape data-caption=caption href='images/photography/fres/lions_gate.jpg'><img class='img-responsive' height="500px" src='https://media.gettyimages.com/photos/cocker-spaniel-puppy-picture-id904219284'></a>
</div>
</div>
<div class="box">
<div class="inner-box">
<a data-type='image' data-fancybox=landscape data-caption=caption href='images/photography/fres/bubbles.jpg'><img class='img-responsive' src='http://cdn.bangli.uk/images/201504/article_9323_1.jpg'></a>
</div>
</div>
</div>
<div class="gallery">
<div class="box">
<div class="inner-box">
<a data-type='image' data-fancybox=landscape data-caption=caption href='images/photography/fres/burnaby_mountain.jpg'><img class='img-responsive' src='https://i.kinja-img.com/gawker-media/image/upload/t_original/bhjivrw2chm9um9yrrmy.jpg'></a>
</div>
</div>
<div class="box">
<div class="inner-box">
<a data-type='image' data-fancybox=landscape data-caption=caption href='images/photography/fres/lions_gate.jpg'><img class='img-responsive' height="500px" src='https://media.gettyimages.com/photos/cocker-spaniel-puppy-picture-id904219284'></a>
</div>
</div>
<div class="box">
<div class="inner-box">
<a data-type='image' data-fancybox=landscape data-caption=caption href='images/photography/fres/bubbles.jpg'><img class='img-responsive' src='http://cdn.bangli.uk/images/201504/article_9323_1.jpg'></a>
</div>
</div>
</div>

How do I get a Bootstrap container to stay inline with another div?

Currently, the top of my web page looks like this:
I'm trying to use Bootstrap instead of CSS as I was told it was simpler (however so far I'm struggling to bend it to my will just as much as CSS). I have a div containing the logo and title, and a Bootstrap container with a list group of buttons to share the website. I want the buttons to appear on the right hand side of the page inline with the logo.
HTML:
<div class="headerDiv" style="display: inline">
<div>
<img id="logo" src="{% static "images/logo.jpg" %}" alt="Fact or Fiction Logo" />
</div>
<div class="titleDiv">
<h1 id="title">FACTorFICTION</h1>
</div>
</div>
<div class="container" style="display: inline">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<div class="list-group list-group-horizontal">
<script>
function fbs_click() {
u = location.href;
t = document.title;
window.open
('http://www.facebook.com/sharer.php?u=' +
encodeURIComponent(u) + '&t=' + encodeURIComponent(t),
'sharer', 'toolbar=0,status=0,width=626,height=436');
return false;
}
</script>
<a class="list-group-item" href="http://www.facebook.com/share.php?u=http://www.example.com/" onclick="return fbs_click()" target="_blank">
<img src="{% static "images/facebook.jpg" %}" alt="Share to Facebook.">
</a>
<a class="list-group-item" href="https://twitter.com/home?status=http://www.example.com/" onclick="window.open('https://twitter.com/home?status=Fact Or Fiction http://www.example.com/; return false;">
<img src="{% static "images/twitter.jpg" %}" alt="Share to Twitter.">
</a>
<a class="list-group-item" href="https://plus.google.com/share?url=http://www.example.com/" onclick="window.open('https://plus.google.com/share?url=http://www.example.com/',null,'height=626,width=436,status=yes,toolbar=no,menubar=no,location=no'); return false;" target="_blank">
<img src="{% static "images/googleplus.jpg" %}" alt="Share to Google Plus.">
</a>
<a class="list-group-item" href="http://www.reddit.com/submit" onclick="window.open('http://www.reddit.com/submit?url=http://www.example.com/',null,'height=900,width=750,status=yes,toolbar=no,menubar=no,location=no'); return false;">
<img src="{% static "images/reddit.jpg" %}" alt="Share to Reddit.">
</a>
</div>
</div>
</div>
</div>
CSS:
.list-group-horizontal .list-group-item {
display: inline-block;
}
.list-group-horizontal .list-group-item {
margin-bottom: 0;
margin-left:-4px;
margin-right: 0;
}
.list-group-horizontal .list-group-item:first-child {
border-top-right-radius:0;
border-bottom-left-radius:4px;
}
.list-group-horizontal .list-group-item:last-child {
border-top-right-radius:4px;
border-bottom-left-radius:0;
}
.headerDiv {
float: left;
padding-top: 10px;
padding-left: 10px;
padding-right: 10px;
margin-bottom: 5px;
margin-right: 5px;
}
.headerDiv div {
display:table-cell;
}
.titleDiv {
position: relative;
top: 30px;
width:100%;
}
I have tried putting the two divs inside another, however for some reason this causes my buttons to be vertical, and still beneath the logo.
I'm open to all suggestions, including telling me that I'm going about this completely wrong. Thanks in advance.
Bootstrap is easy as long as you understand the fundamental concept and basic structure. It general has a structure of a container with rows and within each row, you could have several cols. With that in mind, it is as easy as this:
<div class="container">
<div class="row">
<div class="headerDiv col-xs-4">
<img src="https://placehold.it/200x50">
<h1 id="title">Company Name</h1>
</div>
<div class="list-group list-group-horizontal col-xs-8">
<img src="https://placehold.it/80x20">
<img src="https://placehold.it/80x20">
<img src="https://placehold.it/80x20">
<img src="https://placehold.it/80x20">
</div>
</div>
</div>
With minimum styling as:
.headerDiv {
display:inline;
float:left;
}
h1#title {
display:inline;
}
.list-group {
float: right;
}
You can style the rest of margins and alignment of text as you need.

How to make images height/width/padding auto scale to fit images in properly

What I want to do is have the images on this site change in width and height (they should be equal) between 50-60px. However between them they all need to have a minimum padding of 5px. This can vary depending on the size of the images, this is the case as the two end images need to fit to the edges of the parent div, to align with an image about it. The height/width/padding should all change to ensure the images are still properly aligned when then screen size changes.
If you look at this page you will be able to see what I mean. The images that need to change are the grey squares at the bottom.
http://media.gaigo.org/work2.html
This is my html:
<div class="smallImages">
<div><img src="static/img/smallImage.png"></div>
<div><img src="static/img/smallImage.png"></div>
<div><img src="static/img/smallImage.png"></div>
<div><img src="static/img/smallImage.png"></div>
</div>
and my css is as follows:
smallImages div {
display: inline-block;
padding: 5px;
}
.smallImages div img {
max-width: 60px;
min-width: 50px;
max-height: 60px;
min-height: 50px;
}
Sorry if this seems confusing. Just ask if you need me to explain more.
One option is to set percentage widths, however that number percentage is dependent upon the number of images in your row. See this example:
* {
box-sizing:border-box; /* You need this so that heights and widths are inclusive of padding and border */
}
.container {
width:400px; /* set this to whatever you like, it should work still */
padding:5px;
border:1px solid;
}
.row {
width:100%;
padding:0 5px;
}
.row img {
padding:5px;
}
.row.one img {
width:100%;
}
.row.two img {
width:50%;
}
.row.three img {
width:33.33%;
}
.row.four img {
width:25%;
}
<div class="container">
<div class="row one">
<img src="http://placehold.it/150x150">
</div>
<div class="row two">
<img src="http://placehold.it/150x150"><!--
--><img src="http://placehold.it/150x150">
</div>
<div class="row three">
<img src="http://placehold.it/150x150"><!--
--><img src="http://placehold.it/150x150"><!--
--><img src="http://placehold.it/150x150">
</div>
<div class="row four">
<img src="http://placehold.it/150x150"><!--
--><img src="http://placehold.it/150x150"><!--
--><img src="http://placehold.it/150x150"><!--
--><img src="http://placehold.it/150x150">
</div>
</div>
Putting HTML comments between lines means there's no white space between the images.
This is what you are after.
Display inline-block wont let the images behave in that manner you need to use table.
You should just check the source code of the site you are working from..
.row {
display: table-row;
}
.smallImages {
padding-left: 0px;
margin-bottom: 0px;
display: table;
text-align: center;
}
.smallImages .row div {
display: table-cell;
padding: 5px;
}
.smallImages .row div:first-child {
padding-left: 0;
}
.smallImages .row div img {
max-width: 100%;
}
img {
border: 0;
}
<div class="smallImages">
<div class="row">
<div>
<a href="#item-1">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-2">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-3">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-4">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-5">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-6">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-7">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-8">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-9">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-10">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-11">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
<div>
<a href="#item-12">
<img src="http://media.gaigo.org/static/img/smallImage.png">
</a>
</div>
</div>
</div>