Width change of one row moves the whole div up - html

I am trying to create an overlay for the website, it should have the form of three boxes stacked on top of each other. Currently, they are situated so that the first two are on the first row, and the third one is on the bottom. To make them all be on a separate row, I am trying to add single parameter to css: width: 100%, which worked for the third row, but ruins everything if I do it to either of the ones left.
Here is the code snippet, It will work on its own:
* {
box-sizing: border-box;
}
#box {
width: 70vw;
height: 80vh;
margin: 10px;
padding: 10px;
border-radius: 25px;
}
.column4 {
height: 39vh;
width: 50%;
float: left;
padding: 50px;
text-align: center;
color: black;
font-size: 20px;
line-height: 1.3;
/*width: 100%;*/ /* here is the culprit*/
}
.column5 {
height: 39vh;
width: 100%;
float: left;
padding: 10px;
text-align: center;
color: black;
font-size: 20px;
line-height: 1.3;
}
#overlay {
position: fixed;
display: none;
width: 100%;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.8);
z-index: 2;
cursor: pointer;
}
#text {
position: absolute;
top: 50%;
left: 50%;
font-size: 50px;
color: white;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
#boxt3 {
font-size: 25px;
}
#boxt1 {
font-size: 20px;
}
#boxt2 {
font-size: 20px;
}
<div id="overlay" style="z-index: 100; display: block;" onclick="off()">
<div id="text">
<div id="box" style="background:#fff">
<div class="row">
<div id="boxt1" class="column4" style="padding-top: 0; overflow: auto">Facebook, Inc.<br>NASDAQ<br>US<br>Internet Content & Information<br>Communication Services<br>some nice info</div>
<div id="boxt2" class="column4" style="padding-top: 0; overflow: auto">Price: 341.00 <br>mCap: 965.39B<br>Beta: 1.295305<br>volAvg: 14142012<br>P/E: NA</div>
<div class="column5" style="padding-top: 5; overflow: auto">
<h2 id="boxt3" stle="">Key features:<br> Net income: 6969% year-to-year<br> Undervalued on Very% by P/S<br>We love your data -Mark<br><br> Estimated probability of success: 0<br></h2>
</div>
</div>
</div>
</div>
</div>
I understand that there is probably some dumb mistake, but I can't find it at all (I have just started learning :) ). What is the issue here?

The issue occurs because you have set the height for the child element which is too high (39vh + 39vh + 39vh) for the parent element (80vh) . Try fitting the height of the child elements into parent's height. It will fix your problem.
* {
box-sizing: border-box;
}
#box {
width: 70vw;
height: 80vh;
/*margin: 10px;
padding: 10px;*/
border-radius: 25px;
}
.column4 {
height: 20vh;
width: 50%;
float: left;
padding: 50px 50px 10px;
text-align: center;
color: black;
font-size: 20px;
line-height: 1.3;
width: 100%;
}
*{box-sizing:border-box;}
.column5 {
height: 40vh;
width: 100%;
float: left;
padding: 10px;
text-align: center;
color: black;
font-size: 20px;
line-height: 1.3;
}
#overlay {
position: fixed;
display: none;
width: 100%;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.8);
z-index: 2;
cursor: pointer;
}
#text {
position: absolute;
top: 50%;
left: 50%;
font-size: 50px;
color: white;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
#boxt3 {
font-size: 25px;
}
#boxt1 {
font-size: 20px;
}
#boxt2 {
font-size: 20px;
}
<div id="overlay" style="z-index: 100; display: block;" onclick="off()">
<div id="text">
<div id="box" style="background:#fff">
<div class="row">
<div id="boxt1" class="column4" style="padding-top: 0; overflow: auto">Facebook, Inc.<br>NASDAQ<br>US<br>Internet Content & Information<br>Communication Services<br>some nice info</div>
<div id="boxt2" class="column4" style="padding-top: 0; overflow: auto">Price: 341.00 <br>mCap: 965.39B<br>Beta: 1.295305<br>volAvg: 14142012<br>P/E: NA</div>
<div class="column5" style="padding-top: 5; overflow: auto">
<h2 id="boxt3" stle="">Key features:<br> Net income: 6969% year-to-year<br> Undervalued on Very% by P/S<br>We love your data -Mark<br><br> Estimated probability of success: 0<br></h2>
</div>
</div>
</div>
</div>
</div>
Now I have set the child element's height to 20vh + 20vh + 40vh sums up to the height of the parent's height 80vh

You must remove width: 100% from column5 class

* {
box-sizing: border-box;
}
#box {
width: 70vw;
height: 80vh;
margin: 10px;
padding: 10px;
border-radius: 25px;
}
.column4 {
height: 39vh;
width: 50%;
float: left;
padding: 50px;
text-align: center;
color: black;
font-size: 20px;
line-height: 1.3;
/*width: 100%;*/ /* here is the culprit*/
}
.column5 {
height: 39vh;
float: left;
padding: 10px;
text-align: center;
color: black;
font-size: 20px;
line-height: 1.3;
}
#overlay {
position: fixed;
display: none;
width: 100%;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.8);
z-index: 2;
cursor: pointer;
}
#text {
position: absolute;
top: 50%;
left: 50%;
font-size: 50px;
color: white;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
#boxt3 {
width : 50px;
font-size: 25px;
}
#boxt1 {
width : 30px;
font-size: 20px;
}
#boxt2 {
width : 50px;
font-size: 20px;
}

<div id="overlay" style="z-index: 100; display: block;" onclick="off()">
<div id="text">
<div id="box" style="background:#fff">
<div class="row">
<div id="boxt1" class="column4" style="padding-top: 0; overflow: auto">Facebook, Inc.<br>NASDAQ<br>US<br>Internet Content & Information<br>Communication Services<br>some nice info</div>
<div id="boxt2" class="column4" style="padding-top: 0; overflow: auto">Price: 341.00 <br>mCap: 965.39B<br>Beta: 1.295305<br>volAvg: 14142012<br>P/E: NA</div>
<div class="column5" style="padding-top: 5; overflow: auto">
<h2 id="boxt3" stle="">Key features:<br> Net income: 6969% year-to-year<br> Undervalued on Very% by P/S<br>We love your data -Mark<br><br> Estimated probability of success: 0<br></h2>
</div>
</div>
</div>
</div>
</div>

Related

Absolutely positioned black screen covers the text of a div but not the image and I don't understand why [duplicate]

This question already has answers here:
Position absolute but relative to parent
(5 answers)
Closed 2 years ago.
As you can see in the code below, the absolutely positioned black screen div covers the members's username but not the actual image. The image stays over the black screen as if it has high z-index, but it doesn't. Is there any way to make the black screen cover the image without completely rewriting the CSS?
.members {
width: 239px;
background-color: #2f3136;
}
.member {
display: flex;
align-items: center;
padding: 30px 20px 30px 20px;
}
.member-image-container {
position: relative;
margin-right: 10px;
}
.member-image {
width: 32px;
height: 32px;
border-radius: 50%;
}
.member-username {
font-weight: 500;
color: #8e9297;
margin-right: 10px;
}
.crown {
color: #faa61a;
}
.online-indicator,
.offline-indicator
{
width: 10px;
height: 10px;
border-radius: 50%;
position: absolute;
bottom: 0;
right: 0;
}
.online-indicator {
background-color: #43b581;
}
.offline-indicator {
background-color: #747f8d;
}
.black-screen {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.8);
}
<div class='navigation'>
<div class='modal'>
<div class="black-screen"></div>
</div>
</div>
<div class='server'>
<div class="members">
<div class="member">
<div class="member-image-container">
<img class='member-image' src="https://api.adorable.io/avatars/100/BozhidarKabzamalov">
<div class='online-indicator'></div>
</div>
<span class='member-username'>Username</span>
</div>
</div>
</div>
Just add position: relative; in member-username
Hope it will work.
.members {
width: 239px;
background-color: #2f3136;
}
.member {
display: flex;
align-items: center;
padding: 30px 20px 30px 20px;
}
.member-image-container {
position: inherit;
margin-right: 10px;
}
.member-image {
width: 32px;
height: 32px;
border-radius: 50%;
}
.member-username {
font-weight: 500;
color: #8e9297;
margin-right: 10px;
position: inherit;
}
.crown {
color: #faa61a;
}
.online-indicator,
.offline-indicator
{
width: 10px;
height: 10px;
border-radius: 50%;
position: absolute;
bottom: 0;
right: 0;
}
.online-indicator {
background-color: #43b581;
}
.offline-indicator {
background-color: #747f8d;
}
.black-screen {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.8);
}
<div class='navigation'>
<div class='modal'>
<div class="black-screen"></div>
</div>
</div>
<div class='server'>
<div class="members">
<div class="member">
<div class="member-image-container">
<img class='member-image' src="https://api.adorable.io/avatars/100/BozhidarKabzamalov">
<div class='online-indicator'></div>
</div>
<span class='member-username'>Username</span>
</div>
</div>
</div>

Divs not in a straight line when centering them

I am trying to center 4 div boxes in a straight vertical line using translate method you use when centering objects in the middle of the screen, this is the code I used:
.body-component {
position: relative;
margin: 10px;
color: #000;
display: inline-block;
vertical-align: top;
background-color: #ff6d00;
overflow: auto;
border: 1px solid #D0D3D4;
}
.width-medium {
width: 500px;
}
.height-medium {
height: 400px;
}
.code-snippet {
position: relative;
width: 95%;
height: 95%;
background-color: #000;
}
.snippet-title {
position: absolute;
color: #248b98;
font-family: "Open Sans", sans-serif;
padding: 15px;
text-decoration: underline;
z-index: 1;
}
.center {
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
margin: 0px;
}
.boxes {
position: relative;
width: 100%;
height: 100%;
}
.box1 {
position: absolute;
width: 30px;
height: 30px;
background-color: #056ab3;
top: 20%;
left: 50%;
transform: translate(-20%, -50%);
}
.box2 {
position: absolute;
width: 30px;
height: 30px;
background-color: #056ab3;
top: 40%;
left: 50%;
transform: translate(-40%, -50%);
}
.box3 {
position: absolute;
width: 30px;
height: 30px;
background-color: #056ab3;
top: 60%;
left: 50%;
transform: translate(-60%, -50%);
}
.box4 {
position: absolute;
width: 30px;
height: 30px;
background-color: #056ab3;
top: 80%;
left: 50%;
transform: translate(-80%, -50%);
}
<div class="body-component width-medium height-medium">
<span class="snippet-title">Box loading animation</span>
<div class="code-snippet center">
<div class="boxes">
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
</div>
</div>
</div>
I tried multiple methods to fix this, but I would not like to centre them using pixels because I am using this on a responsive website.
If absolute positioning, you can use left: 50% with a negative translateX of 50%.
.body-component {
position: relative;
margin: 10px;
color: #000;
display: inline-block;
vertical-align: top;
background-color: #ff6d00;
overflow: auto;
border: 1px solid #D0D3D4;
}
.width-medium {
width: 500px;
}
.height-medium {
height: 400px;
}
.code-snippet {
position: relative;
width: 95%;
height: 95%;
background-color: #000;
}
.snippet-title {
position: absolute;
color: #248b98;
font-family: "Open Sans", sans-serif;
padding: 15px;
text-decoration: underline;
z-index: 1;
}
.center {
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
margin: 0px;
}
.boxes {
position: relative;
width: 100%;
height: 100%;
}
.box {
position: absolute;
width: 30px;
height: 30px;
background-color: #056ab3;
left: 50%;
transform: translateX(-50%)
}
.box1 {
top: 20%;
}
.box2 {
top: 40%;
}
.box3 {
top: 60%;
}
.box4 {
top: 80%;
}
<div class="body-component width-medium height-medium">
<span class="snippet-title">Box loading animation</span>
<div class="code-snippet center">
<div class="boxes">
<div class="box box1"></div>
<div class="box box2"></div>
<div class="box box3"></div>
<div class="box box4"></div>
</div>
</div>
</div>
That said, you could use flexbox to achieve this layout without having to know the number of the boxes in advance for the purpose of vertical spacing.
html,
body {
margin: 0;
padding: 0;
color: #248b98;
font-family: "Open Sans", sans-serif;
}
.body-component {
background-color: black;
height: 100vh;
border: 10px solid #ff6d00;
box-sizing: border-box;
padding: 10px;
display: flex;
flex-direction: column;
justify-content: space-betwen;
align-items: center;
min-height: 500px;
}
.snippet-title {
flex: 0 1 auto;
text-decoration: underline;
padding: 10px;
}
.code-snippet {
flex: 1 1 auto;
display: flex;
}
.boxes {
width: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
padding: 15px;
}
.box {
width: 30px;
height: 30px;
background-color: #056ab3;
}
<div class="body-component">
<span class="snippet-title">Box loading animation</span>
<div class="code-snippet">
<div class="boxes">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
</div>
</div>
Try this... add transform: translate(-50%, -50%); to box classes
.body-component {
position: relative;
margin: 10px;
color: #000;
display: inline-block;
vertical-align: top;
background-color: #ff6d00;
overflow: auto;
border: 1px solid #D0D3D4;
}
.width-medium {
width: 500px;
}
.height-medium {
height: 400px;
}
.code-snippet {
position: relative;
width: 95%;
height: 95%;
background-color: #000;
}
.snippet-title {
position: absolute;
color: #248b98;
font-family: "Open Sans", sans-serif;
padding: 15px;
text-decoration: underline;
z-index: 1;
}
.center {
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
margin: 0px;
}
.boxes {
position: relative;
width: 100%;
height: 100%;
}
.box1 {
position: absolute;
width: 30px;
height: 30px;
background-color: #056ab3;
top: 20%;
left: 50%;
transform: translate(-50%, -50%);
}
.box2 {
position: absolute;
width: 30px;
height: 30px;
background-color: #056ab3;
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
}
.box3 {
position: absolute;
width: 30px;
height: 30px;
background-color: #056ab3;
top: 60%;
left: 50%;
transform: translate(-50%, -50%);
}
.box4 {
position: absolute;
width: 30px;
height: 30px;
background-color: #056ab3;
top: 80%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="body-component width-medium height-medium">
<span class="snippet-title">Box loading animation</span>
<div class="code-snippet center">
<div class="boxes">
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
</div>
</div>
</div>

z-index positioning of pseudo element

I can't seem to figure out how to get the line positioned underneath the circles. Z-index isn't working and I've got the divs positioned non-static. How can I accomplish this? The idea would be that the portion of the line that overlaps the circles would be positioned behind the circles.
div.step-line {
margin: 0;
}
div.step-col {
padding: 30px 0;
text-align: center;
}
div.step-line div.step-title:before {
right: 50%;
}
div.step-line div.step-number {
font-size: 26px;
border-radius: 50%!important;
display: inline-block;
margin: auto;
padding: 9px;
border: 3px solid #e5e5e5;
position: relative;
z-index: 5;
height: 60px;
width: 60px;
/*text-align: center;*/
}
div.step-line div.step-title {
position:relative;
font-size: 20px;
font-weight: 400;
text-transform: uppercase;
}
div.step-line div.step-title:after {
content: '';
height: 3px;
width: 100%;
position: absolute;
background-color: #e5e5e5;
z-index: 4;
transform: translateY(-100%);
top: -90%;
left: 0%;
}
div.step-line div.step-col.first div.step-title:after {
width: 50%;
left: 50%;
}
div.step-line div.step-col.last div.step-title:after {
width: 50%;
right: 50%;
}
<div class="row step-line">
<div class="col-md-4 step-col first">
<div class="step-number">1</div>
<div class="step-title">This is a step title</div>
<div class="step-content">This is a description</div>
</div>
<div class="col-md-4 step-col">
<div class="step-number">2</div>
<div class="step-title">This is a step title</div>
<div class="step-content">This is a description</div>
</div>
<div class="col-md-4 step-col last">
<div class="step-number">3</div>
<div class="step-title">This is a step title</div>
<div class="step-content">This is a description</div>
</div>
</div>
What i understand from your question is, you want your lines to be behind those circles, just add background color background-color: white; in your CSS
Final code:
div.step-line div.step-number {
font-size: 26px;
border-radius: 50%!important;
display: inline-block;
margin: auto;
padding: 9px;
border: 3px solid #e5e5e5;
position: relative;
z-index: 5;
height: 60px;
width: 60px;
/*text-align: center;*/
background-color: white;
}

Scale text without breaking it to next line

I have a div which covers the entire page and has some text in it. I want that text to be big, center aligned and scale properly on different screen sizes without breaking the words to the next line. I want it be one single line. How do I do it?
#main {
position: relative;
width: 100%;
height: 100%;
text-align: center;
letter-spacing: 10px;
}
#main-text {
z-index: 1;
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 100%;
font-size: 50px;
text-align: center;
white-space: nowrap;
}
#name {
font-weight: 900;
}
#description {
font-weight: 400;
}
#arrow-downward {
z-index: 1;
position: fixed;
bottom: 25px;
left: 0;
right: 0;
margin: 0 auto;
width: 24px;
height: 24px;
text-align: center;
}
#arrow-downward:hover {
color: #777 !important;
cursor: pointer;
}
.material-icons .md-24 {
font-size: 24px;
}
<div id="main">
<div id="main-text">
<span id="name">Kaushal Shah</span> <span id="description">Cinematographer</span>
</div>
<div id="arrow-downward">
<i class="material-icons md-24">arrow_downward</i>
</div>
</div>
You can use vw as a unit to set the font size of the text, and this will make it resize according to screen width.
for example: font-size: 3.5vw; on #main-text will give you the result below
#main {
position: relative;
width: 100%;
height: 100%;
text-align: center;
letter-spacing: 10px;
}
#main-text {
z-index: 1;
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 100%;
font-size: 3.5vw;
text-align: center;
white-space: nowrap;
}
#name {
font-weight: 900;
}
#description {
font-weight: 400;
}
#arrow-downward {
z-index: 1;
position: fixed;
bottom: 25px;
left: 0;
right: 0;
margin: 0 auto;
width: 24px;
height: 24px;
text-align: center;
}
#arrow-downward:hover {
color: #777 !important;
cursor: pointer;
}
.material-icons .md-24 {
font-size: 24px;
}
<div id="main">
<div id="main-text">
<span id="name">Kaushal Shah</span> <span id="description">Cinematographer</span>
</div>
<div id="arrow-downward">
<i class="material-icons md-24">arrow_downward</i>
</div>
</div>

Text in hover element not centering when changing font size

So i'm trying to have a div with text appear on a parent div when a mouse hovers the parent, all was going well and good until I encountered a problem where the text ("VISIT") was no longer centering when the font size is changed to be larger.
.project-box {
width: 1000px;
background-color: white;
height: 350px;
margin: auto;
box-shadow: 0px 2px 5px 0px #737373;
}
.project-image {
width: 400px;
height: 260px;
margin-left: 30px;
background-color: #f1f1f0;
position: relative;
top: 50%;
transform: translateY(-50%);
cursor: pointer;
}
.slidein-content {
display: none;
background-color: #ff9933;
z-index: 1;
width: 400px;
height: 50px;
position: absolute;
bottom: 0;
text-align: center;
}
.project-image:hover .slidein-content {
display: block;
}
.visit {
font-family: 'Montserrat', sans-serif, Arial;
color: white;
letter-spacing: 1px;
font-size: 2em;
<div class="project-box">
<div class="project-image">
<div class="slidein-content">
<p class="visit">VISIT</p>
</div>
</div>
</div>
As you can see, the text "VISIT" is aligned properly horizontally, but not vertically. Anyone know a solution?
Try using a <span> element instead of a <p> element. So modify your code to this:
<div class="project-box">
<div class="project-image">
<div class="slidein-content">
<span class="visit">VISIT</span>
</div>
</div>
</div>
That should help center it or at least get you in the right direction. I tested this on jsfiddle here. You may need to play around with the margin or padding a bit, but the problem you're having is because of the <p> element.
Set a line-height=0 on .visit
.project-box {
width: 1000px;
background-color: white;
height: 350px;
margin: auto;
box-shadow: 0px 2px 5px 0px #737373;
}
.project-image {
width: 400px;
height: 260px;
margin-left: 30px;
background-color: #f1f1f0;
position: relative;
top: 50%;
transform: translateY(-50%);
cursor: pointer;
}
.slidein-content {
display: none;
background-color: #ff9933;
z-index: 1;
width: 400px;
height: 50px;
position: absolute;
bottom: 0;
text-align: center;
}
.project-image:hover .slidein-content {
display: block;
bottom:0;
}
.visit {
font-family: 'Montserrat', sans-serif, Arial;
color: white;
letter-spacing: 1px;
font-size: 2em;
line-height:0;
<div class="project-box">
<div class="project-image">
<div class="slidein-content">
<p class="visit">VISIT</p>
</div>
</div>
</div>
Add top:50%; and transform: translateY(-50%); to .slidein-content, erase the bottom:0 from it and add amargin: 0 to .visit (I don't know from where, but it has a 32px top- and bottom-margin, which you have to reset to 0 that way.)
.project-box {
width: 1000px;
background-color: white;
height: 350px;
margin: auto;
box-shadow: 0px 2px 5px 0px #737373;
}
.project-image {
width: 400px;
height: 260px;
margin-left: 30px;
background-color: #f1f1f0;
position: relative;
top: 50%;
transform: translateY(-50%);
cursor: pointer;
}
.slidein-content {
display: none;
background-color: #ff9933;
z-index: 1;
width: 400px;
height: 50px;
position: absolute;
top:50%;
transform: translateY(-50%);
text-align: center;
}
.project-image:hover .slidein-content {
display: block;
}
.visit {
font-family: 'Montserrat', sans-serif, Arial;
color: white;
letter-spacing: 1px;
font-size: 2em;
line-height: 2em;
margin: 0;
}
<div class="project-box">
<div class="project-image">
<div class="slidein-content">
<p class="visit">VISIT</p>
</div>
</div>
</div>