Flexbox items spilling over into header - html

I am building a personal website, and have been using a lot of flexbox to attain the layout I want. I recently ran into an issue that I cannot seem to solve. Where the items in my flexbox container seem to be spilling out and into other containers, such as my header container or past the bottom of where the page should end.
<div class="main-container">
<div class="header">
<h1>John Doe</h1>
<h2>Test</h2>
</div>
<div class="content-container">
<div class="projects">
<div class="content-container">
<div>
<h1>project</h1>
<p>project text</p>
</div>
<div>
<h1>project</h1>
<p>project text</p>
</div>
<div>
<h1>project</h1>
<p>project text</p>
</div>
<div>
<h1>project</h1>
<p>project text</p>
</div>
</div>
</div>
</div>
</div>
https://codepen.io/anon/pen/XYBbgE
I wanted to use a flexbox layout for my projects section so that the content will be centered, and I like how easy it is to do that with flexbox. If you adjust the height of the codepen container by either increasing the height OR reduce it, you can see that the header is hiding some of the elements.
I have included some HTML to kind of show the layout. I have excluded a lot to conserve space, however the codepen link is much closer to what the actual design looks like.
EDIT: I made a gif demonstrating the behavior that I am having an issue with
gif of flexbox problem
As you can see, as I adjust the height, the header of my page appears to cover up some of the items beneath it. I also cannot scroll higher than what the height is, if that makes sense.

To point out your error, it's the alignment of item's, for all elements you have aligned it center vertically. so it seemed out of a container as it's height was more than viewport. You can fix it by align-items: center; to align-items: flex-start;
.projects {
height: 100%;
width: 100%;
display: flex;
justify-content: center;
align-items: flex-start;
}
and to let you know, i think you are using too flex for everything which can be achieved without it easily

Related

How to use wrapper div & using flexbox on sections

I'm building my first website, and I am having some issues figuring out how to combine a wrapper that limits the max-width of the content and using flexbox on a section.
A typical section of my website would look like:
<section class="hero flex">
<div class="wrapper">
<h1>Content 1</h1>
<p>Content 2</p>
<button>Content 3</button>
</div>
</section>
I am running into the following problems:
When adding the wrapper div between section & the content, the content is no longer direct children of section, and thus are not affected by the flexbox. Therefore I cannot center the content.
If I put the classes .hero and .wrapper on the section tag, the background color is affected by the width/max-width of wrapper
I'm sure that I'm running into more problems that I still haven't found yet. I am therefore interested in how to use a wrapper for limited max-width together with flexbox sections.
.hero{
max-width: 700px;
}
.wrapper{
width: 100%;
display: flex;
justify-content: space-between;
}
<section ="hero flex">
<div class="wrapper">
<h1>Content 1</h1>
<p>Content 2</p>
<button>Content 3</button>
</div>
</section>

HTML, CSS, Bootstrap - Two columns with centering

I am trying to make a little website that should have two columns, and each column should have its content centered.
However, I have noticed that the columns will follow the height of each other, and not act as individual columns. E.g. whenever I add content to one of the columns, the content of the other column will be moved to fit the height of that column.
In the JSFiddle, you can see that the "Hello" on the right side is not completely centered; it has been moved up to stand in line with the first of three "Hello"'s on the left side. I would like it so, that whenever I add content to one column, it doesn't affect the other - so the "Hello" on the right side should ideally stay completely centered.
JSFiddle: https://jsfiddle.net/goupb2ch/1/
I have worked on this for quite a while now. Any ideas? Thanks!
Consider using flexbox to solve your problem: in this case far less code is required.
https://jsfiddle.net/upwgk2u4/
.container {
display: flex;
text-align: center;
height: 100%;
}
.container > div {
flex: 1;
align-self: center;
}
Why not use what's already in Bootstrap 4? No extra CSS is needed.
https://www.codeply.com/go/0zwGz83Cbw
<div class="container">
<div class="row">
<div class="col-md-6 text-center">
<p>Hello</p>
<p>Hello</p>
<p>Hello</p>
</div>
<div class="col-md-6 align-self-center text-center">
<p>Hello</p>
</div>
</div>
</div>

Bootstrap: How to center content vertically within a column

I have spent hours on this problem now and have read through countless questions, but none of the provided solutions works for me, so I'm now just gonna post my specific problem:
I want to build a row with four columns. The first three columns have pictures in them and the fourth column has a text description that I want to show vertically centered (meaning with an equal margin on the top and bottom that is obviously not fixed, but responsive to changing screen-sizes). Here's the code:
<section>
<div class="container-fluid">
<div class="row">
<div class="col-lg-4 col-sm-6">
<img ...>
</div>
<div class="col-lg-4 col-sm-6">
<img ...>
</div>
<div class="col-lg-3 col-sm-6">
<img ...>
</div>
<div class="col-lg-1 col-sm-6">
<div class="container-fluid">
<p>Some text that is supposed to be vertically centered within the column</p>
</div>
</div>
</div>
</div>
</section>
It must have to do something with the Bootstrap specific classes that non of the CSS-based solutions I can find on this works. How can I make it work in this particular example? Feel free to make any changes you want on this part:
<div class="container-fluid">
<p>Some text that is supposed to be vertically centered within the column</p>
</div>
However the rest of the structure should remain unchanged if possible (including the col-lg-1).
Your help is greatly appreciated!
In Bootstrap 4, add "align-self-center"-class to the col, where you want the content centred vertically.
You can use flexbox. Make your outer div, display: flex and use The property align-items to make it's contents vertically center. Here is the code:
#outerDiv{
display: flex;
align-items: center;
flex-wrap: wrap;
}
All you need to do is adding below snippet to your CSS.
just like this.
.row{ display: flex; align-items: center;}
I tried the same code and got output too. if you want to see, download the file and run it.
https://www.dropbox.com/s/0x7iqi6alayd8xg/VerticallyCentered.html?dl=0
The following code will center items perfectly within a div:
display: -webkit-flex; /* Safari */
-webkit-justify-content: space-around; /* Safari 6.1+ */
display: flex;
justify-content: space-around;
justify-content: center;

Owl Carousel align each item vertically when their height not equal

I'm working on a really simple Html/Bootstrap website.
I'm using owl-carousel library to display and slide multiple paragraphs.
The problem is that when displaying on small devices, these paragraphs will not have the same height, depending on how long they are.
I would like all my owl-item div or paragraph to be aligned vertically within the owl-wrapper div. I tried few display combinations, and also the owl carousel's autoHeight: true option but it does not work as I except.
See the pictures, the little paragraph is displayed on the top of the owl-wrapper div, but I would like it to be centered vertically:
<div class="container">
<div class="caption text-center text-white" data-stellar-ratio="0.7">
<div id="owl-intro-text" class="owl-carousel">
<div class="item">
<h1>Oscar Götting</h1>
</div>
<div class="item">
<h1>Let's build something together</h1>
</div>
</div>
</div>
</div>
Add this to your CSS
.owl-carousel .owl-stage { display: flex; align-items: center; }

Flexbox not displaying full width of page

I'm trying to use Flexbox to create my own grid. I don't want to use Bootstrap or any other framework, so please don't link any of them.
In my flex-container, I want to display two sections which are both 100% of the page's width. So one section should be positioned on top of the other. Instead, each section is being given 50% of the page's width even when I explicitly defined 100%. I have no idea why this is happening. The browser's developer tools don't lead me to any conclusions either.
I reconstructed the problem in a jsFiddle. I get the expected result if, let's say, I define one section to be 7/12 the page's width and the other section to be 5/12 the page's width.
HTML
<div class="flex-container">
<div class="flex-12">
<h4>Title</h4>
<p class="flex-2">Content</p>
<p class="flex-2">Content</p>
<p class="flex-2">Content</p>
<p class="flex-2">Content</p>
<p class="flex-2">Content</p>
<p class="flex-2">Content</p>
<p class="flex-2">Content</p>
<p class="flex-2">Content</p>
</div>
<div class="flex-12">
<h4>Title 2</h4>
</div>
</div>
Need to tell the container to permit wrapping as the default is nowrap.
.flex-container {
display: flex;
flex-wrap:wrap;
}
Jsfiddle Demo
You can use also use flex-direction column:
.flex-container {
display: flex;
flex-direction: column;
}