The issue I am having is with my Flexbox growing in height when I enter content inside of it. I am not 100% sure why this is happening, but I believe it has something to do with it not being in an absolute position and thus keeping its height property.
Included is the CodePen where I have the HTML and CSS setup for the Flexbox style site that I am making (Also included the Snippet below) Here is so info about it
body p {
color: white;
font-size: 30px;
margin-top: 10px !important; }
.home-wrap {
display: flex;
min-height: 100vh;
justify-content: center;
transition: background 1.5s ease-in-out; }
.home-sections {
display: flex;
flex-direction: row;
flex-wrap: wrap;
min-width: 775px;
max-width: 775px; }
.home-sections section {
border-radius: 20px;
border: 3px solid white;
overflow: hidden; }
.home-sections .flex {
display: flex;
flex-direction: row; }
.home-sections .flex--center {
justify-content: center; }
.col-1 {
text-align: center; }
.alignTop {
display: flex;
flex-direction: row;
flex-wrap: wrap;
min-width: 100%;
align-items: flex-start;
transition: opacity 1.5s ease-in-out; }
.alignCenter {
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
position: relative;
width: 50%; }
.alignBottom {
display: flex;
flex-direction: row;
flex-wrap: wrap;
min-width: 100%;
align-items: flex-end;
transition: opacity 1.5s ease-in-out; }
section.about {
position: absolute;
width: 100%;
height: 220%;
left: 100%;
box-shadow: -6px 6px 8px rgba(0, 0, 0, 0.6);
z-index: 1;
transition: transform 1.5s ease-in-out;
animation: enticing-grow 2s 2;
background-color: #CB7E15; }
section.about .displayB {
display: block;
text-align: center; }
section.about .displayB h1 {
margin-top: 10px;
text-align: center;
font-size: 30px;
text-shadow: 5px 5px 8px white; }
section.about .displayB p {
font-size: 16px; }
section.about .mike-faq {
display: flex;
opacity: 0;
flex-direction: row;
justify-content: space-around;
flex-wrap: wrap;
max-width: 100%;
transition: all 1.5s ease-in-out; }
section.setup {
width: calc(55% - 6px);
height: 80%;
box-shadow: -8px 8px 8px rgba(0, 0, 0, 0.6);
background-color: #004EFF; }
section.social {
width: calc(45% - 6px);
height: 55%;
box-shadow: 8px 8px 8px rgba(0, 0, 0, 0.6);
opacity: 0.5;
transition: all 1s ease-in-out;
background-color: #585656; }
section.social:hover {
opacity: 1;
transform: scale(1.5);
z-index: 2; }
section.social .displayB {
display: block; }
section.social .displayB p {
text-align: center;
margin: 10px; }
section.social .social-wrap {
display: flex;
flex-direction: row;
max-width: 100%;
justify-content: space-around; }
section.social .social-wrap .twitter-logo {
background-image: url(/assets/img/twitter-logo.gif);
background-size: contain;
width: 55px;
height: 55px;
box-shadow: 0 5px 20px 0 #1DA1F2; }
section.social .social-wrap .email-logo {
background-image: url(/assets/img/gmail-logo.png);
background-size: contain;
width: 55px;
height: 55px;
box-shadow: 0 5px 20px 0 #E70F10; }
section.social .social-wrap .facebook-logo {
background-image: url(/assets/img/facebook-logo.png);
background-size: contain;
width: 55px;
height: 55px;
box-shadow: 0 5px 10px 5px #3C5A98; }
section.social .social-wrap .github-logo {
background-image: url(/assets/img/github-logo.png);
background-size: contain;
width: 55px;
height: 55px;
box-shadow: 0 5px 20px 0 #E04006; }
section.twitch {
width: calc(55% - 6px);
height: 80%;
box-shadow: -8px -8px 8px rgba(0, 0, 0, 0.6);
background-color: #5A3E85; }
section.twitch h1 {
margin-top: 10px;
font-size: 30px;
text-align: center; }
section.twitch p {
font-size: 16px; }
section.twitch .displayB {
display: block;
text-align: center; }
.button {
color: #5A3E85; }
section.webdesign {
width: calc(45% - 6px);
height: 53%;
box-shadow: 8px -8px 8px rgba(0, 0, 0, 0.6);
background-color: #1F843A; }
section.youtube {
position: absolute;
width: 95%;
height: 140%;
margin-right: 5px;
box-shadow: -8px 0 8px rgba(0, 0, 0, 0.6);
transition: opacity 1.5s ease-in-out;
background-color: #CC181E; }
<div class="home-wrap">
<div class="home-sections">
<div class="alignTop">
<section class="twitch">
<div class="flex flex--center displayB">
<h1>Twitch</h1>
<!-- <p>I've been livestreaming on Twitch since it's days as Justin.tv - I plan to pick it back up again once I can figure out a schedule</p> -->
</div>
</section>
<section class="webdesign">
<div class="flex flex--center">
<p>Web Design</p>
</div>
</section>
</div>
<div class="alignCenter">
<section class="youtube">
<div class="flex flex--center">
<P>YouTube</P>
</div>
</section>
<section class="about grown">
<div class="flex flex--center displayB">
<h1>What's Going on, Mike here, and Welcome to my Site!</h1>
<p>I'm your typical 26 year old nerd, who loves computers, video games, pretty much anything tech. Along with that, I have a ton of hobbies that range from playing music to stock investments. </p>
<p>I've always been interested in, and worked on my web design skills, but it wasn't until the past few months where I decided this is what I am passionate about.</p>
<p>With that said, click around the site to learn more about me. All panels are expandable clickable which will allow you to learn more about "Mike" and who I am!</p>
<div class="mike-faq">
<p>FAQ 1</p>
<p>FAQ 2 </p>
<p>FAQ 3</p>
<p>FAQ 4</p>
</div>
</div>
</section>
</div>
<div class="alignBottom">
<section class="setup">
<div class="flex flex--center">
<p>Setup</p>
</div>
</section>
<section class="social">
<div class="flex flex--center displayB">
<p>Social</p>
<div class="social-wrap">
<div class="twitter-logo"></div>
<div class="email-logo"></div>
<div class="facebook-logo"></div>
<div class="github-logo"></div>
</div>
</div>
</section>
</div>
</div>
1 - I have a wrapping div around the site content so I can control the flow and background of the back
2 - I have another wrapping div for each "Row" of Flexbox so I can have them align in different areas (Top is aligned Flex-Start, Center is aligned Flex-Center and Bottom is aligned Flex-Bottom)
3 - The 2 Center Flexboxes (YouTube and About) are set with Absolute position so I am able to have the "About" section grow out and overlap the top and bottom sections.
4 - I have all the fleboxes set with % height and width so they will scale with the window value.
5 - Inside of each FlexBox section, I have a container so that I can manipulate the content and move it around so it fits within their parent flexbox.
Now, I am not 100% sure if all the nesting and parent/child elements is the best way to handle what I am trying to do, but I haven't been able to visualize it any other way and get it work (outside of the way I am doing it).
So - to go over it again, inside of the "Twitch: panel I have a <p> section that when I uncomment, the flexbox will grow in height, rather than remain the same. However, in the "About" section, this doesn't happen. The only difference I am able to see is that the "About" section is position: absolute.
You can play around by giving alignTop, alignCenter and alignBottom heights.
http://codepen.io/anon/pen/GWEgMK : try commenting in and out what you said then find the adequates values for heights you are happy with.
.alignTop {
height:33%;}
.alignCenter {
height:25%;}
.alignBottom {
height:20%;}
Not sure that's exactly what you want but to be honnest there is way too much clutter in your codepen for us to really want to try :) Are the animations even relevant ?
rather than % heights you may want to let flexbox handle the heights for you, as in grow to the viewport as it is designed to do but then use a max-height with a vh unit rather than a % value (like max-height: 75vh instead of max-height:75%). vh uses the viewport to scale not the parent div.
Related
This question already has answers here:
How can I vertically align elements in a div?
(28 answers)
Flexbox: center horizontally and vertically
(14 answers)
Closed last year.
I am trying to make a LoL website, and I have a problem trying to display the list of matches, because I don't know how to align vertically the content of each match without leading to another problem. Initially, I have this
<li>
<div class="match_li lost_match">
<div class="match_li_champ">
<img src="https://ddragon.leagueoflegends.com/cdn/12.1.1/img/champion/Ekko.png"
alt="Ekko"
title="Ekko">
</div>
<div class="match_li_info">
<h3>3/13/14</h3>
<h6>ARAM</h6>
</div>
<div class="match_li_extra">
<img src="../../resources/images/lol_assets/farm_icon.png">
<h5>22<h5>
<br>
<img src="../../resources/images/lol_assets/gold_icon.png">
<h5>12838<h5>
</div>
<div class="match_li_items">
<img src="https://ddragon.leagueoflegends.com/cdn/12.1.1/img/item/3157.png">
<img src="https://ddragon.leagueoflegends.com/cdn/12.1.1/img/item/3916.png">
<img src="https://ddragon.leagueoflegends.com/cdn/12.1.1/img/item/1026.png">
<img src="https://ddragon.leagueoflegends.com/cdn/12.1.1/img/item/3089.png">
<img src="https://ddragon.leagueoflegends.com/cdn/12.1.1/img/item/6655.png">
<img src="https://ddragon.leagueoflegends.com/cdn/12.1.1/img/item/3020.png">
<img src="https://ddragon.leagueoflegends.com/cdn/12.1.1/img/item/2052.png">
</div>
<div class="match_li_spells">
<img src="https://ddragon.leagueoflegends.com/cdn/12.1.1/img/spell/SummonerFlash.png" alt="Flash" title="Flash">
<img src="https://ddragon.leagueoflegends.com/cdn/12.1.1/img/spell/SummonerBarrier.png" alt="Barrier" title="Barrier">
</div>
<div class="match_li_time">
<h4>23:20 • 2022/01/09</h4>
</div>
<div class="match_li_expand">
<h4>▼</h4>
</div>
</div>
</li>
and this CSS
.match_li {
display: flex;
flex-direction: row;
margin-bottom: 20px;
padding: 20px 30px;
color: rgba(0, 0, 0, 0.6);
box-shadow: 0 4px 6px 0 rgba(0, 0, 0, 0.2), 0 6px 15px 0 rgba(0, 0, 0, 0.2);
}
.match_li div {
margin-right: 40px;
background-color: lightgreen;
}
.won_match {
background-color: rgba(184, 212, 242, 0.9);
}
.lost_match {
background-color: rgba(244, 144, 144, 0.9);
}
.match_li_champ img {
display: block;
width: 80px;
border-radius: 50%;
}
.match_li_info {
width: 100px;
}
.match_li_extra {
width: 100px;
}
.match_li_extra img {
width: 20px;
}
.match_li_extra h5 {
display: inline;
}
.match_li_items {
display: flex;
flex-direction: row;
}
.match_li_items img {
display: block;
width: 40px;
height: 40px;
margin-right: 3px;
}
.match_li_spells {
display: flex;
flex-direction: row;
}
.match_li_spells img {
display: block;
width: 40px;
height: 40px;
margin-right: 3px;
}
When I try to align vertically using position and top, this happens:
new CSS:
.match_li_time {
position: relative;
}
.match_li_time * {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
Does anyone know why the div body dissappears? And why does the text is contracted? Any source for better understanding of this topic would be appreciated c:
When you set the element to position:absolute it is removed from the normal flow so the parent is effectively empty hence the collapse. You can try using flex:
.match_li_time {
display: flex;
justify-content: center;
align-items: center;
}
More about flex here
Container with only position absolute children will not have width and height.
try css below on your prev version before position absolute
.match_li div {
align-items: center;
margin-right: 40px;
background-color: lightgreen;
}
I got a quick question. I want an icon at the top right of the div, and the bottom right. I think I am doing it well, but for some reason it goes behind the div.
Image of what happens, you can see the green and red icon not going above it, but behind
This is the code I wrote:
HTML:
<div v-if="showMenu" class="wrapper">
<!-- Begin karakters onderaan -->
<div v-if="karakters" class="karakters-wrapper">
<span v-for="karakter in karakters" :key="karakter">
<div v-if="karakter !== undefined" class="karakter-box">
<p>{{karakter.charinfo.firstname}} {{karakter.charinfo.lastname}}</p>
<i class="fas fa-play-circle icoon-speel"></i>
<i class="fas fa-trash icoon-verwijder"></i>
</div>
<div v-else class="karakter-box">
<p>Leeg karakter slot</p>
</div>
</span>
</div>
<div v-else>
<h1 style="color:#fff;font-size:48px;">GEDULD!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!</h1>
</div>
<!-- Einde karakters onderaan -->
</div>
^^ Don't mind the v-if etc. that's from VueJS. Anyways, the div with class "karakter-box" is the div where I want an icon at the top right of.
CSS:
width: 100%;
height: 100%;
display: flex;
justify-content: flex-end;
align-items: center;
flex-direction: column;
}
.karakters-wrapper {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
padding: 10px;
}
/* Karakter boxjes */
.karakter-box {
position: relative;
display: flex;
justify-content: center;
align-items: center;
width: 300px;
height: 100px;
background-color: rgba(0, 0, 0, 0.7);
border-top: 8px solid var(--white);
padding: 5px;
margin: 5px;
color: var(--white);
transition: .25s ease-in-out;
}
.karakter-box:hover {
border-top: 8px solid var(--groen);
background-color: rgba(0, 0, 0, 0.9);
}
.icoon-speel {
position: absolute;
top: -10px;
right: -10px;
font-size: 2rem;
background-color: var(--groen);
color: var(--white);
padding: 10px;
border-radius: 100%;
}
.icoon-verwijder {
position: absolute;
bottom: -10px;
right: -10px;
font-size: 2rem;
background-color: var(--rood);
color: var(--white);
padding: 10px;
border-radius: 100%;
}```
I'm not sure why but it looks like there is an overflow: hidden karakter-box class.
even though i don't see it in the code sample you provided.
When i tested the code the sample this issue did not occur
Try Checking for css overflow on karakter-box
I suggest use another for the background and set its width to device width.
use this css code to get positions to right corners
Position: absolute;
and use this at css to get front of div
z-index:1;
index 1 is go front of styles and 2 3 4 going backward as ordered.
set the z-index of div to be -1
div{
z-index: -1;
}
and that of icons to be 1
i{
z-index: 1;
}
i will make the div behind your icons, so you can interact with your icons.
I have a modal window which has an absolutely positioned black div that covers the entire viewport whenever the modal window is open. For some reason though this window doesn't cover a certain element even though it goes over it. Everything else is covered by the black screen just fine so I have no idea why this specific element doesn't.
.black-screen {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.8);
}
The element that is not being covered:
<div class="form-container">
<form class='send-message'>
<input class='message-input' placeholder="Type a message">
</form>
</div>
And the CSS of that element:
.form-container {
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
.send-message {
position: relative;
padding: 20px 0px 20px 20px;
flex: 1;
}
.message-input {
width: 100%;
padding: 15px;
outline: none;
border: none;
background-color: #40444b;
color: #dcddde;
font-size: 14px;
border-radius: 5px 0 0 5px;
}
With small chunk of css I can only guess (css is a cascade and is hereditary)
.form-container {
position: relative; /* remove this */
display: flex;
justify-content: center;
align-items: center;
}
.send-message {
position: relative; /* remove this */
padding: 20px 0px 20px 20px;
flex: 1;
}
.message-input {
width: 100%;
padding: 15px;
outline: none;
border: none;
background-color: #40444b;
color: #dcddde;
font-size: 14px;
border-radius: 5px 0 0 5px;
}
If for whatever reasons this is not possible or it doesn't work - replace div elements but I don't know if this will work in every browser ...
<div class="form-container">
<form class='send-message'> <input class='message-input' placeholder="Type a message"> </form>
</div>
<div class="black-screen">black</div>
If the problem persists, use Validator w3c to find out how bad it is
... in fact, use Validator no matter what
This question already has answers here:
How do you make div elements display inline?
(20 answers)
Closed 4 years ago.
Hello everyone i have a header with a div in my header with a pic in it but i want to display my pics next to eachother but instead of that its displays it under each other how can i fix this i tried to change my css but didnt work.
its now like this when i add anoter div
How it is now:
I want it like this:
this is my code
#import url('https://fonts.googleapis.com/css?family=Josefin+Sans:400,400i,600,600i');
html,
body {
margin: 0;
height: 120%;
font-family: 'Josefin Sans', sans-serif;
}
.header {
position: relative;
overflow: hidden;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: flex-start;
align-content: flex-start;
height: 50vw;
min-height: 400px;
max-height: 550px;
min-width: 300px;
color: #eee;
}
.header:before {
content: "";
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
-webkit-backface-visibility: hidden;
-webkit-transform: translateZ(0) scale(1.0, 1.0);
transform: translateZ(0);
background: #1B2030 url(https://unsplash.it/1999/999?image=1063) top center no-repeat;
background-size: cover;
background-attachment: fixed;
animation: grow 60s linear 10ms infinite;
transition: all 0.2s ease-in-out;
z-index: -2
}
.header a {
color: #eee
}
.info {
width: 100%;
padding: 25% 10% 0 10%;
text-align: center;
text-shadow: 0 2px 3px rgba(0, 0, 0, 0.2)
}
.author {
display: inline-block;
width: 50px;
height: 50px;
border-radius: 50%;
background: url(http://favim.com/media/uploads/images/610/140308/black-n-white-cute-funny-iron-man-Favim.com-1462744.jpg) center no-repeat;
background-size: cover;
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.3);
margin-bottom: 3px
}
.info h4,
.meta {
font-size: 0.7em
}
.meta {
font-style: italic;
}
.twtr {
margin-top: 100px
}
.btn.twtr:after {
content: "\1F426";
padding-left: 5px
}
<body>
<div class="header">
<div class="info">
<h1>TestHeader</h1>
<div class="meta">
test
</div>
<div class="meta">
<br> By James Nodws on May 30, 2017
</div>
</div>
</div>
</body>
You First Have clear the body from margin and padding just in case
body{padding:0;margin:0;}
after that give each div 25% width and display either inline or inline-block
div{width:25%;display:inline;}
Add :
.meta {
display: inline-block
}
div are int display mode block by default, so it wraps the entire ligne. Change to inline-block to allow multiple divs horizontally
You have two options here
You can use Bootsrap as described in here.
Use below CSS
.meta {
float:left;
width: 30%;
}
You can use any other class which is applied only for image divs.
I think you should try using .
.meta {
display : flex;
}
This also aligns all the the <divs> in a single row
you can use flex property for,
Display:flex apply flex layout to the flex items or children of the container only. So, the container itself stays a block level element and thus takes up the entire width of the screen. ... Display:inline-flex apply flex layout to the flex items or children as well as to the container itself.
I have header tag, which has full width/height image on the background.
I need to algin elements in the center of that page exactly as picture shows.
First goes image, than text, than buttons one after another one and on the very bottom of the page is slider
apart from slider, I've managed to put all content to the center with code below
Also, I'm using boostrap and jquery if needed
It's one page design, this is just a header
Thank you for any help :)
<header>
<img src="" alt="full">
<h1>The</h1>
Login
Browse
<div class="swiper-container">
</div>
</header>
SCSS
header {
margin-top: -56px !important;
background-image: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)), url(../img_cover_m.jpg);
background-size: cover;
background-position: center;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
img {
margin-top: 5%;
max-width: 50%;
height: auto;
}
h1 {
color: #fff;
}
.btn {
#include Myriad-Pro-Light;
}
.btn-green {
margin-top: 5%;
color: #fff;
}
.btn-grey {
color: #000;
}
.swiper-container {
margin-top: 5%;
width: 100%;
height: 300px;
}
}
You can achieve this by using the following properties at the appropriate places.
text-align:center;
display:flex;
align-center;
margin:0 auto;
Also as your using bootstrap so some of the classes may get overwritten so make sure to use !important on properties that you want to force your setting on.
Using your code i have made some changes using the above mentioned suggestions and here is the code:
<header>
<img src="http://placehold.it/350x150" alt="full">
<h1>The</h1>
Login
Browse
<div class="swiper-container">
<p>Large full width div, which must stay on the bottom of the header tag</p>
</div>
</header>
header {
background-image: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)), url(../img_cover_m.jpg);
background-size: cover;
background-position: center;
height: 100vh;
min-width: 20%;
display: flex;
flex-direction: column;
align-items: center;
}
img {
margin: 0 auto;
display: block;
max-width: 50%;
height: auto;
}
h1 {
color: #fff;
text-align:center;
}
.btn {
#include Myriad-Pro-Light !important;
margin: 10px auto !important;
display: block !important;
width: 25vw !important;
text-align:center !important;
padding: 6px 0px !important;
}
.btn-green {
color: #fff;
display:block;
}
.btn-grey {
color: #000;
display:block;
}
.swiper-container {
background-color:red;
width: 100%;
height: 300px;
position:absolute;
bottom:0;
display: flex;
align-items: center;
justify-content: center
}
.swiper-container p{
#include Myriad-Pro-Light !important;
margin:0 auto;
color:white;
font-size: 18px;
}
Here is a sample using this code. http://codepen.io/Nasir_T/pen/PboZme