How do I put space between my Bootstrap columns? [duplicate] - html

This question already has answers here:
Borders between columns of Bootstrap Grid not working
(3 answers)
Closed 5 years ago.
I am trying to make a website using Bootstrap, and when I tried putting two columns beside each other (they together come out to the 12 allowed columns in bootstrap) they just get squished together. I tried adding a margin to one of the columns, but that just caused the smaller column to wrap and end up under the larger one.
<div class="container">
<div class="row">
<div class="col-sm-8s">
<div class="featuredPost">
<h2>Featured Post <hr></h2>
<img src="Images/placeholderImg.jpg" alt="Featured Image">
<p>
Portland aesthetic cardigan cloud bread brooklyn food truck blog leggings quinoa street art franzen. Fixie swag artisan ennui vaporware cred. Church-key direct trade neutra try-hard tilde typewriter selfies butcher trust fund. Aesthetic iceland small batch ugh health goth you probably haven't heard of them glossier fixie before they sold out fingerstache knausgaard cloud bread slow-carb. Man bun gluten-free sartorial, thundercats blog man braid banjo. Skateboard poke hot chicken pickled, tote bag tacos 90's..Read More »
</p>
</div>
</div>
<aside class="authorBio col-sm-4">
<div class="widget">
<div class="row">
<img class="col-sm-6" src="Images/AimeeAvatar.jpg" alt="Avatar">
<h1 class="col-sm-6">Aimée LeVally</h1>
</div>
<hr>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur.
</p>
</div><!-- widget -->
</aside>
</div><!-- row -->
</div>
.authorBio {
background-color: #fff4e8;
padding: 15px 50px 30px 50px;
text-align: justify;
border: 5px solid #f7ddc0;
}
.authorBio h1 {
text-align: justify;
color: #ad4b34;
}
.authorBio img {
width: 50%;
-webkit-border-radius: 100%;
-moz-border-radius: 100%;
border-radius: 100%;
}
.featuredPost {
background-color: #fff4e8;
padding: 15px 50px 30px 50px;
text-align: justify;
border: 5px solid #f7ddc0;
}
.featuredPost img {
width: 100%;
padding: 0 0 0 0;
margin: 0;
}
.featuredPost p {
padding-top: 25px;
}

I advise you to only use the column classes inside of <div> tags.
<div class="widget">
<div class="row">
<div class="col-sm-6">
<img src="Images/AimeeAvatar.jpg" alt="Avatar">
</div>
<div class="col-sm-6">
<h1 class="col-sm-6">Aimée LeVally</h1>
</div>
</div>
<hr>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur.
</p>
</div><!-- widget -->

You need to create div in columns, like:
<div class="col-sm-8">
<div class='extra_div_1'>
<div class="featuredPost">
<h2>Featured Post <hr></h2>
<img src="Images/placeholderImg.jpg" alt="Featured Image">
<p>
<a>Portland</a>
</p>
</div>
</div>
</div>
<aside class="authorBio col-sm-4">
<div class='extra_div_2'>
<div class="widget">
<div class="row">
<img class="col-sm-6" src="Images/AimeeAvatar.jpg" alt="Avatar">
<h1 class="col-sm-6">Aimée LeVally</h1>
</div>
<hr>
<p>
Lorem
</p>
</div>
</div>
</aside>
CSS:
.extra_div_1{
padding:0px 15px 0px 15px; // or margin
}
.extra_div_2{
padding:0px 15px 0px 15px; // or margin
}
Why ... because when You use margins for column - width became bigger then col-md-12 and Your column jump on bottom. So You need to create extra div in column and use padding/margin to make blank space between columns.

The problem is due to your applying a background-color directly to the Bootstrap Grid .col-*-* class. These classes use padding to create the spacing between each element, but a background would make it appear as though each grid element was immediately brushing up against the other.
Instead, place your background as a wrapper class - for example:
<div class="col-sm-8">
<div class="my-well">
<p>Hi I am some text</p>
</div>
</div>
With CSS along the lines of:
.my-well {
padding: 15px;
background: #999;
}

Always follow this rule with the Bootstrap grid:...
.col-* must be wrapped in .row, and only .col-* should be the
immediate child of row
https://www.codeply.com/go/uH5cQ5HB8X
Also, cols should be div, not other inline elements like img and h1. Since padding is used to create the "gutter" or spacing between columns, use a margin around the inner content of the column(s) to increase spacing. Therefore, your authorBio and featuredPost should be contained within the Bootstrap columns.
<div class="container">
<div class="row">
<div class="col-sm-8">
<div class="featuredPost">
..
</div>
</div>
<aside class="col-sm-4">
<div class="row">
<div class="col-sm-12">
<div class="authorBio">
<div class="row">
<div class="col-lg-6">
<img>
</div>
<div class="col-lg-6">
...
</div>
</div>
</div>
</div>
</div>
</aside>
</div>
<!-- row -->
</div>
https://www.codeply.com/go/uH5cQ5HB8X

Related

How to place background image and text inline in Bulma CSS?

I am creating a portfolio page. I am using Bulma. The thing I want is to place the background image and text inline.
Here's the code:
<section class="hero is-halfheight upload-descr" style = "height: 37em">
<div class="hero-body">
<div class="container">
<div class="clearfix"></div>
<hr class = "rm-descr-bar" style = "float: left;"></hr>
<div class="clearfix"></div>
<h1 class = "title">
Loren Ipsum
</h1>
<div class="content rm-has-medium-size">
<p class = "upload-descr-exp" aria-live = "polite" aria-atomic = "true">Lorem ipsum dolor sit amet, consectetur adipiscing<br />elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br />Ut enim ad minim veniam, quis nostrud exercitation<br />ullamco laboris nisi ut aliquip ex ea<br />ea commodo consequat. Duis aute irure dolor.</p>
</div>
</div>
</div>
</section>
The thing I want is background image shifted at right in <div class = "container">. However it gets cropped. I messed up with height and width of the container. This affected the text inside the container i.e. it was not vertically centered anymore. Please help.
I want to achieve this:
I tried:
<section class="hero is-halfheight upload-descr section" style = "height: 37em">
<div class="hero-body container" style = "background: url('/img/pic.png') no-repeat right; background-size: contain;">
<div class="container">
<div class="clearfix"></div>
<hr class = "rm-descr-bar" style = "float: left;"></hr>
<div class="clearfix"></div>
<h1 class = "title">
Loren Ipsum
</h1>
<div class="content rm-has-medium-size">
<p class = "upload-descr-exp" aria-live = "polite" aria-atomic = "true">Lorem ipsum dolor sit amet, consectetur adipiscing<br />elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.<br />Ut enim ad minim veniam, quis nostrud exercitation<br />ullamco laboris nisi ut aliquip ex ea<br />ea commodo consequat. Duis aute irure dolor.</p>
</div>
</div>
</div>
</section>
I achieved the thing I wanted after trying above code. However, on decreasing viewport size, background image and text appears on above other maybe they got vertical and horizontal centered. Please help me. How can I place background image and text next to each other without any bugs?
Here's the bug:
Idea
Left side text and right side the image
Give all the same background color
Example
(The image ratio is about 4:3. Change CSS according to your needs.)
.mySection {
background-color: #F93122;
color: white;
border: 1px solid white;
}
.myHero {
padding: 50px 0 50px 75px;
}
.myHero .hr {
display: inline-block;
width: 100px;
height: 15px;
background: white;
border-radius: 20px;
margin-bottom: 15px;
}
.myHero h1 {
font-size: 50px
}
#media(max-width: 768px) {
.myHero {
padding: 50px !important;
}
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.1/css/bulma.min.css">
<section class="mySection">
<div class="columns is-vcentered">
<div class="column is-5-tablet is-5-desktop">
<div class="myHero">
<div class="hr"></div>
<h1>Loren Ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dicta a et ipsa voluptates in velit rem minus nihil, blanditiis nisi, quidem tempore quos qui quas. Blanditiis hic dolorem fugiat? Blanditiis!</p>
</div>
</div>
<div class="column is-7-tablet is-7-desktop">
<figure class="image is4by3">
<img src="http://i64.tinypic.com/29gedzq.png">
</figure>
</div>
</div>
</section>
Hint
Bulma#image
You used two times container class as per my thought that is why you getting this bug. Are you want change background color red to and img ?

HTML and CSS, can't get the text to float next to an image correctly

I am trying to get my text to the right of an image but i've tried to float it right, i tried to even put it in a flexbox but nothing is seeming to work out very well. Here is the code that I have..
<div class="tab-content">
<div class="tab-pane active" id="tab_default_1">
<h2 class="text-dark-green">Kur Gin</h2>
<p>
<img class="img-responsive" style="height: 40em; width:30em; margin-top:25px; box-shadow: 10px 10px 5px #888888;" src="app/what-we-make/images/KurGin.jpg" alt="" />
</p>
<p>
Our gin, Kur (pronounced "cure") is made in the London Dry Gin style and is produced with Washington heirloom variety red winter wheat that emphasizes a backbone of classic juniper aromas and flavors with subtle citrus (Seville orange) as well as Douglas Fir and Braeburn apples from Mr. Liedholm's back yard.
</p>
</div>
<div class="tab-pane" id="tab_default_2">
<h2 class="text-dark-green">Stark Vatten</h2>
<p>
<img class="img-responsive" style="height:40em; width:30em; margin-top:25px; box-shadow: 10px 10px 5px #888888;" src="app/what-we-make/images/StarkVatten.jpg" alt="" />
</p>
<p>
Our vodka, Stark Vatten (Swedish for “strong water”), is produced with Washington heirloom variety red winter wheat and pure, filtered water to create a clean, viscous, oily vodka that displays a definitive classic European style while remaining a distinctive local product.
</p>
</div>
<div class="tab-pane" id="tab_default_3">
<h2 class="text-dark-green">White Dog Bourbon</h2>
<p>
<img class="img-responsive" style="height:40em; width:30em; margin-top:25px; box-shadow: 10px 10px 5px #888888;" src="app/what-we-make/images/bourbon.jpg" alt="" />
</p>
<p>
Duis autem vel eum iriure dolor in hendrerit in vulputate. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat
</p>
</div>
</div>
</div>
</div>
You can use a wrapper for image and ptext, make that wrapper a flex container having align-items: center; (if you want it vertically centered to the image) and give the the p the settings below.
.wrap {
display: flex;
align-items: center;
}
.wrap p {
flex: 1 0 100px;
padding-left: 20px;
}
<div class="tab-content">
<div class="tab-pane active" id="tab_default_1">
<h2 class="text-dark-green">Kur Gin</h2>
<div class="wrap">
<img class="img-responsive" style="height: 40em; width:30em; margin-top:25px; box-shadow: 10px 10px 5px #888888;" src="http://placehold.it/200x600/fa0" alt="" />
<p>Our gin, Kur (pronounced "cure") is made in the London Dry Gin style and is produced with Washington heirloom variety red winter wheat that emphasizes a backbone of classic juniper aromas and flavors with subtle citrus (Seville orange) as well as Douglas Fir and Braeburn apples from Mr. Liedholm's back yard.</p>
</div>
<div class="tab-pane" id="tab_default_2">
<h2 class="text-dark-green">Stark Vatten</h2>
<div class="wrap">
<img class="img-responsive" style="height:40em; width:30em; margin-top:25px; box-shadow: 10px 10px 5px #888888;" src="http://placehold.it/200x600/fa0" alt="" />
<p>
Our vodka, Stark Vatten (Swedish for “strong water”), is produced with Washington heirloom variety red winter wheat and pure, filtered water to create a clean, viscous, oily vodka that displays a definitive classic European style while remaining a distinctive local product.</p>
</div>
</div>
</div>
<div class="tab-pane" id="tab_default_3">
<h2 class="text-dark-green">White Dog Bourbon</h2>
<div class="wrap">
<p>
<img class="img-responsive" style="height:40em; width:30em; margin-top:25px; box-shadow: 10px 10px 5px #888888;" src="http://placehold.it/200x600/fa0" alt="" />
</p>
<p>
Duis autem vel eum iriure dolor in hendrerit in vulputate. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat
</p>
</div>
</div>
</div>
</div>
Use the .pull-left class on the p that wraps your images, and .clearfix on the parent to clear the float. Then you'll want to apply margin and padding to the text so that it aligns with your image.
Ignore the .tab-pane css here - just used for the demo so your hidden panes would show.
/* ignore this - just for demo */
.tab-pane {
display: block!important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="tab-content">
<div class="tab-pane active clearfix" id="tab_default_1">
<h2 class="text-dark-green">Kur Gin</h2>
<p class="pull-left">
<img class="img-responsive" style="height: 40em; width:30em; margin-top:25px; box-shadow: 10px 10px 5px #888888;" src="app/what-we-make/images/KurGin.jpg" alt="" />
</p>
<p>
Our gin, Kur (pronounced "cure") is made in the London Dry Gin style and is produced with Washington heirloom variety red winter wheat that emphasizes a backbone of classic juniper aromas and flavors with subtle citrus (Seville orange) as well as Douglas
Fir and Braeburn apples from Mr. Liedholm's back yard.
</p>
</div>
<div class="tab-pane clearfix" id="tab_default_2">
<h2 class="text-dark-green">Stark Vatten</h2>
<p class="pull-left">
<img class="img-responsive" style="height:40em; width:30em; margin-top:25px; box-shadow: 10px 10px 5px #888888;" src="app/what-we-make/images/StarkVatten.jpg" alt="" />
</p>
<p>
Our vodka, Stark Vatten (Swedish for “strong water”), is produced with Washington heirloom variety red winter wheat and pure, filtered water to create a clean, viscous, oily vodka that displays a definitive classic European style while remaining a distinctive
local product.
</p>
</div>
<div class="tab-pane clearfix" id="tab_default_3">
<h2 class="text-dark-green">White Dog Bourbon</h2>
<p class="pull-left">
<img class="img-responsive" style="height:40em; width:30em; margin-top:25px; box-shadow: 10px 10px 5px #888888;" src="app/what-we-make/images/bourbon.jpg" alt="" />
</p>
<p>
Duis autem vel eum iriure dolor in hendrerit in vulputate. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit
esse molestie consequat
</p>
</div>
</div>
</div>
</div>
You can get the text to the right of the image without the use of a table by using
"float:left" in the inline style of the image.

Can I use one Bootstrap column width (not equaling 12) in separate rows?

I have been trying to create two separate Bootstrap rows, each with a width of 8.
Unfortunately, both rows overlap each other. I've tried various approaches to solving the problem but nothing is working.
I'm curious if this is a problem with the way I'm using column widths.
Sorry for such a simple question - I'm fairly new to all of this.
HTML
<div class="container">
<!-- HEADLINE -->
<div class="row">
<div class="short-description col-xs-8">
<div class="listing-headline">
{{ adContent?.headline }}
</div>
<div class="location-info">
{{ location?.city }}, {{ location?.state }}, {{ location?.country }}
</div>
<hr>
</div>
</div>
<!-- DETAILS OVERVIEW -->
<div class="row">
<div class="details-overview col-xs-8" *ngFor="let info of unitContent">
<div class="rental-type">
{{ info?.unitContent.propertyType }}
</div>
<div class="guest-allowance">
</div>
<div class="space-type">
</div>
<div class="bed-number">
</div>
<hr>
</div>
</div>
</div>
CSS
.short-description {
height: 80px;
padding: auto;
margin-top: 20px;
}
.listing-headline {
font-style: bold;
font-size: 3em;
line-height: 120%;
}
.location-info {
margin-top: 15px;
font-weight: 300;
font-size: 1.4em;
}
.details-overview {
}
Your Bootstrap looks fine to me. I think it might be a CSS issue because if you remove the CSS there's no overlap.
Adding a margin-top in .details-overview may help.
Your class .listing-headline has a to big font size / line height for your .short-description class with height of 80px;
You have to decrease the font size or increase the height of .short-description for avoiding overlapping in your case.
When you delete the height of .short-description it looks nice:
.short-description {
margin-top: 20px;
}
Nothings wrong with your code. I think overlapping of both rows with each other is because of some codes missing with bootstrap stylesheets (either of bootstrap.css or bootstrap.min.css) you are using. It's better to get a new copy of it.
<div class="container">
<div class="row">
<div class="col-xs-8">
<div class="listing-headline">
HEADLINE 1
</div>
<!--/col-xs-8-->
<div class="location-info">
CITY, STATE, COUNTRY
</div>
<!--/col-xs-8-->
<hr>
</div>
<!--/col-xs-8-->
</div>
<!--/row-->
<div class="row">
<div class="col-xs-8">
<div class="rental-type">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<!--/rental-type-->
<div class="guest-allowance">
</div>
<!--/guest-allowance-->
<div class="space-type">
</div>
<!--/space-type-->
<div class="bed-number">
</div>
<!--/bed-number-->
<hr>
</div>
<!--/col-xs-8-->
</div>
<!--/row-->
</div>
<!--/container-->
<style type="text/css">
.short-description {
height: 80px;
padding: auto;
margin-top: 20px;
}
.listing-headline {
font-style: bold;
font-size: 3em;
line-height: 120%;
}
.location-info {
margin-top: 5px;
font-weight: 300;
font-size: 1.4em;
}
</style>

Position absolute bottom + scroll fix

I have the following element:
Where the "1 comment" button container is positioned absolute to the main container which is relative positioned.
There problem is when I resize it and scroll down, the "1 comment" button container is going up few px. I want it to keep it in the bottom.
Like a sticky footer positioned fixed to the main container.
I wouldn't want to use javascript for this.
You can see the code live, here.
Place all content in a div with:
overflow: scroll;
and put the footer outside the div with:
position: absolute; bottom: 0; width: 100%; margin: 0; padding: 0;
You should put everything in the container except the subtitle_box bottom inside a different container.
Then set the overflow-y on the different container, with a absolute position, and a bottom offset of the height of the subtitle_box bottom.
Something like this
<div id="container">
<div class="inner-container">
<div class="title_box">
<h1>Default Project</h1>
<p>September 29 2015</p>
</div>
<div class="subtitle_box high">
<h2>Incomplete work</h2>
</div>
<div class="subtitle_box dark">
<button class="btn btn_toggle"></button>
<h2>Task 1</h2>
<button class="btn btn_menu"></button>
</div>
<div class="subtitle_box">
<button class="btn btn_toggle"></button>
<h2>Goal</h2>
</div>
<div class="text_box">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div class="subtitle_box">
<button class="btn btn_toggle"></button>
<h2>Involved in this task</h2>
</div>
<div class="extra_box">
<div class="contact_box">
<button class="btn btn_toggle"></button>
<p class="bold">Samuel Rush</p> <span class="dot"></span>
<p>Strive Technologies</p>
<button class="btn right">Contact</button>
</div>
<div class="skills_box">
<p>PHP,CSS,Joomla,MySQL,JavaScript,HTML5</p>
</div>
</div>
</div>
<div class="subtitle_box bottom">
<button class="btn comment">1 Comment</button>
</div>
</div>
And then add the following css
.inner-container {
position:absolute;
left:0;
top:0;
right:0;
bottom:25px;
overflow-y:auto;
}
.bottom {
height:25px;
position:absolute;
bottom:0;
left:0;
right:0;
padding:0;
}
See http://jsfiddle.net/yhgsddcz/1/
You just need to put the .subtitle_box outside of your #container
You could use a wrapper to have some basic style like the madding, text-align.
remove position: relative from #container that wrap your comment box, .subtitle_box bottom will be relative to #pane instead.it work like a charm.
Congratulation !!!

Twitter bootstrap - DIV absolute positon to an image responsive enlarging

I have an image as a background with a div overlaying it. I'm trying to find ways to make it responsive and cover more of the picture as it gets smaller. I'm tried the below but I don't think even the column classes are doing what they are supposed to do.
<div class="row">
<div class="col-lg-12 col-md-12 col-xs-12"
<div id="test-container">
<img src="images/productsplash.jpg" alt="Home Page" class="img-responsive"/>
<div class="row">
<div class="col-lg-4 col-md-9 col-xs-12" id="products-container">
<div class="op-container col-lg-12 col-md-12"><h1>OUR PRODUCTS</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisiut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu</p>
</div>
<div class="col-lg-6 col-md-6" id="button-good"><p>Good <br>Products</p></div>
<div class="col-lg-6 col-md-6" id="button-bad"><p>Bad <br>Products</p></div>
</div>
</div>
</div>
</div>
#test-container {
position:relative;
display:inline;
}
#products-container {
position:absolute;
min-width:30%;
max-width:40%;
top:35%;
left:55%;
background-color: blue; /* currently missing opacity css*/
}
I had a thought of using media query to override the css for #products container. Couldn't get it to work. I essentially want it to cover half the div at something in the tablet range size and then overlay the picture completely.
Any thoughts on how to tackle?
You might putting the image as a background-image to a div, and setting the background-size to cover or contain.
The div should have the same classes as the covering div eg: col-lg-4 col-md-9 col-xs-12
Something like
HTML
<div class="col-lg-4 col-md-9 col-xs-12 responsive-image"
style="background-image: url(/dynamic/image/url.png)">
</div>
CSS
.responsive-image {
background-size: cover; /* or contain */
background-position: center center;
height: 300px; /* or 25vh - 25% of viewport height */
}
The only drawback is that you have to control the height of the image div, because on its own it won't automatically expand to best fit the image
Also see viewport units compatibility