Getting DIVs same height and not covering each other - html

Here is my current code in JSfiddle
There are 4 Div's two that are side by side in the middle.
What I'm trying to do is get the two child divs to be the same height as the parent and show a white background.
Right now the bottom DIV is sitting on top of the two other ones in the middle and the background isn't white.
I've been messing with different display methods (table, flex, grid) but haven't found a working combination yet.
This is my HTML
<main>
<div class="full">
<div class="gbar"><span class="hb">Testing text</span>
</div>
<div class="txt">
<p>Testing text</p>
</div>
</div>
<div class="dialog">
<div class="left">
<div class="obar"><span class="hb">Testing text</span>
</div>
<div class="txt">
<p>Testing text</p>
<p>Testing text</p>
<p>Testing text</p>
<p>Testing text</p>
</div>
</div>
<div class="right">
<div class="bbar"><span class="hb">Testing text</span>
</div>
<div class="txt">
<p>Testing text</p>
<p>Testing text</p>
</div>
</div>
</div>
<div class="full">
<div class="ybar"><span class="hb">Testing text</span>
</div>
<div class="txt">
<p>Testing text</p>
</div>
</div>
This is the CSS part I'm trying to get working
.full {
display: inline-block;
position: relative;
margin-top: 10px;
display: inline-block;
width: 100%;
background-color: #fff;
}
.dialog {
display: block;
position: relative;
margin-top: 10px;
}
.left {
display: inline-block;
position: absolute;
width: 49%;
left: 0;
top: 0;
bottom: 0;
background-color: #fff;
}
.right {
display: inline-block;
position: absolute;
width: 49%;
right: 0;
top: 0;
bottom: 0;
background-color: #fff;
}

You can use flex
.dialog {
margin-top: 10px;
width: 100%;
display: flex;
}
.left {
flex: 1;
background-color: white;
}
.right{
flex: 1;
background-color: white;
}
https://jsfiddle.net/rnk44rtn/2/

Changed the middle row to tabel layout.
.dialog {
display: table;
position: relative;
margin-top: 10px;
width: 100%;
}
.left, .right {
background: #fff;
display: table-cell;
width: 50%;
}
body {
margin: 0;
padding: 0;
background-image: url("../img/bg.jpg");
background-repeat: repeat;
}
main {
display: block;
position: relative;
padding-top: 10px;
width: 950px;
margin: 0 auto;;
}
.full {
display: inline-block;
position: relative;
margin-top: 10px;
display: inline-block;
width: 100%;
}
.dialog {
display: table;
position: relative;
margin-top: 10px;
width: 100%;
}
.left, .right {
background: #fff;
display: table-cell;
width: 50%;
}
.bbar {
width: 100%;
background: linear-gradient(#4B4A5F, #6381D9);
}
.gbar {
width: 100%;
background: linear-gradient(#589288, #576A63);
}
.obar {
width: 100%;
background: linear-gradient(#C42D25, #EC694A);
}
.ybar {
width: 100%;
background: linear-gradient(#F85A4D, #EAC746);
}
.st {
display: inline-block;
font-size: 24px;
color: #fff;
padding: 6px;
}
.hb {
display: inline-block;
padding: 8px;
font-size: 18px;
color: #fff;
font-weight: bold;
text-shadow: 1px 1px 2px #000;
}
.txt {
padding: 8px;
color: #000;
background-color: #fff;
}
<main>
<div class="full">
<div class="gbar"><span class="hb">Testing text</span>
</div>
<div class="txt">
<p>Testing text</p>
</div>
</div>
<div class="dialog">
<div class="left">
<div class="obar"><span class="hb">Testing text</span>
</div>
<div class="txt">
<p>Testing text</p>
<p>Testing text</p>
<p>Testing text</p>
<p>Testing text</p>
</div>
</div>
<div class="right">
<div class="bbar"><span class="hb">Testing text</span>
</div>
<div class="txt">
<p>Testing text</p>
<p>Testing text</p>
</div>
</div>
</div>
<div class="full">
<div class="ybar"><span class="hb">Testing text</span>
</div>
<div class="txt">
<p>Testing text</p>
</div>
</div>
</main>
https://jsfiddle.net/afelixj/o3cm8jed/3/

Related

How align 2 super sub div of a sub div in a container div using HTML CSS

I have two queries in a single program.
query1:
I am trying to align two sub super sub divisions horizontally inside a sub div of a container div. Below is my code, could you please help me out with this. I have attached the desirable output.
query2:
and from the code you can see inside a circle there is a paragraph day, I wanted it to start from the center of the circle such as if the number of days is 1 it should be shown from the center and when there are 3 digit days it should be adjusted in the center. Hope you understand my queries.
.circle {
height: 50px;
width: 50px;
border-radius: 50%;
padding: 5%;
text-align: center;
border-color: black;
border-style: solid;
}
.container-meta {
position: relative;
}
.container-meta .left {
float: left;
}
.container-meta .right {
float: right;
}
.right p,
.left p {
padding: 0;
margin: 0;
}
<div class="container-meta">
<div class="left">
<div class="circle">
<p>days</p>
<p>hours</p>
</div>
<div class="date">
<p>today-date</p>
<p>tomorrow-date</p>
</div>
</div>
<div class="right">
<p>text1</p>
<p>text2</p>
<p>text3</p>
</div>
</div>
current output:
expected output:
You can do this by giving display:flex; to the left class and by giving some margin to one of divs.
.circle {
height: max-content;
width: max-content;
border-radius: 50%;
padding: 5%;
text-align: center;
border-color: black;
border-style: solid;
}
.container-meta {
position: relative;
}
.container-meta .left {
float: left;
display: flex;
}
.container-meta .right {
float: right;
}
.right p,
.left p {
padding: 0;
margin: 0;
width:max-content;
}
.date {
margin-left: 5px;
}
<div class="container-meta">
<div class="left">
<div class="circle">
<p>days</p>
<p>hours</p>
</div>
<div class="date">
<p>today-date</p>
<p>tomorrow-date</p>
</div>
</div>
<div class="right">
<p>text1</p>
<p>text2</p>
<p>text3</p>
</div>
</div>
Solution1.
I add display: flex at the .leftand margin-right: 10px at .circle.
.circle {
height: 50px;
width: 50px;
border-radius: 50%;
padding: 5%;
text-align: center;
border-color: black;
border-style: solid;
margin-right: 10px;
}
.container-meta {
position: relative;
}
.container-meta .left {
display: flex;
float: left;
}
.container-meta .right {
float: right;
}
.right p,
.left p {
padding: 0;
margin: 0;
}
<body>
<div class="container-meta">
<div class="left">
<div class="circle">
<p>days</p>
<p>hours</p>
</div>
<div class="date">
<p>today-date</p>
<p>tomorrow-date</p>
</div>
</div>
<div class="right">
<p>text1</p>
<p>text2</p>
<p>text3</p>
</div>
</div>
</body>
Solution2.
Using flex instead of float.
.circle {
height: 50px;
width: 50px;
border-radius: 50%;
padding: 5%;
text-align: center;
border-color: black;
border-style: solid;
margin-right: 10px;
}
.container-meta {
display: flex;
align-items: center;
justify-content: space-between;
}
.container-meta .left {
display: flex;
align-items: center;
flex-grow: 1;
}
.right p,
.left p {
padding: 0;
margin: 0;
}
<body>
<div class="container-meta">
<div class="left">
<div class="circle">
<p>days</p>
<p>hours</p>
</div>
<div class="date">
<p>today-date</p>
<p>tomorrow-date</p>
</div>
</div>
<div class="right">
<p>text1</p>
<p>text2</p>
<p>text3</p>
</div>
</div>
</body>

Positioning elements around element

I need to position elements on a side like in the image above and have onclick function on them to show the corresponding text. Any info on how to best achieve this to be responsive?
By responseive i mean that the dots and text should always stay on the same position relative to the size of the bottle.
What I did was to put everything inside the container div and then positioned the elements relative to that div and the bottle image absolute to the container div.
It kinda works when container div has fixed dimensions, but I guess there are better ways to do it.
EDIT: Added code! I suck at formatting, sorry.
<div class="bottle-one">
<div class="bottle-one-content">
<div class="bottle-one-image">
<div class="message">
<div class="message-hidden">
<div>
text
</div>
<div>
<img src="assets/images/icons/line_blue.svg" alt="">
</div>
</div>
<a href="#msg1" class="droplet droplet1 js-drop">
<img src="assets/images/icons/droplet.svg">
</a>
</div>
<div class="message">
<div class="message-hidden">
<div>
text
</div>
<div>
<img src="assets/images/icons/line_blue.svg" alt="">
</div>
<a href="#msg2" class="droplet droplet2 js-drop">
<img src="assets/images/icons/droplet.svg">
</a>
</div>
</div>
<div class="message">
<div class="message-hidden">
<div>
text
</div>
<div>
<img src="assets/images/icons/line_blue.svg" alt="">
</div>
<a href="#msg3" class="droplet droplet3 js-drop">
<img src="assets/images/icons/droplet.svg">
</a>
</div>
</div>
<div class="message">
<div class="message-hidden">
<div>
text
</div>
<div>
<img src="assets/images/icons/line_blue.svg" alt="">
</div>
<a href="#msg4" class="droplet droplet4 js-drop">
<img src="assets/images/icons/droplet.svg">
</a>
</div>
</div>
<img src="assets/images/bottle1.png" alt="" class="bottle-one-bottle">
</div>
</div>
.bottle-one {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 30%;
}
.bottle-one-image {
height: 100%;
position: relative;
width: 251px;
}
.message {
left: -340px;
top: 180px;
position: relative;
display: flex;
align-items: center;
justify-content: flex-end;
text-transform: uppercase;
font-size: .7rem;
color: #004197;
height: 30px;
width: 400px;
margin-bottom: 1rem;
}
.message-hidden {
display: flex;
}
.message-hidden div:nth-of-type(1) {
text-align: right;
font-family: 'BrandonGrotesqueWeb-Black', sans-serif;
letter-spacing: 2px;
border-right: 1px solid #004197;
width: 70%;
}
.message-hidden div:nth-of-type(2) {
width: 30%;
display: flex;
overflow:hidden;
}
I came up with this to help you with aligning your element to the left of a div.
By using a mix of [psuedo-elements] and floats, I think this gives you the desired effect you are looking for. Post your code and I'll be more then happy to help you with the other part.
html {
width: 550px;
border: none;;
}
body {
font-family: sans-serif;
color: rgba(0,0,0,.15);
height:200px;
}
body:after {
content: '';
display: block;
clear: both;
}
div {
position: relative;
}
div:after {
font-size: 200%;
position: absolute;
left: 0;
right: 0;
top: 0;
text-align: center;
}
.sibling {
border: 3px solid red;
height:200px;
}
.sibling.root:after {
content: 'Sibling';
color: green;
}
.float {
float: left;
border: 3px solid blue;
height: 90px;
width: 150px;
z-index: 1;
}
.float:after {
content: 'floated Element';
color: red;
}
.root {
overflow: hidden;
}
<div class="float">
</div>
<div class="sibling root">
</div>

How can I get rid of this space between body and div?

So I centered my text. But now there is a white space between body and the div. This is the HTML:
.parent-aligner {
background: #f2f2f2;
width: 100vw;
height: 500px;
text-align: center;
}
.parent-aligner .aligner {
display: table-cell;
height: inherit;
width: inherit;
vertical-align: middle;
}
<div class="container-fluid">
<div class="parallax">
<div class="parent-aligner">
<div class="aligner">
<p class="textcontent">lorem ipsum text</p>
</div>
</div>
</div>
</div>
I think what causes this is the width: 100vw;. But when I change it to width:100%; the text isn't centered anymore. Any suggestions on how to fix this?
Deduct the width of the scrollbar from the viewport width for smaller screen sizes...
EDIT: Add max-width property.
(And also remove the margin on body)
body {
margin: 0;
}
.parent-aligner {
background: #f2f2f2;
width: 100vw;
max-width: 100%;
height: 500px;
text-align: center;
}
.parent-aligner .aligner {
display: table-cell;
height: inherit;
width: inherit;
vertical-align: middle;
}
<div class="container-fluid">
<div class="parallax">
<div class="parent-aligner">
<div class="aligner">
<p class="textcontent">lorem ipsum text</p>
</div>
</div>
</div>
</div>
try this
.parent-aligner {
background: #f2f2f2;
width: 100%;
height: 500px;
text-align: center;
display:table;
}
.parent-aligner .aligner {
display: table-cell;
height: inherit;
width: inherit;
vertical-align: middle;
}
<div class="container-fluid">
<div class="parallax">
<div class="parent-aligner">
<div class="aligner">
<p class="textcontent">lorem ipsum text</p>
</div>
</div>
</div>
</div>

Align 6 divs content vertical

How would i align all these 6 divs vertically in a 3x3 pattern so that the top and bottom divs content are aligned with each other so it looks good. i've tried some vertical-align: middle; with no sucess.
It's a must to be 100% responsive and that the number also is centered and aligned so whatever number gets there is aligned.
.top-right-container {
position: absolute;
border: 1px solid white;
height: 20%;
width: 50%;
right: 0;
top: 0;
}
.stats-container {
position: relative;
float: left;
border: 1px solid white;
width: 75%;
height: 80%;
}
.Agility,
.Stamina,
.Respect,
.Intelligence,
.Strength,
.Cash {
display: inline-block;
color: black;
}
.Agility,
.Intelligence {
float: left;
margin-left: 10%;
}
.Stamina,
.Strength {
margin: 0 auto;
}
.Respect,
.Cash {
margin-right: 10%;
float: right;
}
.stats-container h2 {
font-family: Marker-Felt;
margin: 0;
font-size: calc(0.7vh + 1.2vw);
}
.stats-container p {
margin: 5%;
text-align: center;
font-size: calc(0.5vh + 0.8vw);
}
.top-stats,
.bottom-stats {
width: 100%;
text-align: center;
}
<div class="top-right-container">
<div class="stats-container">
<div class="top-stats">
<div class="Agility">
<h2>Agility</h2>
<p>10</p>
</div>
<div class="Stamina">
<h2>Stamina</h2>
<p>10</p>
</div>
<div class="Respect">
<h2>Respect</h2>
<p>10</p>
</div>
</div>
<div class="bottom-stats">
<div class="Intelligence">
<h2>Intelligence</h2>
<p>10</p>
</div>
<div class="Strength">
<h2>Strength</h2>
<p>10</p>
</div>
<div class="Cash">
<h2>Cash</h2>
<p>10</p>
</div>
</div>
</div>
</div>
You can do it with the Flexbox:
* {margin:0;padding:0;box-sizing:border-box}
html, body {width:100%}
.stats-container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
}
.top-stats,
.bottom-stats {
display: flex;
width: 100%;
text-align: center;
}
.Agility,
.Stamina,
.Respect,
.Intelligence,
.Strength,
.Cash {
flex: 1;
}
.stats-container h2 {
font-size: calc(0.7vh + 1.2vw);
}
.stats-container p {
font-size: calc(0.5vh + 0.8vw);
}
<div class="top-right-container">
<div class="stats-container">
<div class="top-stats">
<div class="Agility">
<h2>Agility</h2>
<p>10</p>
</div>
<div class="Stamina">
<h2>Stamina</h2>
<p>10</p>
</div>
<div class="Respect">
<h2>Respect</h2>
<p>10</p>
</div>
</div>
<div class="bottom-stats">
<div class="Intelligence">
<h2>Intelligence</h2>
<p>10</p>
</div>
<div class="Strength">
<h2>Strength</h2>
<p>10</p>
</div>
<div class="Cash">
<h2>Cash</h2>
<p>10</p>
</div>
</div>
</div>
</div>
responsive 2 rows and 6 boxes
Here is some code you can work with.
The container of all the divs .container will take 100% of the page eg. its <body> .
The rows .statRow will take 100% of its parent the container.
Now the boxes .box will take 33% of its parent width.
Then adding 3 of these boxes 33%+33%+33% will take up 99% of the container.
Additionally borders usually take up more space so width + border is its actual width.
This is fixed with chancing the elements box-sizing to border-box.
.container {
border: 10px solid black;
width: 100%;
box-sizing: border-box;
border-radius: 5px;
}
.statRow {
width: 100%;
display: block;
}
.box {
color: white;
display: inline-block;
text-align: center;
width: 33%;
border: 10px solid white;
box-sizing: border-box;
border-radius: 15px;
background-color: #222;
}
<div class="container">
<div class="statBubble">
<div class="box">
<h5>Agility</h5>
<p>10</p>
</div><!--
--><div class="box">
<h5>Strength</h5>
<p>10</p>
</div><!--
--><div class="box">
<h5>Stat</h5>
<p>number</p>
</div>
</div>
<div class="statRow">
<div class="box">
<h5>Wisdom</h5>
<p>100</p>
</div><!--
--><div class="box">
<h5>Stat</h5>
<p>number</p>
</div><!--
--><div class="box">
<h5>Stat</h5>
<p>number</p>
</div>
</div>
</div>

How to keep a specific element in the middle?

I have a row of elements, but one of them, which is in the middle, should be centered. Try to run this simple snippet, the "Must be in the middle" thing is not in the middle, but I would like it to be, despite the sizes of things around it. The "text-align:center" won't help, because it puts the entire list of elements in the middle and it's not aware that I want the "the-middle" thing to be in the middle:
.the-whole {
width: 100%;
text-align: center;
}
.side-thing {
display: inline-block;
margin: 8px;
}
.the-center {
display: inline-block;
font-weight: bold;
}
<div class="the-whole">
<div class="side-thing">
long thing at left
</div>
<div class="side-thing">
a
</div>
<div class="side-thing">
b
</div>
<div class="the-center">
(Must be in the Middle)
</div>
<div class="side-thing">
c
</div>
<div class="side-thing">
d
</div>
</div>
If you can change HTML, than you can move left and right elements inside centered one:
.the-whole {
width: 100%;
text-align: center;
}
.side-thing {
display: inline-block;
}
.the-center {
display: inline-block;
position: relative;
margin: 8px;
padding: 0 10px;
}
.the-center span {
font-weight: bold;
}
.left {
position: absolute;
white-space: nowrap;
right: 100%;
top: 0;
}
.right {
position: absolute;
white-space: nowrap;
left: 100%;
top: 0;
}
<div class="the-whole">
<div class="the-center">
<div class="left">
<div class="side-thing">
long thing at left
</div>
<div class="side-thing">
a
</div>
<div class="side-thing">
b
</div>
</div>
<span>(Must be in the Middle)</span>
<div class="right">
<div class="side-thing">
c
</div>
<div class="side-thing">
d
</div>
</div>
</div>
</div>
Solution using display:flex.
.the-whole {
display: flex;
}
.the-whole div {
display: inline;
}
.the-whole > div {
flex: 1;
border: 1px solid green;
}
.the-whole > div.center {
text-align: center;
}
<div class="the-whole">
<div class="left">
<div>
long thing at left
</div>
<div>
a
</div>
<div>
b
</div>
</div>
<div class="center">
<div>
(Must be in the Middle)
</div>
</div>
<div class="right">
<div>
c
</div>
<div>
d
</div>
</div>
</div>
You can use flexbox:
.the-whole {
display: flex;
}
.side {
flex: 1; /* Distribute remaining width equally among the left and right parts */
}
.the-left {
text-align: right;
}
.the-right {
text-align: left;
}
.side-thing {
display: inline-block;
margin: 0 8px;
}
.the-center {
font-weight: bold;
}
<div class="the-whole">
<div class="the-left side">
<div class="side-thing">long thing at left</div>
<div class="side-thing">a</div>
<div class="side-thing">b</div>
</div>
<div class="the-center">(Must be in the Middle)</div>
<div class="the-right side">
<div class="side-thing">c</div>
<div class="side-thing">d</div>
</div>
</div>
I think it's better to insert a new div. So you will have seven. only One in the center.
#page{
width: 100%;
text-align: center;
}
.the-whole {
width: 39%;
display: inline-block;
text-align: center;
}
.side-thing {
min-width: 10%;
display: inline-block;
text-align: center;
margin: 0px;
border: 0.1em solid red;
}
.side-thing-left{
min-width: 40%;
display: inline-block;
text-align: center;
margin: 8px;
border: 0.1em solid red;
}
.the-center {
width: 20%;
display: inline-block;
font-weight: bold;
border: 0.1em solid green;
}
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<id id="page">
<div class="the-whole">
<div class="side-thing-left">left</div>
<div class="side-thing">a</div>
<div class="side-thing">b</div>
</div>
<div class="the-center">(Must be in the Middle)</div>
<div class="the-whole">
<div class="side-thing-left">left</div>
<div class="side-thing">c</div>
<div class="side-thing">d</div>
</div>
</div>
</body>
</html>
Is this a solution?
.the-whole {
width: 100%;
text-align: center;
}
.side-thing {
float: left;
margin: 8px;
}
.the-center {
float: left;
font-weight: bold;
margin: 0 auto;
}