Different spacing between images - html

Using Bootstrap, I am trying to get a larger margin space on the left and right of the screen and a thin space between images. Attempted to individually target images and play around with the margin but that changes the image size and since different images has different margin sizes, the images are not even.
Attempted to target all the images to have the same margin but the gap is too much which is not what I want is there a way around this? Added images to show what I want and what I currently have. My code as follows:
Expected outcome (Large margin left and right, thin margin between images)
Current Outcome (No margin left and right, large margin between images)
HTMl
<div class="row">
<div class="row" class="top-img-custom">
<div class="text-center col-md-4">
<img class="img-responsive" src="http://via.placeholder.com/650x512" alt="Smiley face">
</div>
<div class="text-center col-md-4">
<img class="img-responsive" src="http://via.placeholder.com/650x512" alt="Smiley face">
</div>
<div class="text-center col-md-4">
<img class="img-responsive" src="http://via.placeholder.com/650x512" alt="Smiley face">
</div>
</div>
</div>
CSS
.top-img-custom{
margin-left: 20px;
margin-right: 20px;
}

To achieve expected result, use below CSS
.top-img-custom{
margin-left: 20px;
margin-right: 20px;
padding-left:20px;
padding-right:20px;
}
.text-center {
text-align: center!important;
padding: 1px;
}
img{
width:100%;
}
https://codepen.io/nagasai/pen/dzNGqv
And as I mentioned before use both classes in one class-

body{
background-color: #f2f2f2!important;
}
.top-img-custom{
margin:10px 25px!important;
}
.top-img-custom .text-center{
padding: 0 1px!important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="row top-img-custom" >
<div class="text-center col-md-4 col-sm-4 col-xs-4">
<img class="img-responsive" src="https://www.w3schools.com/html/pic_mountain.jpg" alt="Smiley face">
</div>
<div class="text-center col-md-4 col-sm-4 col-xs-4">
<img class="img-responsive" src="https://www.w3schools.com/html/pic_mountain.jpg" alt="Smiley face">
</div>
<div class="text-center col-md-4 col-sm-4 col-xs-4">
<img class="img-responsive" src="https://www.w3schools.com/html/pic_mountain.jpg" alt="Smiley face">
</div>
</div>
</div>

This behaviour won't come totally easy to the bootstrap grid system - it is pretty much designed for 15px padding in each of its col- classes, and a negative margin on the containing row classes to compensate at the edges. Messing with those, it is pretty easy to get some accidental element wrapping or horizontal scrollbars.
My approach might be to leave the row and col- classes alone to size themselves, but give the contents of your col- classes a negative margin to fill more of the space. And you would have to be tricky if you didn't want this on the edge elements.
This css should work:
.top-image-custom .img-responsive {
margin-left: -12px;
margin-right: -12px;
}
If you don't want this on the edge elements then using some :first-of-type and :last-of-type selectors may help, or assign new classes in your html to differentiate.

Related

Using CSS or HTML how can I eliminate the margins of a website?

I am building the project section of my personal website.
It looks the following way:
Website
I am trying to get rid of the left margin so my image can start from the left margin.
This my current code:
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
<div class="row-lg-4">
<div class="hovereffect">
<img class="img-responsive" src="../Projects/img/cyberSecurity.jpg" height = "600vh" width = "100vw" alt="">
<div class="overlay">
<h2>Effect 12</h2>
<p>
LINK HERE
</p>
</div>
</div>
</div>
</div>
I have tried doing inline CSS
<body style="margin:0; padding:0;">
It does not work.
I have also tried doing:
* {
margin: 0;
padding: 0;
}
in my css file. However, that did not work either.
Any sort of help would be highly appreciate it :D
Have a wonderful day.
To remove padding/margin in bootstrap, do something like this.
Add no-padding class to padding: 0px; for bootstrap columns and no-marginLR class to margin-left:0; and margin-right:0; for bootstrap rows.
here, no-padding and no-marginLR are used as example purpose.
<div class="container">
<div class="row no-marginLR">
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 no-padding">
...your code
</div>
</div>
If you want multiple columns that go edge to edge you could just use .no-gutters on the .row and make sure it's not nested in a .container.
<div class="row no-gutters">
<div class="col-12 col-sm-6 col-md-8">.col-12 .col-sm-6 .col-md-8</div>
<div class="col-6 col-md-4">.col-6 .col-md-4</div>
</div>
There are some stuff that you should fix in order to get this done without any kind of "force".
You need to wrap the all this in one row div (div class="row"), since a column must be inside a row like this:
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
<div class="row-lg-4>
<div class="hovereffect">
<img class="img-responsive" src="../Projects/img/cyberSecurity.jpg" height = "600vh" width = "100vw" alt="">
<div class="overlay">
<h2>Effect 12</h2>
<p>
LINK HERE
</p>
</div>
</div>
</div>
</div>
</div>
Make sure that " <div class="hovereffect">" doesnt have any kind of spacing property added in the CSS File.
This line by default would have a padding of 15px, so you can get rid of this padding by adding the class "px-0". (if it is inside of a row, you dont need to do this).
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
As a final resource if any of these worked for you (they should work since thats how the grid system works), you can created your own not padding class that would look like this:
.nospacing {
padding: 0 !important;
margin: 0 !important;
}
Then you can add it to any of your HTML Tags.

How to centralize a "short bio"?

I've made a short bio for me, which has my picture, my name and e-mail. I've been trying for hours to centralize it in my page, but I can't find a way to do it.
I used Bootstrap for this, making a column with size 2 for the picture and a column with size 10 for the text. I tried removing the whole grid thing, working with float: left and float: right to align the image and text and then centralizing everything, tried display: block; margin: 0 auto; too, but no success.
I believe the solution lies in creating a single element which has the image and text side to side and then centralizing it, though I can't seem to find a way to do it.
I would be grateful if someone explained how to achieve the desired effect.
Edit: Here's a picture of what I mean to achieve: https://i.imgur.com/vWgPg2M.png
That's what I got right now:
.profile-pic {
border-radius: 50%;
}
<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-md-2 col-xs-9">
<img class="img-responsive profile-pic" src="https://avatars0.githubusercontent.com/u/9438853">
</div>
<div class="col-md-10 col-xs-auto">
<h1>Telmo "Trooper"</h1>
<h4>telmo.trooper#gmail.com</h4>
</div>
</div>
</div>
I defined a class mycenter and set the flexbox property for it. The class is added to the row.
Please note the flex property may have compliance issues for older browsers. See here for details.
.profile-pic {
border-radius: 50%;
}
.mycenter {
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
<div class="container-fluid">
<div class="row mycenter">
<div class="col-md-2 col-xs-9">
<img class="img-responsive profile-pic" src="https://avatars0.githubusercontent.com/u/9438853" width="200">
</div>
<div class="col-md-10 col-xs-auto">
<h1>Telmo "Trooper"</h1>
<h4>telmo.trooper#gmail.com</h4>
</div>
</div>
</div>
I used the offset class of Bootstrap to push the div, and added text-align:center;
NOTE: This is only applicable when the browser's size is within the range of col-xs, this is because you included col-md, meaning when it reached the range of col-md, it will use whatever you put in col-md. To make it applicable to all, you can remove col-md in both div so that the col-xs will be the default class for all sizes
body {
text-align: center;
}
.profile-pic {
border-radius: 50%;
}
<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-md-2 col-xs-8 col-xs-offset-2">
<img class="img-responsive profile-pic" src="https://avatars0.githubusercontent.com/u/9438853">
</div>
<div class="col-md-10 col-xs-8 col-xs-offset-2">
<h1>Telmo "Trooper"</h1>
<h4>telmo.trooper#gmail.com</h4>
</div>
</div>
</div>

Two column bootstrap layout without any padding or spaces

This is similar to the layout I'm trying to achieve:
The code I have now
<div class="row ">
<div class="col-lg-6 row-eq-height push-right">
<img src="1.jpg" class="img-responsive">
</div>
<div class="col-lg-6 row-eq-height">
<div class="eq-row-text ">
<p class="row-text">Text description for image </p>
</div>
</div>
</div>
<div class="row ">
<div class="col-lg-6 row-eq-height ">
<div class="eq-row-text ">
<p class="row-text"> Text description for the image </p>
</div>
</div>
<div class="col-lg-6 row-eq-height">
<img src="1.jpg" class="img-responsive">
</div>
</div>
I have tried using CSS class "no-padding" and also tried playing around with margins. when i apply 0 padding, the left side of the first image touches the edge of the browser( this is desired), however the other edge(right side of image) still has some empty space.
How do I get rid of that empty space get the results like the reference layout?
.col-md-6{
padding-right: 0px;
padding-left: 0px;
}
There could be an issue with the <p> padding/margin, could also be an issue with the <img> padding/margin. However it seems to be an issue with the sizing of the elements within the row.
I did however seemingly fix the issue in my PEN HERE
I added a height: *** to the row class, this may be needed for desired results as you are using row-eq-height bootstrap class.
HTML
<div class="row ">
<div class="col-lg-6 row-eq-height push-right">
<img src="1.jpg" class="img-responsive">
</div>
<div class="col-lg-6 row-eq-height">
<div class="eq-row-text ">
<p class="row-text">Text description for image </p>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6 row-eq-height ">
<div class="eq-row-text ">
<p class="row-text"> Text description for the image </p>
</div>
</div>
<div class="col-lg-6 row-eq-height">
<img src="1.jpg" class="img-responsive">
</div>
</div>
CSS
p{
margin: 0;
padding: 0;
}
img{
margin: 0;
padding: 0;
}
.row {
margin: 0;
padding: 0;
height:60px;
background-color: #eee
}
If using the LESS/SASS source: change #grid-gutter-width in the variables file to 0
If you want to get rid of the white space you will need to make your image bigger to span the cols. You can manually adjust the width of an image using css:
img {
width: 100%;
}

Can't get images into proper container. Images stacked, divs out of order?

I'm a visual designer, so this may seem a silly question (and at one point, this wasn't broken!) but I'm stuck. I'm trying to get images to appear in a responsive row with a mouseover.
Can anyone help? I know the code is jacked; I've been struggling with the order of the divs. The mouseover is working, BUT the images are now stacking and aren't appearing in a row anymore. They're outside of the col-lg-4 container, but I've included that. What am I missing?
*image is FPO
/// HTML:
<div class="col-lg-12">
<div class="highlight">
<h3>LOREM IMPSUM DOLAR</h3>
<h5>The fox and the rabbit.</h5>
</div>
</div>
<div class="row">
<div class="col-lg-4">
<figure class="cap-left">
<div class="thumbnail">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/T_Roosevelt.jpg/473px-T_Roosevelt.jpg" alt="">
<figcaptions><h4>Please let this work</h4></figcaptions>
</div>
</figure>
</div>
</div>
<div class="col-lg-4">
<figure class="cap-left">
<div class="thumbnail">
<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/T_Roosevelt.jpg/473px-T_Roosevelt.jpg" alt="">
<figcaptions><h4>Please let this work</h4></figcaptions>
</div>
</figure>
</div>
</div>
/// JSFiddle:
http://jsfiddle.net/zvcNa/
This is due to your padding: 30px 40px; for figcaptions{}.
figcaptions is 100% width and height, but add your padding to this size.
Remove this padding and add it to your figcaptions children :
figcaptions h4{
padding:30px;
}
FIDDLE
EDIT #1:
Replaced :
figure {
display: block;
position: relative;
}
.col-lg-4 {
display:block;
float:left;
}
FIDDLE

Adjusting and image size to fit a div with Bootstrap

I'm trying to get an image to fit within a specific size div. Unfortunately, the image isn't conforming to it and is instead proportionally shrinking to a size that isn't big enough. I'm not sure what the best way is to go about getting the image to fit inside it is.
If this isn't enough code, I'd be happy to supply more, and I'm open to fixing any other errors that I am overlooking.
Here is the HTML
<div class="span3 top1">
<div class="row">
<div class="span3 food1">
<img src="images/food1.jpg" alt="">
</div>
</div>
<div class="row">
<div class="span3 name1">
heres the name
</div>
</div>
<div class="row">
<div class="span3 description1">
heres where i describe and say "read more"
</div>
</div>
</div>
My CSS
.top1{
height:390px;
background-color:#FFFFFF;
margin-top:10px;
}
.food1{
background-color:#000000;
height:230px;
}
.name1{
background-color:#555555;
height:90px;
}
.description1{
background-color:#777777;
height:70px;
}
Try this way:
<div class="container">
<div class="col-md-4" style="padding-left: 0px; padding-right: 0px;">
<img src="images/food1.jpg" class="img-responsive">
</div>
</div>
UPDATE:
In Bootstrap 4 img-responsive becomes img-fluid, so the solution using Bootstrap 4 is:
<div class="container">
<div class="col-md-4 px-0">
<img src="images/food1.jpg" class="img-fluid">
</div>
</div>
You can explicitly define the width and height of images, but the results may not be the best looking.
.food1 img {
width:100%;
height: 230px;
}
jsFiddle
...per your comment, you could also just block any overflow - see this example to see an image restricted by height and cut off because it's too wide.
.top1 {
height:390px;
background-color:#FFFFFF;
margin-top:10px;
overflow: hidden;
}
.top1 img {
height:100%;
}
Just a heads up that Bootstrap 4 now uses img-fluid instead of img-responsive, so double check which version you're using if you're having problems.
Simply add the class img-responsive to your img tag, it is applicable in bootstrap 3 onward!
I used this and works for me.
<div class="col-sm-3">
<img src="xxx.png" style="width: auto; height: 195px;">
</div>
I had this same problem and stumbled upon the following simple solution. Just add a bit of padding to the image and it resizes itself to fit within the div.
<div class="col-sm-3">
<img src="xxx.png" class="img-responsive" style="padding-top: 5px">
</div>
If any of you looking for Bootstrap-4. Here it is
<div class="row no-gutters">
<div class="col-10">
<img class="img-fluid" src="/resources/img1.jpg" alt="">
</div>
</div>
Most of the time,bootstrap project uses jQuery, so you can use jQuery.
Just get the width and height of parent with JQuery.offsetHeight() and JQuery.offsetWidth(), and set them to the child element with JQuery.width() and JQuery.height().
If you want to make it responsive, repeat the above steps in the $(window).resize(func), as well.