I am trying to vertically center h5 in a div but I want to do it responsively, so those solutions where you set the parent's height to a certain amount of pixels aren't a solution for me.
The h5 with id "channelName" is what I am trying to vertically center in the parent div.
<div class="col-10 text-left channelTab"><h5 id="channelName">Name</h5></div>
#greyBox {
background-color: grey;
}
#title {
color: white;
}
.logo {
max-height: 50px;
max-width: 50px;
border-radius: 50%;
border: 3px solid white;
}
#channelName {
vertical-align: middle;
display: inline-block;
}
#channelRow {
background-color: red;
}
<div class="container-fluid">
<div class="row">
<div class="col-4"></div>
<div id="greyBox" class="col-4 text-center">
<div class="row">
<div class="col-12 text-center">
<h1 id="title">TITLE</h1>
<div class="row" id="channelRow">
<div class="col-2">
<img src="image.png" class="logo"></div>
<div class="col-10 text-left channelTab">
<h5 id="channelName">Name</h5>
</div>
</div>
<div class="col-6">
</div>
</div>
</div>
</div>
</div>
</div>
If this could be done more easily with some more changes to my code, any such tips would be welcome as I am really new to this and still learning.
Add this class to parent of h5 d-flex align-items-center and remove bottom margin of h5
This class (d-flex) will make the display of parent of h5 flex and the align-items-center will vertically center it.
#greyBox {
background-color: grey;
}
#title {
color: white;
}
.logo {
max-height: 50px;
max-width: 50px;
border-radius: 50%;
border: 3px solid white;
}
#channelName {
margin:0;
}
#channelRow {
background-color: red;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col-4"></div>
<div id="greyBox" class="col-4 text-center">
<div class="row">
<div class="col-12 text-center">
<h1 id="title">TITLE</h1>
<div class="row" id="channelRow">
<div class="col-2">
<img src="image.png" class="logo"></div>
<div class="col-10 text-left d-flex align-items-center channelTab">
<h5 id="channelName">Name</h5>
</div>
</div>
<div class="col-6">
</div>
</div>
</div>
</div>
</div>
</div>
Related
I have two bootstrap columns, and I need to implement a footer in just one of them.
I have it implemented here:
.row {
background: #f8f9fa;
}
.container {
}
.col {
border: solid 1px #6c757d;
padding: 10px;
}
.footer {
bottom: 0;
height: 40px;
line-height: 40px;
}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row h-100">
<div class="col col-3">
1 of 2
</div>
<div class="col-9">
<div class="row">
<div class="col col-8">2 of 2</div>
<div class="col col-4">2 of 2</div>
</div>
<div class="row">
<footer class="position-fixed border w-100 footer">STICKY FOOTER</footer>
</div>
</div>
</div>
</div>
But the problem is that the position: fixed makes the footer out of the flow of the container, and it takes the complete width of the page. Is there a way to make the footer end where the column ends?
Or is there a better way to do this with flexbox?
Thanks!
.main {
height: 200vh;
}
.col {
background-color: #CCC;
height: 40px;
line-height: 40px;
}
.black-border {
border: 1px solid black;
border-width: 1px 0px 1px 1px;
}
.black-border:last-child {
border-width: 1px;
}
.footer {
bottom: 0;
height: 40px;
line-height: 40px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container main">
<div class="row h-100">
<div class="col col-3 black-border">
1 of 2
</div>
<div class="col col-9">
<div class="row">
<div class="col col-8 black-border">2 of 2</div>
<div class="col col-4 black-border">2 of 2</div>
</div>
</div>
</div>
</div>
<footer class="position-fixed w-100 footer">
<div class="container">
<div class="row justify-content-end">
<div class="col col-9 black-border">
<div class="w-100">STICKY FOOTER</div>
</div>
</div>
</div>
</footer>
How to make a span with sticky element float through 2 bootstrap's container divs?
Right now I couldn't make the span element stick on top of the container div, the container will always stay below of the span element. Also, When shrink into mobile view, I would like to have content 1 stay above then follow by span element with image then lastly is content 2. Each of the container has a background-image with it, so I want the span element can move up and down through 2 containers. Thank you so much in advance.
This is what I expected result:
Here is the jsfiddle link: https://jsfiddle.net/oafwmghd/2/
#sticky {
position: -webkit-sticky;
position: sticky;
display: flex;
display: -ms-flex;
display: -webkit-flex;
justify-content: center;
margin-top: 30px;
padding-bottom: 80px;
top: 0;
z-index: 1;
}
<div class="container">
<span><img
src="https://previews.123rf.com/images/sooolnce/sooolnce1611/sooolnce161100038/66323541-realistic-plastic-bottle-for-water-on-a-transparent-background-vector-illustration.jpg"
width=20% height=50% id="sticky"></span>
<section>
<div class="container" style="height:500px; background-color: green;">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-0">
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
Content 1
</div>
</div>
</div>
</section>
<section>
<div class="container" style="height:500px; background-color: red;">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-0">
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
Content 2
</div>
</div>
</div>
</section>
</div>
You might not need these empty elements if you use margin-left:auto (class : ml-auto).
To reorder elements, you need a flex or a grid container , you may reset container to a column flex box (class : d-flex flex-column)
There is nor ordering responsive class (as much as i know), you may create the classes and the breaking point you need and remove t the same time the sticky behavior.
A negative margin or absolute position could be used to avoid image pushing the content down . let's try with position or margin.
An approach could be :
#sticky {
position: -webkit-sticky;
position: sticky;
display: flex;
display: -ms-flex;
display: -webkit-flex;
justify-content: center;
margin-top: 30px;
width: 50%;
top: 1em;
z-index: 1;
margin-left: 0;
border: 0;
order: -1
}
#sticky img {
position: absolute;
}
#media (max-width: 768px) {
.order-sm-1 {
order: 1;
}
#sticky.order-sm-2 {
order: 2;
}
#sticky img {
position: static;
}
.order-sm-3 {
order: 3;
}
#sticky {
position: static;
margin: auto;
width: auto;
}
}
/* demo purpose*/
section {
border: solid;
margin-bottom: 1em;
}
.row .ml-auto {
min-height: 300px;
background: green;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<!--
Bootstrap docs: https://getbootstrap.com/docs
-->
<div class="container d-flex flex-column">
<section class="row col-lg-6 col-md-6 col-sm-12 order-sm-2" id="sticky"><img src="https://images.containerstore.com/catalogimages/318610/ColoredStopperBottlesClear_x.jpg?width=1200&height=1200&align=center" width=80%></section>
<section class="order-sm-1">
<div class="container">
<div class="row">
<!--<div class="col-lg-6 col-md-6 col-sm-0"></div>-->
<div class="col-lg-6 col-md-6 col-sm-12 ml-auto">
<p><b>Play the snippet in full page mode and resize the window to checkout the behavior</b></p>
</div>
</div>
</div>
</section>
<section class="order-sm-3">
<div class="container">
<div class="row">
<!--<div class="col-lg-6 col-md-6 col-sm-0"></div>-->
<div class="col-lg-6 col-md-6 col-sm-12 ml-auto">
Content 2
</div>
</div>
</div>
</section>
</div>
follow up from comment :
#sticky {
position: -webkit-sticky;
position: sticky;
display: flex;
display: -ms-flex;
display: -webkit-flex;
justify-content: center;
margin-top: 30px;
width: 30%;
top: 4em;
z-index: 1;
margin-left: 0;
border: 0;
order: -1;
flex: 0 0 auto;
}
#sticky img {
position: absolute;
}
#media (max-width: 768px) {
.order-sm-1 {
order: 1;
}
#sticky.order-sm-2 {
order: 2;
}
#sticky img {
position: static;
}
.order-sm-3 {
order: 3;
}
#sticky {
position: static;
margin: auto;
width: auto;
}
}
/* demo purpose*/
section {
border: solid;
margin-bottom: 1em;
}
.row .ml-auto {
min-height: 200px;
background: green;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="container d-flex flex-column p-0">
<section class="row col-lg-6 col-md-6 col-sm-12 order-sm-2" id="sticky"><img src="https://images.containerstore.com/catalogimages/318610/ColoredStopperBottlesClear_x.jpg?width=1200&height=1200&align=center" width=80%></section>
<section class="order-sm-1">
<div class="container">
<div class="row">
<!--<div class="col-lg-6 col-md-6 col-sm-0"></div>-->
<div class="col-lg-6 col-md-6 col-sm-12 ml-auto">
<p><b>Play the snippet in full page mode and resize the window to checkout the behavior</b></p>
</div>
</div>
</div>
</section>
</div>
<section class="order-sm-3">
<div class="container">
<div class="row">
<!--<div class="col-lg-6 col-md-6 col-sm-0"></div>-->
<div class="col-lg-6 col-md-6 col-sm-12 ml-auto">
Content 2
</div>
</div>
</div>
</section>
</div>
<div class="container">
<section>
<div class="container">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12 ml-auto">
Content 3
</div>
</div>
</div>
</section>
<section>
<div class="container">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12 ml-auto">
Content 4
</div>
</div>
</div>
</section>
</div>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<style>
.row.one{
align-items: stretch;
justify-content: center;
display: flex;
}
.col-lg-6 { width:50%;}
.col-lg-12 { width:100%;}
</style>
<section>
<div class="container">
<div class="row one">
<div class="col-lg-6 col-md-6 col-sm-12" style="background:#006;padding:50px 0;">
Content 1
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12" style="background:#993;padding:50px 0;">
Content 2.1
</div>
<div class="col-lg-12 col-md-12 col-sm-12" style="background:#3FC;padding:50px 0;">
Content 2.2
</div>
</div>
</div>
</div>
</div>
</section>
Hope so this will work for you
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<style>
.row.one{
align-items: stretch;
justify-content: center;
display: flex;
}
.col-lg-6 { width:50%;}
.col-lg-12 { width:100%;}
</style>
<section>
<div class="container">
<div class="row one">
<div class="col-lg-6 col-md-6 col-sm-12" style="background:#006;padding:50px 0;">
Content 1
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12" style="background:#993;padding:50px 0;">
Content 2.1
</div>
<div class="col-lg-12 col-md-12 col-sm-12" style="background:#3FC;padding:50px 0;">
Content 2.2
</div>
</div>
</div>
</div>
</div>
</section>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<style>
.row.one{
align-items: stretch;
justify-content: center;
display: flex;
}
.col-lg-6 { width:50%;}
.col-lg-12 { width:100%;}
</style>
<section>
<div class="container">
<div class="row one">
<div class="col-lg-6 col-md-6 col-sm-12" style="background:#006;padding:50px 0; background:url(https://www.nationalgeographic.com/content/dam/travel/rights-exempt/2018-travel-photographer-of-the-year/magical-mountains/dawn-vestrahorn-iceland-mountains.jpg); background-size:cover;">
</div>
<div class="col-lg-6 col-md-6 col-sm-12">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12" style="background:#006;padding:50px 0; background:url(https://www.dw.com/image/48396304_303.jpg); background-size:cover;">
</div>
<div class="col-lg-12 col-md-12 col-sm-12" style="background:#006;padding:50px 0; background:url(https://amp.businessinsider.com/images/5ac3bdf57a74af1b008b4612-960-480.jpg); background-size:cover;">
</div>
</div>
</div>
</div>
</div>
</section>
Hop so this will help you
I am trying to center red block Horizontally and Vertically as in the picture below, but unfortunately red block is placed in the wrong place. I use bootstrap 4. Сan anyone say what's wrong??
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<div class="container-fluid">
<div class="row header-layout">
*Some content*
</div>
<div class="row content-layout">
<div class="col-6 left-side">
*Some content*
</div>
<div class="col-6 right-side">
<div class="row right-title">
*Some Text*
</div>
<div class="row parent">
<div class="child">
*Some content*
</div>
</div>
</div>
</div>
</div>
You can use flexbox for effortless centering of element.
Here's a full guide for Flexbox
.parent {
height: 100px;
width: 100px;
background: black;
display: flex;
align-items: center;
justify-content: center; }
.child {
height: 50px;
width: 50px;
background: red; }
<div class="parent">
<div class="child"></div>
</div>
i just change some bootstrap class and css. hope it help :)
div {
border: thin solid black;
}
.child {
position: relative;
margin: auto;
width: 60px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<div class="container-fluid">
<div class="row header-layout">
*Container content*
</div>
<div class="row content-layout">
<div class="col-6 left-side">
*left content*
</div>
<div class="col-6 right-side">
<div class="row right-title">
*Right Text*
</div>
<div class="row">
<div class="child">
*Child content*
</div>
</div>
</div>
</div>
</div>
You can do this using the new Bootstrap 4 flexbox utilities..
<div class="container-fluid h-100 d-flex flex-column">
<div class="row header-layout">
*Some content*
</div>
<div class="row content-layout flex-grow">
<div class="col-6 left-side d-flex flex-column">
<div class="row">
<div class="col-12 text-center">content</div>
</div>
<div class="row flex-grow">
<div class="col-12 text-center my-auto">content</div>
</div>
</div>
<div class="col-6 right-side d-flex flex-column">
<div class="row right-title">
<div class="col-12 text-center">title</div>
</div>
<div class="row parent flex-grow">
<div class="child col-6 mx-auto my-auto">
<div class="card card-block">child</div>
</div>
</div>
</div>
</div>
</div>
http://www.codeply.com/go/6nALguHQyw
Just make sure the body,html are 100% height. Also, I added a flex-grow class to make content fill the remaining height. In the future, this may be added as a util class so that you won't need this extra CSS.
<div class="row">
<div class="col-xs-6">
<img src="img.png" width="100%" />
</div>
<div class="col-xs-6">
<div class="row"><p>Main text</p></div>
<div class="row"><p>More...</p></div>
</div>
</div>
I need this result:
So I need a picture which takes up 50% of the screen width and then a big title which is centered horizontally, but vertically is on top; and "more..." text which is to the right horizontally, but on the bottom vertically. How do I manage to do this? Can someone help me, please?
Here is your solution: use display flex to make both columns have same height, then use position relative ad absolute to position your columns
.title{
background-color: red;
text-align: center;
}
.title h1{
width: 100%;
}
.description{
background-color: yellow;
}
/*NEW*/
.row{
display:flex;/*makes col have same height*/
}
.details{
position: relative !important;
}
.description{
position: absolute !important;
bottom: 0;
}
.description p{
width: 100%;
text-align: right;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row col-xs-12">
<div class="col-xs-6">
<img src="https://placehold.it/150/150" width="100%" />
</div>
<div class="col-xs-6 details">
<div class="row col-xs-12 title">
<h1>Main text</h1>
</div>
<div class="row col-xs-12 description">
<p>More...</p>
</div>
</div>
</div>
Is it this you mean?
.title{
background-color: red;
text-align: center;
}
.description{
background-color: blue;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row col-xs-12">
<div class="col-xs-6">
<img src="https://placehold.it/150/150" width="100%" />
</div>
<div class="col-xs-6 details">
<div class="row col-xs-12 title">
<h1>Main text</h1>
</div>
<div class="row col-xs-12 description">
<p>More...</p>
</div>
</div>
</div>
I have been trying to get the following done with css with no avail.
This is the closest I've gotten to something like this.
As you see, I am close, but no cigar. I need the dashes (or lines preferably, but won't get picky) are not all reaching the number. I tried taking them all the way over and use overflow:hidden, but nothing. And also, this is a responsive site so it has to respect responsiveness as well.
Here is my code. THANKS!! :
HTML
<div class="col-md-12 allocation">
<div class="row">
<div class="col-md-10 col-sm-10 col-xs-10">Equities</div>
<div class="col-md-2 col-sm-2 col-xs-2">65%</div>
</div>
<div class="row">
<div class="col-md-10 col-sm-10 col-xs-10">Domestic large capitalized firms</div>
<div class="col-md-2 col-sm-2 col-xs-2">25%</div>
</div>
<div class="row">
<div class="col-md-10 col-sm-10 col-xs-10">Domestic small capitalized firms</div>
<div class="col-md-2 col-sm-2 col-xs-2">15%</div>
</div>
<div class="row">
<div class="col-md-10 col-sm-10 col-xs-10">International developed markets</div>
<div class="col-md-2 col-sm-2 col-xs-2">15%</div>
</div>
<div class="row">
<div class="col-md-10 col-sm-10 col-xs-10">International emerging markets</div>
<div class="col-md-2 col-sm-2 col-xs-2">10%</div>
</div>
<div class="row">
<div class="col-md-10 col-sm-10 col-xs-10"><strong>Fixed Income</strong></div>
<div class="col-md-2 col-sm-2 col-xs-2"><strong>15%</strong></div>
</div>
<div class="row">
<div class="col-md-10 col-sm-10 col-xs-10"><strong>Real Estate</strong></div>
<div class="col-md-2 col-sm-2 col-xs-2"><strong>20%</strong></div>
</div>
<div class="row">
<div class="col-md-10 col-sm-10 col-xs-10">Core</div>
<div class="col-md-2 col-sm-2 col-xs-2">12.5%</div>
</div>
<div class="row">
<div class="col-md-10 col-sm-10 col-xs-10">Timber</div>
<div class="col-md-2 col-sm-2 col-xs-2">7.5%</div>
</div>
</div>
CSS:
.allocation .row{
margin:15px auto;
}
.allocation .row > div.col-md-10.col-sm-10.col-xs-10:after{
content: "--------------------------------------------------- ";
}
If you want to achieve this, you can check the code here or here:
<div class="col-xs-12">
<div class="row">
<div>Equities</div>
<div>65%</div>
</div>
<div class="row">
<div>Domestic large capitalized firms</div>
<div>25%</div>
</div>
<div class="row">
<div>Domestic small capitalized firms</div>
<div>15%</div>
</div>
<div class="row">
<div>International developed markets</div>
<div>15%</div>
</div>
<div class="row">
<div>International emerging markets</div>
<div>10%</div>
</div>
<div class="row">
<div><strong>Fixed Income</strong></div>
<div><strong>15%</strong></div>
</div>
<div class="row">
<div><strong>Real Estate</strong></div>
<div><strong>20%</strong></div>
</div>
<div class="row">
<div>Core</div>
<div>12.5%</div>
</div>
<div class="row">
<div>Timber</div>
<div>7.5%</div>
</div>
</div>
With this css code:
.row {
border-bottom: 1px dashed black;
height: 15px;
clear: right;
margin-bottom: 16px;
}
.row div:first-of-type {
float: left;
background: #FFF;
padding-right: 5px;
}
.row div:last-of-type {
float: right;
margin-top: 1px;
background: #FFF;
width: 50px;
text-align: right;
}
There are several solutions for this... here is one:
.index-row{
border-bottom: 1px dashed;
height:1.5em;
clear:both;
}
.index-row h2, .index-row span{
padding:5px;
margin:0;
line-height:1.0em;
background:white;
}
.index-row h2{
float:left;
}
.index-row span{
float:right;
}
<div>
<div class="index-row">
<h2>titulo indice</h2>
<span>45</span>
</div>
<div class="index-row">
<h2>titulo indice</h2>
<span>45</span>
</div>
<div class="index-row">
<h2>titulo indice</h2>
<span>45</span>
</div>
</div>
Simple and responsive solution using grid:
.index-item {
display: grid;
justify-content: space-between;
align-items: baseline;
grid-template-columns: auto 1fr auto;
gap: .5rem;
padding-block: .5rem;
}
.index-line {
height: 3px;
min-width: 15px;
background: linear-gradient(90deg, #888 2.5%, #fff 2.5%, #fff 47.5%, #888 47.5%, #888 52.5%, #fff 52.5%, #fff 97.5%, #888 97.5%);
background-size: 10px 10px;
background-position: 50px 50px;
}
<div class="index-item">
<div class="index-title">Page Title</div>
<span class="index-line"></span>
<div class="index-number">200</div>
</div>
<div class="index-item">
<div class="index-title">Page Title (long title)</div>
<span class="index-line"></span>
<div class="index-number">230</div>
</div>