Why does div display above div with display:flex - html

I have a div (divA) which has the style "display:flex" and another div (divB) without any positioning styles/properties which displays itself above divA even when divB comes after divA inside my HTML file.
(Someone who is relatively new to CSS so please excuse any poor/confusing terminology)
#login_or_signup {
display: flex;
top: 30%;
position: relative;
}
#terms_conditions {
text-align: center;
}
<div id="welcome_div">
<h1>Hi. Welcome to Website name</h1>
<p>Please Login or Sign up</p>
</div>
<div id="login_or_signup"> <!--(divA)-->
<div id="login_div" class="select_options borders">
<p>Login</p>
</div>
<div id="line"></div> <!-- displays grey line between divs -->
<div id="signup_div" class="select_options borders">
<p>Sign Up</p>
</div>
</div>
<div id="terms_conditions"> <!--(divB)-->
<p>Please view our T&C's</p>
</div>

By using 'top: 30%' you are forcing position of that div.

by using relative top:30% DOES NOTHING. If you used position:absolute it would reposition the element. Your code seems to work just fine.
#login_or_signup {
display: flex;
top: 30%;
position: relative;
}
#terms_conditions {
text-align: center;
}
<div id="login_or_signup">div a <!--(divA)-->
<div id="login_div" class="select_options borders">
<p>Login</p>
</div>
<div id="line"></div> <!-- displays grey line between divs -->
<div id="signup_div" class="select_options borders">
<p>Sign Up</p>
</div>
</div>
<div id="terms_conditions"> <!--(divB)-->
<p>div b</p>
</div>

#login_or_signup {
display: flex;
}
#terms_conditions {
text-align: center;
}
<div id="welcome_div">
<h1>Hi. Welcome to Website name</h1>
<p>Please Login or Sign up</p>
</div>
<div id="login_or_signup"> <!--(divA)-->
<div id="login_div" class="select_options borders">
<p>Login</p>
</div>
<div id="line"></div> <!-- displays grey line between divs -->
<div id="signup_div" class="select_options borders">
<p>Sign Up</p>
</div>
</div>
<div id="terms_conditions"> <!--(divB)-->
<p>Please view our T&C's</p>
</div>
I changed your CSS rules to fix the problem.
Removing position: relative; resolves the positioning issue.

Related

Centering texts inside div using Flex

I am trying to split the div "Info" into three sections to evenly divide the sections. I think I did that correctly to begin, but I am having issues centering the titles (Address, Hours, Contact) from their own divs. The example below is how I'm trying to make it look. Thank you for your time.
Example
.info{
display: flex;
justify-content: space-between;
}
<div class="info">
<div class="left-info">
<div class="address-title">
Address
</div>
<div class="address">
1111 Some Words, Tampa, FL 33647, United States
</div>
</div>
<div class="middle-info">
<div class="hours-title">
Hours
</div>
<div class="hours">
Mon-Fri
</div>
</div>
<div class="right-info">
<div class="contact-title">
Contact
</div>
<div class="contact">
111-111-1111
</div>
</div>
</div>
Try this one. I've given width: 33% to each div inside .info in order to divide the entire width into three equal width. In addition, gave text-align: center to individual divs.
.info {
display: flex;
justify-content: space-between;
}
.left-info,
.right-info,
.middle-info {
width: 33%;
text-align: center;
}
<div class="info">
<div class="left-info">
<div class="address-title">
Address
</div>
<div class="address">
1111 Some Words, Tampa, FL 33647, United States
</div>
</div>
<div class="middle-info">
<div class="hours-title">
Hours
</div>
<div class="hours">
Mon-Fri
</div>
</div>
<div class="right-info">
<div class="contact-title">
Contact
</div>
<div class="contact">
111-111-1111
</div>
</div>
</div>
I hope this helps you.

Error when trying to write two div elements The template root requires exactly one element.eslint-plugin-vue

<template>
<div class="footerpart-container">
<div class="general-container">
dadada
</div>
<div class="legal-container">
dadad
</div>
<div class="helpsupport-container">
dadada
</div>
</div>
<div class="footer-two">
<div class="follow-us">follow us</div>
</div>
</template>
Under one template i have two div tags, Where i am trying to display first div on the top and second footer-two tag in the bottom.
After placing there i am getting error as
The template root requires exactly one element.eslint-plugin-vue
You can use flexbox.
When you use display: flex it align flex-items side-by-side because of its default flex-position: row. But to make footerpart-container and footerparttwo-container flex items you need to wrap both HTML element into a container(footer-parent-container)
.footer-parent-container {
display: flex;
gap: 1rem;
}
.footerpart-container {
background-color: #ffffff;
height: auto;
display: flex;
}
.footerparttwo-container {
background-color: #ffffff;
}
<div class="footer-parent-container">
<div class="footerpart-container">
<div class="general-container">
sas
</div>
<div class="legal-container">
<div class="legal-title">Legal</div>
</div>
<div class="helpsupport-container">
<div class="helpsupport-title">Help & support</div>
</div>
<div class="whatsup-icon-helpnum">
<div class="ph-num">180034014</div>
</div>
</div>
<div class="footerparttwo-container">
<div class="follow-us">follow us</div>
</div>
</div>

Having trouble getting a Div to expand to the height of another div once text is loaded

In this CodePen, I am trying to get the .icon div to appear the full height of the div it's in. Unfortunately, it looks like it's loading before the text is there so the div has a height of 0 when it loads. How would I get it to load once the text is there and grab that full height? Preferably with no JS if possible.
All help is appreciated!
HTML
.faqSection {
height: 600px;
width: 100vw;
}
.topFaqSection {
margin: 100px 0 40px 10vw;
}
.innerFaqSection {
height: 100%;
width: 100%;
display: flex;
justify-content: center;
}
.leftFaq {
width: 35%;
height: 100%;
/* background-color: violet; */
}
.rightFaq {
width: 35%;
height: 100%;
/* background-color: blanchedalmond; */
}
.singleFaqBlock {
margin: 20px 0 0 0;
}
.questionBlock {
background-color: red;
display: flex;
flex-direction: row;
align-content: flex-start;
}
.icon {
background-color: blue;
width: 50px;
height: 100%;
}
.questionText {
/* display: none; */
background-color: green;
width: 100%;
}
.answerBlock {}
.answerBlock p {
margin: 0 0 0 62px;
}
.hiddenText {
display: none;
}
.notHiddenText {
display: block;
}
<div class="faqSection">
<div class="topFaqSection">
<h1>Questions? Look Here</h1>
<div class="bar blue"></div>
</div>
<div class="innerFaqSection">
<div class="leftFaq">
<div class="singleFaqBlock">
<div class="questionBlock">
<div class="icon">
<div class="circle-plus closed">
<div class="circle">
<div class="horizontal"></div>
<div class="vertical"></div>
</div>
</div>
</div>
<div class="questionText">
<h3>
How do I earn a return?
</h3>
</div>
</div>
<div class="answerBlock">
<p class="hiddenText">
Yes! We would love to answer your question thank you for giving us the opoportunity!!
</p>
</div>
</div>
<div class="singleFaqBlock">
<div class="questionBlock">
<div class="icon">
<div class="circle-plus closed">
<div class="circle">
<div class="horizontal"></div>
<div class="vertical"></div>
</div>
</div>
</div>
<div class="questionText">
<h3>
What kind of returns can I expect?
</h3>
</div>
</div>
<div class="answerBlock">
<p class="hiddenText">
Yes! We would love to answer your question thank you for giving us the opoportunity!!
</p>
</div>
</div>
</div>
<div class="space"></div>
<div class="rightFaq">
<div class="singleFaqBlock">
<div class="questionBlock">
<div class="icon">
<div class="circle-plus closed">
<div class="circle">
<div class="horizontal"></div>
<div class="vertical"></div>
</div>
</div>
</div>
<div class="questionText">
<h3>
When is the platform releasing?
</h3>
</div>
</div>
<div class="answerBlock">
<p class="hiddenText">
Yes! We would love to answer your question thank you for giving us the opoportunity!!
</p>
</div>
</div>
<div class="singleFaqBlock">
<div class="questionBlock">
<div class="icon">
<div class="circle-plus closed">
<div class="circle">
<div class="horizontal"></div>
<div class="vertical"></div>
</div>
</div>
</div>
<div class="questionText">
<h3>
Why invest in real estate? </h3>
</div>
</div>
<div class="answerBlock">
<p class="hiddenText">
Yes! We would love to answer your question thank you for giving us the opoportunity!!
</p>
</div>
</div>
<div class="singleFaqBlock">
<div class="questionBlock">
<div class="icon">
<div class="circle-plus closed">
<div class="circle">
<div class="horizontal"></div>
<div class="vertical"></div>
</div>
</div>
</div>
<div class="questionText">
<h3>
I'm a - and interested in raising money through -, what should I do? </h3>
</div>
</div>
<div class="answerBlock">
<p class="hiddenText">
Yes! We would love to answer your question thank you for giving us the opoportunity!!
</p>
</div>
</div>
</div>
</div>
</div>
As I said in a a comment, removing the height: 100% rule should fix it for you. The "why" for it is a bit... unsavory.
Flex children default to "align-self: stretch", so they'll stretch naturally. But when you set a height, it will use that value. The problem is percentage height is calculated from the height actually specified for the parent and .icon's parent (.questionBlock) has no height specified: so .icon gets 100% of 0. If you were to set a height to .questionBlock, .icon would adapt.
From the specs:
The percentage is calculated with
respect to the height of the generated box's containing block. If the
height of the containing block is not specified explicitly (i.e., it
depends on content height), and this element is not absolutely
positioned, the value computes to 'auto'.
This is the comment that pointed me into the right direction. Maybe check it out?

how to make div overlapped another div using html and css

I have two div container, one act as dropdown component, when dropdown clicked, it will not overlapped second component. I am trying using z-index and css position, also it didnt work, try another solution from so and googling but not found the answer, hope anyone can guide this. this is stackblitz I created, what have I tried:
html
<div>
<div class="div1" (click)="selectSavedCard()">
<div *ngIf='!hasSelected'>
<div>
<p>dropdown V</p>
</div>
</div>
<div *ngFor="let card of savedCards">
<div>
<p>{{card.viewValue}}</p>
</div>
</div>
</div>
<div *ngIf="show">
<div *ngFor="let card of savedCreditCards" (click)="selectDropdownCard(card)">
<div>
<p>{{card.viewValue}}</p>
</div>
</div>
</div>
<div class="div2">overlapped this div</div>
</div>
css
.div1 {
border: 1px solid black;
z-index: 1;
}
.div2 {
z-index: 2;
}
ts
You want the dropdown of div1 to overlap the div2 right?
There are multiple ways to do this, but the simplest one i can imagine is to simply put a position: absolute;
property on the dropdown div.
<div>
<div class="div1" (click)="selectSavedCard()" [(ngModel)]="selectedCard" ngDefaultControl>
<div *ngIf='!hasSelected'>
<div>
<p>dropdown V</p>
</div>
</div>
<div style="position: absolute;z-index: 100;background: #aaa;width: 100%;" *ngFor="let card of savedCards">
<div>
<p>{{card.viewValue}}</p>
</div>
</div>
</div>
<div style="position: absolute;z-index: 100;background: #aaa;width: 100%;" *ngIf="show">
<div *ngFor="let card of savedCreditCards" (click)="selectDropdownCard(card)">
<div>
<p>{{card.viewValue}}</p>
</div>
</div>
</div>
<div class="div2">overlapped this div</div>
</div>
From your stackblitz link behavior I think you just don't want the overlapped div to be pushed down when the dropdown is clicked.
You just need to add a wrapper around your dropdown and set the position of the dropdown content to be absolute.
I will edit your stackblitz app HTML and CSS to show this.
app.component.html
<hello name="{{ name }}"></hello>
<div class="container-div">
<div class="wrapp-dropdown">
<div class="div1" (click)="selectSavedCard()" [(ngModel)]="selectedCard" ngDefaultControl>
<div *ngIf='!hasSelected'>
<div>
<p>dropdown V</p>
</div>
</div>
<div *ngFor="let card of savedCards" class="dropdown-content">
<div>
<p>{{card.viewValue}}</p>
</div>
</div>
</div>
<div *ngIf="show" class="dropdown-content">
<div *ngFor="let card of savedCreditCards" (click)="selectDropdownCard(card)">
<div>
<p>{{card.viewValue}}</p>
</div>
</div>
</div>
</div>
<div class="div2">overlapped this div</div>
Then I updated your app.component.css to look like this
p {
font-family: Lato;
}
.container-div {
position: relative;
}
.div1 {
border: 1px solid black;
z-index: 3;
position: relative;
}
.wrap-dropdown {
position: relative;
}
.dropdown-content {
position: absolute;
}
b.div2 {
z-index: 2;
}

CSS Nth-Child 3n hierarchy structure

With how my HTML is structure I am having hard time selecting 3n child. It doesn't seem even notice the 3n selector of class heroLetter, but if I use the 1n child selector the code notices the class, but it also selects every div. I am not sure how to call the 3n child selector with this structure of classes I have made.
Code:
.heroLetter {
float: left;
width: 48%;
margin-top: 150px;
text-align: center;
font-size: 600px;
color: #f5543a;
position: relative;
}
.windowWrapper .section .heroLetter:nth-child(3n) {
float: left;
width: 48%;
margin-top: 150px;
text-align: center;
font-size: 200px;
color: #f5543a;
position: relative;
}
<div class="wrapper">
<div id="section1" class="windowWrapper">
<div class="section group">
<h1 class="introH1">
<span class="Grand">GRAND</span>
<span class="Stand">STAND</span>
</h1>
<p class="introP">A new font.</p>
scroll down
</div>
</div>
<div id="section2" class="windowWrapper">
<div class="section group">
<div class="col span_6_of_12">
<h1>STORY</h1>
<p>Grandstand invokes</p>
</div>
<div class="heroLetter">
G
</div>
</div>
</div>
<div id="section3" class="windowWrapper">
<div class="section group">
<div class="col span_6_of_12">
<h1>PROCESS</h1>
<p>Grandstand invokes</p>
</div>
<div class="heroLetter">
S
</div>
</div>
</div>
<div id="section4" class="windowWrapper form">
<div class="section group">
<div class="col span_6_of_12">
<h1>BEAM</h1>
<p>Grandstand invokes</p>
</div>
<div class="heroLetter">
<div class="circle"></div>
a
</div>
</div>
</div>
</div>
</div>
The nth-child refers to children of the same parent only.
You could adjust your code to refer to the outer most common element.
Some css like this should help you:
.windowWrapper:nth-child(4n) .section .heroLetter {}
In this case it's the 4th windowWrapper since it contains your 3rd heroLetter