I am using the skeleton CSS and I'm trying to get a div to be at the bottom of the page.
I have tried using position: absolute; bottom: 0; within the container has a relative position, but the div just aligns to the right-hand side of the page.
.page {
align-items: center;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
min-height: 100vh;
}
#home {
background: red;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.1.1/normalize.min.css">
<div class="page" id="home">
<div class="container" style="text-align: center;">
<div class="row">
I am a title in the middle of the page.
</div>
<div class="row" style="">
I want to be at the bottom of the page.
<br>
Click here!
</div>
</div>
</div>
Is this possible, please?
Take the Bottom text element out of the CONTAINER parent and place it as a child of the PAGE element, then position:absolute will work:
https://jsfiddle.net/akLr6zb0/
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.1.1/normalize.min.css">
<div class="page" id="home">
<div class="container" style="text-align: center;">
<div class="row">
I am a title in the middle of the page.
</div>
</div>
<div class="bottom" style="">
I want to be at the bottom of the page.
<br>
Click here!
</div>
</div>
.page {
align-items: center;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
min-height: 100vh;
position: relative;
}
#home {
background: red;
}
.bottom {
bottom: 0;
display: block;
position: absolute;
}
position: absolute; bottom: 0; is right, but you also need to make sure the direct parent .container is the height of the page, and then center everything with display: flex:
.page {
min-height: 100vh;
}
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
#home {
background: red;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.1.1/normalize.min.css">
<div class="page" id="home">
<div class="container" style="text-align: center;">
<div class="row">
I am a title in the middle of the page.
</div>
<div class="row" style="position: absolute; bottom: 0;">
I want to be at the bottom of the page.
<br>
Click here!
</div>
</div>
</div>
I am not sure if it's what you want but I achieve that with displaying the container as flex.
.page {
align-items: center;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: center;
min-height: 100vh;
}
#home {
background: red;
}
.container {
flex-grow: 1;
display: flex;
align-items: center;
justify-content: center;
}
.bottom {
position: absolute;
bottom: 0;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.1.1/normalize.min.css">
<div class="page" id="home">
<div class="container">
<div class="row">
I am a title in the middle of the page.
</div>
<div class="row bottom" style="">
I want to be at the bottom of the page.
<br>
Click here!
</div>
</div>
</div>
Related
I have circular logo here as you can see , I'm trying to have my circle logo and "name" and "family" around it , like : "name" logo "family" and I want to exclude "container" from being flex child because I want to align them left not center here's my codes:
header {
width: auto;
height: 35vh;
background-color: var(--clr-accent);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
flex-wrap: wrap;
}
.logo {
background: url(/src/logo.png);
width: 6rem;
height: 6rem;
background-position: center;
background-repeat: no-repeat;
background-size: 3rem 3rem;
border: 1px solid black;
border-radius: 50%;
}
.name-fam {
display: flex;
flex-direction: row-reverse;
}
<header>
<div class="name-fam">
<h2>Name</h2>
<div class="logo"></div>
<h2>Family</h2>
</div>
<div class="container">
<div>
<h4>My marital status:</h4>
<div class="marital-status"></div>
</div>
<div>
<h4>my birthday:</h4>
<div class="birthday-date"></div>
</div>
</div>
</header>
note: I want flexbox inside my container (it's children) but exclude container itself from being flex element and being centralized.
You don't need to use display: flex on your header, since you can use margin: 0 auto on the name-fam div. Also, not sure why row-reverse was used on nam-fam since the elements are in the order you wanted in the markup.
header {
width: auto;
height: 35vh;
background-color: var(--clr-accent);
}
.logo {
background: url(/src/logo.png);
width: 6rem;
height: 6rem;
background-position: center;
background-repeat: no-repeat;
background-size: 3rem 3rem;
border: 1px solid black;
border-radius: 50%;
}
.name-fam {
display: flex;
margin: 0 auto;
justify-content: center;
}
<header>
<div class="name-fam">
<h2>Name</h2>
<div class="logo"></div>
<h2>Family</h2>
</div>
<div class="container">
<div>
<h4>My marital status:</h4>
<div class="marital-status"></div>
</div>
<div>
<h4>my birthday:</h4>
<div class="birthday-date"></div>
</div>
</div>
</header>
If you want to keep display: flex on the header
header {
width: auto;
height: 35vh;
background-color: var(--clr-accent);
display: flex;
/* Change to row */
flex-direction: row;
justify-content: center;
flex-wrap: wrap;
}
.logo {
background: url(/src/logo.png);
width: 6rem;
height: 6rem;
background-position: center;
background-repeat: no-repeat;
background-size: 3rem 3rem;
border: 1px solid black;
border-radius: 50%;
}
.name-fam {
display: flex;
}
/* Add this to container to make sure it's 100% width so it will not appear to be centered */
.container {
flex: 0 0 100%;
max-width: 100%;
}
<header>
<div class="name-fam">
<h2>Name</h2>
<div class="logo"></div>
<h2>Family</h2>
</div>
<div class="container">
<div>
<h4>My marital status:</h4>
<div class="marital-status"></div>
</div>
<div>
<h4>my birthday:</h4>
<div class="birthday-date"></div>
</div>
</div>
</header>
This question already has answers here:
Align 3 unequal blocks left, center and right
(4 answers)
Closed 1 year ago.
There is 6 items in navbar:
first 3 items should be aligned as flex-start - on beginning of navbar.
Then Logo should be in center of navbar
And on the end -> flex-end should come 2 icons
Here is screenshot of navbar current condition:
Problem: is position of Logo - am using margin-left: '27%'. And on different screen size logo is not aligned well.
I would like to align some how that logo trough flex, is there a way to do that with flex?
Check the code:
HTML/jsx:
<div className="container">
<header className="header">
<nav className="user-nav">
<div className="user-nav-item">
<Link href="/">
<a className="user-nav-item-link">Overview</a>
</Link>
</div>
<div className="user-nav-item">
<Link href="/search">
<a className="user-nav-item-link">Search</a>
</Link>
</div>
<div className="user-nav-item">
<Link href="/feed">
<a className="user-nav-item-link">Feed</a>
</Link>
</div>
<h3 className="logo">Logo</h3>
</nav>
<div className="user-nav-icon">
<div className="user-nav-icon-box">
<img src={bellIcon} alt="notify icon" />
</div>
<div className="user-nav-icon-box">
<img src={settingsIcon} alt="settings icon" />
</div>
</div>
</header>
</div>
CSS:
.container {
max-width: 100vw;
display: flex;
flex-direction: column;
.header {
display: flex;
align-items: center;
height: 5rem;
color: #fff;
background-color: black;
.user-nav {
width: 100%;
display: flex;
align-items: center;
&-item {
width: 5.5rem;
padding: 1.5rem;
cursor: pointer;
}
&-item-link {
text-decoration: none;
color: white;
}
.logo {
margin-left: 27%;
}
&-icon {
display: flex;
align-items: center;
background-color: white;
color: red;
margin-right: 3rem;
& > * {
padding: 0 0.8rem;
cursor: pointer;
}
&-icon-notification {
color: red;
}
}
}
}
}
Using Flex Box. It will be harder to achieve that, I have an alternative. Please test this code on codepen:
* {
box-sizing: border-box;
}
.parent{
width: 100%;
min-height: 80px;
background-color: yellow;
display: relative;
}
.nav-menu,
.icons{
display: inline-block;
}
.icons{
float: right;
margin-left: 75px; /*This will help your icons to never go below the logo element*/
}
.nav-menu{
margin-right: 75px; /*This will help your nav-menu items to never go below the logo element*/
}
.logo{
width: 150px;
height: 40px;
position: absolute;
left: 50%;
background-color: green;
transform: translateX(-50%);
}
<div class="parent">
<div class="nav-menu"> Your Menu</div>
<div class="logo"></div>
<div class="icons">Your Icons</div>
</div>
You can simply get the logo out you nav so that all three, logo, nav and icons become flex items and justify header's content with space-between. Below is the simplified code.
P.S. - Share the rendered code as your implementation in future and not JSX/SASS
.container {
max-width: 100vw;
display: flex;
flex-direction: column;
}
.container .header {
display: flex;
align-items: center;
justify-content: space-between;
height: 5rem;
color: #fff;
background-color: black;
}
.container .header .user-nav {
display: flex;
align-items: center;
}
.container .header .user-nav-item {
padding: 1.5rem;
cursor: pointer;
}
.container .header .user-nav-item-link {
text-decoration: none;
color: white;
}
.container .header .user-nav-icon {
display: flex;
align-items: center;
background-color: white;
color: red;
margin-right: 3rem;
}
.container .header .user-nav-icon > * {
padding: 0 0.8rem;
cursor: pointer;
}
.container .header .user-nav-icon-icon-notification {
color: red;
}
<div class="container">
<header class="header">
<nav class="user-nav">
<div class="user-nav-item">
<a class="user-nav-item-link">Overview</a>
</div>
<div class="user-nav-item">
<a class="user-nav-item-link">Search</a>
</div>
<div class="user-nav-item">
<a class="user-nav-item-link">Feed</a>
</div>
</nav>
<h3 class="logo">Logo</h3>
<div class="user-nav-icon">
<div class="user-nav-icon-box">
Bell
</div>
<div class="user-nav-icon-box">
Settings
</div>
</div>
</header>
</div>
Here is an answer using display: flex; Flexbox is best & elegant to align items to mid of the page without cheesy computations by Margin, Transform,...
<html>
<head>
<style>
*, .container {
width: 100%;
top: 0;
left: 0;
padding: 0;
margin: 0;
color: ivory;
font-family: Arial,"Helvetica Neue",Helvetica,sans-serif;
font-size: 13px;
}
.header {
display: flex;
align-items: center;
padding: 10px;
background-color: gray;
}
.user-nav {
display: flex;
align-items: center;
justify-content: center;
width: 30%;
}
.user-nav-item {
display: flex;
align-items: center;
justify-content: center;
}
.logo {
display: flex;
align-items: center;
justify-content: center;
width: 40%;
}
.user-nav-icon {
display: flex;
align-items: center;
justify-content: center;
width: 30%;
}
</style>
</head>
<body>
<div class="container">
<header class="header">
<nav class="user-nav">
<div class="user-nav-item">
<Link href="/">
<a class="user-nav-item-link">Overview</a>
</Link>
</div>
<div class="user-nav-item">
<Link href="/search">
<a class="user-nav-item-link">Search</a>
</Link>
</div>
<div class="user-nav-item">
<Link href="/feed">
<a class="user-nav-item-link">Feed</a>
</Link>
</div>
</nav>
<h3 class="logo">Logoooooooooooooooooooooo</h3>
<div class="user-nav-icon">
<div class="user-nav-icon-box">
<img src={bellIcon} alt="notify icon" />
</div>
<div class="user-nav-icon-box">
<img src={settingsIcon} alt="settings icon" />
</div>
</div>
</header>
</div>
</body>
</html>
I'm trying to make a div with the background img of a bubble that have the count of comments on a post inside it. I want the width to be controlled by the text inside while the height of the div should stay static so I can keep the text inside centered verticaly.
What I have now is the code under here. It looks ok when the value inside is a 3 digit number, but if I change it to a 2 digit number or anything other then a 3 digit number the bubble moves verticaly and horizontaly so the text is not centered anymore.
#wrapper {
display: flex;
flex-wrap: nowrap;
flex-direction: row;
min-width: 100%;
align-items: baseline;
}
#comment_text {
display: flex;
font-weight: bold;
}
#comment_img {
display: flex;
background: url('https://rajohan.no/img/icons/picons_basic_1/SVG/basic1-021_chat_comment_bubble.svg');
background-repeat: no-repeat;
background-size: 100%;
padding: 21px;
margin-left: 10px;
}
#comment_count {
display: flex;
font-weight: bold;
}
<div id="wrapper">
<div id="comment_text">
COMMENTS
</div>
<div id="comment_img">
<div id="comment_count">
160
</div>
</div>
</div>
Try adding background-position:center - this centers the background image horizontally as the element changes width. I think that's what you're trying to achieve.
#wrapper {
display: flex;
flex-wrap: nowrap;
flex-direction: row;
min-width: 100%;
align-items: baseline;
}
#comment_text {
display: flex;
font-weight: bold;
}
.comment_img {
display: flex;
background: url('https://rajohan.no/img/icons/picons_basic_1/SVG/basic1-021_chat_comment_bubble.svg');
background-repeat: no-repeat;
background-position: center;
padding: 21px;
margin-left: 10px;
}
.comment_count {
display: flex;
font-weight: bold;
}
<div id="wrapper">
<div id="comment_text">
COMMENTS
</div>
<div class="comment_img">
<div class="comment_count">
16
</div>
</div>
<div class="comment_img">
<div class="comment_count">
160
</div>
</div>
</div>
I have added some code in your #comment_count.
#wrapper {
display: flex;
flex-wrap: nowrap;
flex-direction: row;
min-width: 100%;
align-items: baseline;
}
#comment_text {
display: flex;
font-weight: bold;
}
#comment_img {
display: flex;
background: url('https://rajohan.no/img/icons/picons_basic_1/SVG/basic1-021_chat_comment_bubble.svg');
background-repeat: no-repeat;
background-size: 100%;
padding: 21px;
margin-left: 10px;
}
#comment_count {
display: flex;
font-weight: bold;
min-height: 20px;
min-width: 25px;
justify-content: center;
}
<div id="wrapper">
<div id="comment_text">
COMMENTS
</div>
<div id="comment_img">
<div id="comment_count">
160
</div>
</div>
</div>
<div id="wrapper">
<div id="comment_text">
COMMENTS
</div>
<div id="comment_img">
<div id="comment_count">
22
</div>
</div>
</div>
Is it possible to position div#d2 directly under the div#d1 container per markup below instead of positioning outside the height of the wrapper?
#wrapper {
height: 100%;
display: flex;
background-color: steelblue;
align-items: center;
min-height: 100%;
/* fallback style for browsers that do not support the `vh` unit */
min-height: 100vh;
}
#d2 {
margin-top: 0.25rem;
text-align: center;
background-color:#336712;
}
<body>
<div id="wrapper">
<div id="d1">lorem ipsum</div>
</div> <!-- #wrapper -->
<div id="d2">This should appear .25rem's under #d1 container</div>
</body>
Here's a pic of what I am trying to achieve:
html, body {
height: 100%;
}
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: steelblue;
}
#wrapper {
display: flex;
}
#d2 {
margin-top: 0.25rem;
text-align: center;
background-color: #336712;
}
<div id="wrapper">
<div id="d1">lorem ipsum</div>
</div>
<!-- #wrapper -->
<div id="d2">This should appear .25rem's under #d1 container</div>
jsFiddle demo
I'm trying to achieve the following result using flexbox:
I tried the with the following html but I can't get it to work.
<div class=" flex-center">
<div class="flex-item-center">
<p>
Some text in box A
</p>
</div>
<div class="flex-item-bottom">
<p>Some text in box B....</p>
</div>
</div>
CSS:
.flex-center {
display: flex;
align-items: center;
align-content: center;
justify-content: center;
}
.flex-item-center {
align-self: center;
}
.flex-item-bottom {
align-self: flex-end;
}
How can I make it look like the image?
I've made a posible solution.
.flex-center {
background-color: #739FD0;
color: #000000;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-content: center;
align-items: center;
height: 400px;
}
.flex-center-bottom {
background-color: #739FD0;
color: #000000;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: flex-end;
align-content: center;
align-items: center;
}
.flex-item-center {
border: solid 2px #4675AA;
order: 0;
flex: 0 1 auto;
align-self: center;
}
.flex-item-bottom {
border: solid 2px #4675AA;
order: 1;
flex: 0 1 auto;
align-self: flex-end;
}
<div class="flex-center">
<div class="flex-item-center">
<p>DROP FILES HERE</p>
</div>
</div>
<div class="flex-center-bottom">
<div class="flex-item-center">
<p>Hint: You can also drop files in the all files page</p>
</div>
</div>
Update 2017: Tested in Google Chrome VersiĆ³n 62.0.3202.89 (Build oficial) (32 bits).
.flex-center,
.flex-center-bottom {
align-items: center;
background-color: #739FD0;
color: #000000;
display: flex;
}
.flex-center {
height: 400px;
justify-content: center;
}
.flex-center-bottom {
justify-content: flex-end;
}
.flex-item-center {
border: solid 2px #4675AA;
font-family: Arial, sans-serif;
font-size: 1.6em;
line-height: 1px;
padding: 0 3px;
}
<div class="flex-center">
<div class="flex-item-center">
<p>Some text in box A</p>
</div>
</div>
<div class="flex-center-bottom">
<div class="flex-item-center">
<p>Some text in box B...</p>
</div>
</div>
I hope this helps you.
Is this what you are looking for? http://jsfiddle.net/DIRTY_SMITH/q12bh4se/6/
body {
background-color: lightblue;
}
#main {
width: 100%;
height: 400px;
border: 1px solid black;
display: -webkit-flex;
/* Safari */
-webkit-align-items: flex-start;
/* Safari 7.0+ */
display: flex;
align-items: flex-start;
}
#main div {
-webkit-flex: 1;
/* Safari 6.1+ */
flex: 1;
}
.flex-item-center {
margin-left: 40%;
border-style: solid;
-webkit-align-self: center;
/* Safari 7.0+ */
align-self: center;
}
.flex-item-bottom {
border-style: solid;
align-self: flex-end;
}
Try:
#main-wrapper {
background: blue;
width: 100%;
height: 100%;
min-height: 300px;
display: flex;
align-items: center;
}
.x-center {
display: flex;
justify-content: center;
}
.y-center {
flex: 1;
}
.x-right {
justify-content: flex-end;
}
.y-bottom {
align-self: flex-end;
}
.small-div {
padding: 10px;
}
<div id="main-wrapper">
<div class="x-center y-center small-div">Center center</div>
<div class="x-right y-bottom small-div">Bottom Right</div>
</div>
Notes:
The align-self won't work for IE10 or below.
Anybody know how to make the center div a bit more to the left without position relativing it? Thanks
In Bootstrap 4.x you can use the utility classes
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-center h-100">
<div class="d-flex align-items-center">center center</div>
</div>
<div class="d-flex justify-content-end h-100">
<div class="d-flex align-items-end">right bottom</div>
</div>
</div>
</div>
</div>
EDIT
Since I received a couple downvotes I believe a review is in order.
To me the above answer is still valid, however I understand it's not clear it requires some height.
How this height is achieved doesn't really matter. Either you set it fixed in CSS on a wrapper or for the code snippet's sake we set the document's height to make it responsive.
If the "center content" takes up the space in height, the "bottom content" can be positioned absolute, so it doesn't add height. All what's left is to make sure it covers the full width and positions from the bottom.
html, body { height: 100%; } /* can be anything that generates height */
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="d-flex justify-content-center h-100">
<div class="d-flex align-items-center">center center</div>
</div>
<div class="d-flex justify-content-end position-absolute w-100 fixed-bottom">
<div class="d-flex align-items-end">right bottom</div>
</div>
So functionality wise, there's no additional CSS required in Bootstrap.
Documentation justify content
Documentation position