I am trying to make something similar to the below image via bootstrap 4.
You can assume that the black rectangle is the window, the green is a div with the three elements inside, it should be vertically in the center, the red is text and the oranges are two buttons.
This is my code but it doesn't work:
The three elements should stack in rows if the window width is too small.
<div class="row justify-content-md-center">
<div class="col-sm-12">
<span class="btn-projects scrollto">blablablablablablasalkadfjklasd</span>
<span class="row justify-content-md-center">
<span class="col-s-2">
<a href="/" class="btn-get-started scrollto"><i class="fa fa-google"
style="color:tomato;margin-left:4px;"></i></a>
</span>
<span class="col-s-2">
<a href="/" class="btn-get-started scrollto"><i class="fa fa-linkedin"
style="color:tomato;margin-left:4px;"></i></a>
</span>
</span>
</div>
</div>
Thanks for help.
A good way to use bootstrap is to use the col and row bootstrap classes to map the content to the page, in your case a nice way to do it would be to create a row and inside of it create 3 columns using col class, to align I'd just use plain old styling to vertical and horizontal align the contents:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="row" style="border: 2px solid black;height:150px;padding:0;margin:0">
<div class="col-sm-12" style="display:flex;justify-content:center;align-items:center">
<div class="row"
style="border: 1px solid green;display:flex;justify-content:center;align-items:center;text-align:center">
<span class="col-sm-2">
<i class="fa fa-md fa-google" style="color:tomato;"></i>
</span>
<span class="col-sm-8" style="border: 1px solid red">blablablablablabla</span>
<span class="col-sm-2">
<i class="fa fa-md fa-linkedin" style="color:tomato;"></i>
</span>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
The code is basically the same as yours with the propper rearrangements and the center styling, the height of the sample is set to 150px for sample purposes, but you can set it to 100% or whatever height you wish in your project. The col relative proportions I used are also for demonstration purposes, you can, of course, use whatever dimensions you need.
I just added the propper external linkage so the snippet can be ran.
Note that the inline styling is also for sample purposes, you can/should place these in a style sheet.
Add width to child two to set fixed width.
.black {
border: 1px black solid;
padding: 5% 10%;
margin: 10%;
}
.main {
border: 1px green solid;
padding: 5px;
display: flex;
}
.child{
display: inline-block;
width: 100%;
padding: 15px 0px;
}
.child.one:hover,
.child.three:hover{
cursor: pointer;
background-color: #efefef;
}
.child.one{
width: 50px;
border: 1px #ff9800 solid;
text-align: center;
}
.child.two{
width: 100%;
margin: 0px 5px;
padding: 15px;
border: 1px red solid;
}
.child.three{
width: 50px;
border: 1px #ff9800 solid;
text-align: center;
}
<div class="black">
<div class="main">
<a class="child one">G</a>
<div class="child two">Hurraaayyy!</div>
<a class="child three">G</a>
</div>
</div>
You can manage width inside row according to these predefined classes col-sm-12 col-md-7 col-lg-6 col-xl-5. So there is no need inline CSS.
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="container">
<div class="row justify-content-center border border-dark p-5">
<div class="col-sm-12 col-md-7 col-lg-6 col-xl-5">
<div class="row justify-content-center align-items-center border border-success text-center">
<span class="col-2">
<a href="/" class="text-warning">
<i class="fa fa-md fa-star"></i>
</a>
</span>
<span class="col-8 border border-danger">
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</span>
<span class="col-2">
<a href="/" class="text-warning">
<i class="fa fa-md fa-star"></i>
</a>
</span>
</div>
</div>
</div>
</div>
Related
This question already has answers here:
Make container shrink-to-fit child elements as they wrap
(4 answers)
Closed 9 months ago.
Using bootstrap 4.6 and flexbox.
I'm trying to have a horizontal line filling the space between the two other div.
When the text is short, the flex elements stops at the end of the text, as expected. But when the text takes 2 line there is an extra space, and not enough space remaining to have the line displaying.
How can I get rid of it ?
.title, .price {
border: 1px dotted #777;
}
.line {
border-top: 2px dotted black;
margin: 0 20px;
flex: 1;
align-self: center;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css" integrity="sha512-P5MgMn1jBN01asBgU0z60Qk4QxiXo86+wlFahKrsQf37c9cro517WzVSPPV1tDKzhku2iJ2FVgL67wG03SGnNA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<div class="d-flex mt-5">
<div class="title">
<h1>Some text</h1>
</div>
<div class="line">
</div>
<div class="price">
$99
</div>
</div>
<div class="d-flex mt-5">
<div class="title">
<h1>Some other text that is long and takes two line to display</h1>
</div>
<div class="line">
</div>
<div class="price">
$99
</div>
</div>
You could use the text-justify attribute to fill the space remaining after the break. If you want the center line to show, you may want to consider adding an explicit width to the text containers so they don't resize based on the amount of text and the window size. See also: https://www.w3schools.com/cssref/css3_pr_text-justify.asp
.title,
.price {
border: 1px dotted #777;
text-align: justify;
text-justify: inter-word;
}
#longerText {
width: 500px;
}
.line {
border-top: 2px dotted black;
margin: 0 20px;
flex: 1;
align-self: center;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css" integrity="sha512-P5MgMn1jBN01asBgU0z60Qk4QxiXo86+wlFahKrsQf37c9cro517WzVSPPV1tDKzhku2iJ2FVgL67wG03SGnNA==" crossorigin="anonymous" referrerpolicy="no-referrer"
/>
<div class="d-flex mt-5">
<div class="title">
<h1>Some text</h1>
</div>
<div class="line">
</div>
<div class="price">
$99
</div>
</div>
<div class="d-flex mt-5">
<div id="longerText" class="title">
<h1>Some other text that is long and takes two line to display</h1>
</div>
<div class="line">
</div>
<div class="price">
$99
</div>
</div>
Add the Bootstrap-class text-justify to the element where you want the text to fill all availble space:
.title,
.price {
border: 1px dotted #777;
}
.line {
border-top: 2px dotted black;
margin: 0 20px;
flex: 1;
align-self: center;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css" integrity="sha512-P5MgMn1jBN01asBgU0z60Qk4QxiXo86+wlFahKrsQf37c9cro517WzVSPPV1tDKzhku2iJ2FVgL67wG03SGnNA==" crossorigin="anonymous" referrerpolicy="no-referrer"
/>
<div class="d-flex mt-5">
<div class="title">
<h1>Some text</h1>
</div>
<div class="line">
</div>
<div class="price">
$99
</div>
</div>
<div class="d-flex mt-5">
<div class="title text-justify">
<h1>Some other text that is long and takes two line to display</h1>
</div>
<div class="line">
</div>
<div class="price">
$99
</div>
</div>
I want to get the <hr> element next to my Icons, I set the style of Display to .inline-grid to let the hr element stay right next to my Icons.
The Problem is that I need to give it a width to because inline-grid takes it full size width.
How can the hr element be full size and still be between the Icons?
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<span style="cursor: pointer">
<span class="glyphicon glyphicon-chevron-down"></span>
<hr style="width: 100px;margin-left: 0px;margin-right: 0px;display: inline-grid;margin-bottom: 0px;"/>
<span class="glyphicon glyphicon-chevron-down"></span>
</span>
</div>
</div>
Edit: the <hr> element should still be horizontal. (Icon horizontal line Icon) <= this should take the complete row width.
Edit2: wrong bootstrap Version in snipped. Changed to 3.3.7.
Instead display inline-grid use display flex.
hr {
flex:1;
}
.wrapper {
cursor: pointer;
width: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="wrapper d-flex justify-content-center align-items-center">
<span class="glyphicon glyphicon-chevron-down">V</span>
<hr/>
<span class="glyphicon glyphicon-chevron-down">V</span>
</div>
</div>
</div>
Set these properties in style vertical-align: middle; margin: 0;
You can try this :
<div class="row">
<span style="cursor: pointer">
<span class="glyphicon glyphicon-chevron-down">V</span>
<hr class="m-0 pl-3 pr-3">
<span class="glyphicon glyphicon-chevron-down">V</span>
</span>
All that I need is put padding or margin between columns.
If I set it in css, the columns break down.
The code html and css is here:
https://codeshare.io/2pwRPz
Without margin, 3 columns, ok but without space:
With css margin, not ok:
My css, uncomment this css to see the problem
This is breaking to the next line because of the margin left you are applying - to get the desired space - what you need to do is to insert the cards WITHIN the col-md-4, and put padding to the div so that the cards will have space between them, but remain within the bootstrap layout.
//css
.cards-postagens-wrapper {
padding: 15px;
}
.cards-postagens {
background-color: #d4ecd6;
height: 9em;
text-align: left;
border-radius: 8px;
}
//html
<div class="col-sm-12 col-md-4 cards-postagens-wrapper">
<div class="cards-postagens">
<div class="badge badge-primary badge-postagens">categoria blog</div>
<div>12 a column here</div>
</div>
</div>
This is demoonstrated by the following snippet.
.cards-postagens-wrapper {
padding: 15px;
}
.cards-postagens {
background-color: #d4ecd6;
height: 9em;
text-align: left;
border-radius: 8px;
}
.badge-postagens {
margin-top: 2%;
margin-left: 2%;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<div class="container" id="corpo-pagina">
<div class="container-fluid" id="corpo-pagina-conteudo">
<div class="row">
<div class="col-xs-4 col-sm-4 col-md-4 cards-postagens-wrapper">
<div class="cards-postagens">
<div class="badge badge-primary badge-postagens">
categoria blog
</div>
<div>11 a column here</div>
</div>
</div>
<div class="col-xs-4 col-sm-4 col-md-4 cards-postagens-wrapper">
<div class="cards-postagens">
<div class="badge badge-primary badge-postagens">
categoria blog
</div>
<div>11 a column here</div>
</div>
</div>
<div class="col-xs-4 col-sm-4 col-md-4 cards-postagens-wrapper">
<div class="cards-postagens">
<div class="badge badge-primary badge-postagens">
categoria blog
</div>
<div>11 a column here</div>
</div>
</div>
</div>
I am having a problem on putting a border on the left most part of a section outside a container. I tried putting a margin-left on the container-fluid but the line should be inline with the section only. Right now the line is in the blue line. Please see image for better explanation.
Here's the current code
.store_details_item_wrapper {
padding-left: 20px;
border-left: 10px solid blue;
}
.store_details_img_wrapper {
border: 5px solid black;
height: 100px;
width: 100px;
margin-bottom: 15px;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="section-wrapper">
<div class="container">
<div class="row store_details_row">
<div class="store_details col col-md-4 order-12 order-md-1">
<div class="store_details_img_wrapper">
<img class="store_details_img" media={props.fields.logo} />
</div>
<div class="store_details_item_wrapper">
<div class="store_details_item">
<i class="fa fa-clock" />
Text here
</div>
<hr />
<div class="store_details_item">
<i class="fa fa-parking" />
Text here
</div>
</div>
</div>
<div class="store_description col-12 col-md-8 order-1 order-md-12">
<Image
class="store_description_banner img-fluid"
media={props.fields.herobanner}
/>
</div>
</div>
</div>
</div>
Since you have used border-left this is 1 solution.
or you can use position: absolute and left with negative values to .store_details_item_wrapper
.store_details_item_wrapper {
padding-left: 60px;
border-left: 10px solid blue;
margin-left: -70px;
}
.store_details_img_wrapper {
border: 5px solid black;
height: 100px;
width: 100px;
margin-bottom: 15px;
}
.container-fluid{
border: 2px solid black;}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="container-fluid">
<div class="container">
<div class="row store_details_row">
<div class="store_details col col-md-4 order-12 order-md-1">
<div class="store_details_img_wrapper">
<img class="store_details_img" media={props.fields.logo} />
</div>
<div class="store_details_item_wrapper">
<div class="store_details_item">
<i class="fa fa-clock" /> Text here
</div>
<hr />
<div class="store_details_item">
<i class="fa fa-parking" /> Text here
</div>
</div>
</div>
<div class="store_description col-12 col-md-8 order-1 order-md-12">
<Image class="store_description_banner img-fluid" media={props.fields.herobanner} />
</div>
</div>
</div>
</div>
I'm trying to show two divs next to each other using Bootstrap, but there is a distance between them. How can i place them exactly next to each other.
The code:
<div class="col-lg-8 col-lg-offset-2 centered">
<div style="float: left; border: 1px solid; width: 227px; height: 50px;"></div>
<div style="float: right; border: 1px solid;width: 227px; height: 50px;"></div>
</div>
Image illustration:
Look into grids in Bootstrap.
You could do something like this:
<div class="row">
<div class="col-xs-6">div 1</div>
<div class="col-xs-6">div 2</div>
</div>
Adding to Lschessinger's answer you could use offset to center the blocks. Look here under Offsetting columns
Maybe this is what you're looking for?
<style>
.border {border: 1px solid #CCC;}
</style>
<div class="row">
<div class="col-xs-2 border col-xs-offset-4">div 1</div>
<div class="col-xs-2 border">div 2</div>
</div>
Or if you have to stick to your code with the inline styles and specific widths then maybe this, you can increase the width between by increasing the width 454px to 464px for a 10px gap, and so on:
<div class="col-lg-12">
<div style="width: 454px;" class="center-block">
<div style="border: 1px solid; width: 227px; height: 50px;" class="pull-left"></div>
<div style="border: 1px solid; width: 227px; height: 50px;" class="pull-right"></div>
</div>
</div>
One approach is to have a row containing two div elements. The elements will seemingly stack next to each other due to the fact that Bootstrap is built with flexbox.
In the following example I'm using the class justify-content-center to center both elements. And col-auto that will size columns based on the natural width of their content.
div{border:1px solid blue}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<div class="container">
<div class="row justify-content-center p-3">
<div class="col-auto">
content one
</div>
<div class="col-auto">
content two
</div>
</div>
</div>
Align the elements to the left by using justify-content-start
div{border:1px solid blue}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<div class="container">
<div class="row justify-content-start p-3">
<div class="col-auto">
content one
</div>
<div class="col-auto">
content two
</div>
</div>
</div>
Align the elements to the right by using justify-content-end
div{border:1px solid blue}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<div class="container">
<div class="row justify-content-end p-3">
<div class="col-auto">
content one
</div>
<div class="col-auto">
content two
</div>
</div>
</div>
Note: This codes do not have breakpoints. If you want to add breakpoints use this format: col-{breakpoint}-auto or/and justify-content-{breakpoint}-auto