HTML centre a CCS flexible layout [closed] - html

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm using this example codepen as the basis of a simple site.
This works well but I'd like the layout to sit centred on the page, not full height. Please see example image.
Is there anyway to do this and retain the flexibility of the page ?
I've tried adding height or max-height to the wrap but that hasn't made any difference.
Thanks

So, you want to use align-items: center;. But you have to choose where to use it. If you want the sidebar to stay as it is, you should change the html code a bit:
<div class="content">
<div class="inner">
Actual content goes here.
</div>
</div>
and in css:
.content {
display: flex;
justify-content: center;
}
Now the yellow background will stay as it is, but the text will be vertically centered.
If you put display: flex; and justify-content: center; on .main both sidebar and content will get centered. Then it will look like that:
html:
<div class="content">
Actual content goes here.
</div>
and css:
.main {
flex: 1;
display:flex;
align-items:center;
}
EDIT:
Since I misunderstood the question I'll answer it here but I'll leave the part above because someone might find it usefull.
So, you will need to modify styling for .wrap. Since you have flex-direction: column; set on it, to center it vertically you have to use justify-content: center; instead of align-items: center because now the main axis is the vertical one. So:
.wrap {
display: flex;
...
justify-content: center;
}
.main {
max-height: 500px; /* set whatever you want */
...
}

use align-items property for this problem
.main {
flex: 1;
display:flex;
align-items:center;
}

Related

How to get next paragraph element to float around prepended image? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 9 days ago.
Improve this question
I have an image prepended to a paragraph element (see photo below)
The CSS float property for the image is set to right.
The paragraphs and image are part of a div with bootstrap class "container" so the basic layout is just
<div class="container">
<img class="img-fluid">
<p>Text</p>
<p>Text</p>
</div>
However, I really hate the big, ugly white space next to the image. How can I get the next paragraph element to fill that space?
The styling on each element is as follows
p {
text-align: justify;
text-justify: auto;
}
img {
height: auto;
}
Tried CSS clear:both on divs that wrap the image and paragraphs.
You can try the following approach to fill the white space next to the floated image:
Wrap the image and the text in a separate div container, like this:
.image-text {
display: flex;
align-items: center;
}
img {
height: auto;
flex-shrink: 0;
}
p {
text-align: justify;
text-justify: auto;
flex-grow: 1;
}
<div class="container">
<div class="image-text">
<img class="img-fluid">
<p>Text</p>
</div>
<p>Text</p>
</div>
The display: flex property makes the .image-text container a flex container. The align-items: center property aligns the child elements (the image and the text) vertically.
The flex-shrink: 0 property on the image makes sure that the image will not shrink to fit the available space. The flex-grow: 1 property on the text causes the text to take up all the available space in the container.
This way, the text will automatically fill the white space next to the image, without having to use the clear property.

How can I position elements relative to a centered div? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 11 months ago.
Improve this question
I want to center two buttons that are on the same line, and then I want to position a selector on the same line, to the right of the two centered buttons. How can I do it? In other words, how can I position an element relative to a centered div?
EDIT: I want the end result to look something like this: https://i.imgur.com/KeVbCF2.png
Flexbox does the job quite well!
.wrapper {
background: gray;
display: flex;
text-align:center;
justify-content: flex-end;
height:40px;
align-items: center;
justify-content: center;
}
.m {
width: 100%;
}
.m button {
width: 100px;
}
.r {
width: 200px;
}
<div class="wrapper">
<div class="m">
<button>a</button>
<button>b</button>
</div>
<div class="r">Section C</div>
</div>

Center Div Boxes [duplicate]

This question already has answers here:
How can I horizontally center an element?
(133 answers)
Closed 1 year ago.
I bet this question was asked a hundred times before but i was unable to find a solution for my exact problem. I have 4 Div boxes and they have a max width of 50% and a min width of 400px, so if the site is smaller (eg. on a phone), the boxes align below each other. Now i want to center the boxes if they are below each other (it looks fine while they are side by side). I tried to use
display: table; margin: 0 auto;
but it doesnt work. Another thing I tried was to place everything inside of another div and give them the parameters above and in addition i tried to play with the width of this one (max-content, min-content, auto, fit-content) but it didn't work either. Does anyone know an easy workaround?
Here a short version of my problem:
.format {
width: 50%;
float: left;
height: auto;
min-width: 500px;
background-color: lightblue;
display: table;
margin: 0 auto;
}
<div class="format">
<p>Landestrainer</p>
</div>
<div class="format">
<p>U17</p>
</div>
<div class="format">
<p>U15</p>
</div>
<div class="format">
<p>Sonstige</p>
</div>
sorry for my partly bad english. Hopefully, it was not that bad :)
I would recommend using display: flex instead to center them.
So you would need to put all 4 divs inside a parent div and apply the css below:
.parent-div {
display: flex;
flex-direction: column;
align-items: center;
}
New Edit based on the screenshot given
My approach for this problem would be something like this:
Make use of display: flex and #media query
.parent-div {
// This will divide the page into 2 columns cause of sub-parents
display: flex;
align-item: center;
}
.sub-parent{
display: flex;
align-items: center;
flex-direction: column;
}
// #media query means that if the screen becomes smaller than 768px (specified below), then apply the CSS queries which in this case apply flex-direction: column to the "parent-div"
#media screen and (max-width: 768px) {
.parent-div {
flex-direction: column;
}
}
<div class="parent-div">
<div class="sub-parent">
<div class="format">
<p>Landestrainer</p>
</div>
<div class="format">
<p>U17</p>
</div>
</div>
<div class="sub-parent">
<div class="format">
<p>U15</p>
</div>
<div class="format">
<p>Sonstige</p>
</div>
</div>
</div>
Here's the link to CSS display: flex guide: Display Flex Guide

How can I make equal height system without using any javascript or jquery plugin [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I want to make my specific div element's child will be equal height with out using any jquery plugin or Javascript. I want to make this by CSS.
So can any one give me an idea how can i make this?
Yes you can.
You have to use css3 dispaly: table; for the equal height wrapper and display: table-cell; for the each element of equal height wrapper.
Here is the simple way.
HTML & CSS Code:
.equal-height-row{
display: table;
}
.equal-height-row > .equal-height-box{
display: table-cell;
vertical-align: middle;
padding: 2em;
box-sizing: border-box;
background-color: lightgrey;
}
<div class="equal-height-row">
<div class="equal-height-box">Box1<br>box 1 content</div>
<div class="equal-height-box">Box2</div>
<div class="equal-height-box">Box3</div>
</div>
A modern and preferred way is to use flexbox, which aims at providing a more efficient way to lay out, align and distribute space among items in a container, even when their size is unknown and/or dynamic (thus the word "flex").
At this link, A guide to flexbox, you will find a really good start how it works.
.row {
display: flex;
}
.row > div {
flex: 1;
background-color: lightblue;
padding: 10px;
margin: 5px 10px;
}
<div class="row">
<div>First</div>
<div>Second<br>having<br>more than<br>one line</div>
<div>Third</div>
</div>

Sticky footer position in a two column layout

This post is an updated version of this one. I will try to explain my issue better than I did in the other post. The issue is related to the position of the footer in two situations.
Situation 1:
The first situation is when the content of the body is not enough to fill the height of the browser, so the footer must be fixed at the bottom of the browser.
Situation 2:
The second situation is when the height of the content of the body is higher and overflow. Here I do not wish the footer be fixed at the bottom, so the footer must be after the bottom of the content.
The first approach and link to the Fiddle example is in the above link from the other post.
By the way. I know this can be accomplished using Javascript, but I would like to use only CSS rules. Any idea?
I suggest to use nested flexbox, example below:
jsFiddle
body {
display: flex;
flex-direction: column;
height: 100vh;
margin: 0;
}
.container {
flex: 1;
display: flex;
}
.content {
display: flex;
flex-direction: column;
justify-content: space-between;
}
<div class="header">header</div>
<div class="container">
<div class="sidebar">sidebar</div>
<div class="content">
<div class="main">
conent<br>conent<br>conent<br>conent<br>conent<br>
conent<br>conent<br>conent<br>conent<br>conent<br>
conent<br>conent<br>conent<br>conent<br>conent<br>
conent<br>conent<br>conent<br>conent<br>conent<br>
</div>
<div class="footer">footer</div>
</div>
</div>