What is the right way to make this layout working? - css

What seemed to be a simple task turned out to be quite a problem. I am trying to find a way to both preserve the vertical alignment of green DIVs and to prevent the absolute positioned DIV from overlapping the contents that follows.
Since I had to use absolute positioning not to destroy the alignment, I am now looking for a solution to another problem that showed up as a consequence.
Here is the code:
body {
background-color: #ddd;
}
h1 {
color: #FFFFFF;
background-color: #0000FF;
padding: 5px;
}
#container {
height: 100%;
width: 100%;
display: table;
}
#inner {
vertical-align: middle;
display: table-cell;
position: relative;
}
#inner2 {
vertical-align: middle;
display: table-cell;
}
#gauge_div {
width: 240px;
height: 240px;
margin: 0 auto;
background-color: green;
}
#gauge2_div {
width: 240px;
height: 240px;
margin: 0 auto;
background-color: green;
}
#heading {
width: 100%;
margin: 0 auto;
text-align: center;
color: blue;
}
#below {
margin: 0 20px;
text-align: center;
color: blue;
clear: both;
}
.graph {
margin: 0 auto;
padding: 10px 0;
text-align: center;
color: blue;
border: thin solid #00F;
}
#container_main {
padding-right: 100px;
padding-left: 100px;
}
#thermometer {
margin: 0 auto;
padding: 10px 0px 10px 0;
background-color: gray;
}
#thermometer2 {
margin: 0 auto;
padding: 10px 20px 10px 0;
background-color: gray;
}
.below_gauge {
font-weight: bold;
color: blue;
}
.below_container {
position: absolute;
left: 0;
right: 0;
}
.below_gauge2 {
width: 240px;
color: blue;
position: relative;
margin: auto;
}
.below_gauge3 {
width: 240px;
color: blue;
position: relative;
margin: auto;
border: thin solid #F00;
}
<div id="container_main">
<div id="heading"><h1>The title</h1></div>
<div class="graph">
<div id="container">
<div id="inner">
<div id="gauge_div"></div>
<div class="below_gauge">Text #1</div>
<div class="below_container">
<div class="below_gauge2">Here I would like to display some text but would not like the left square to be misaligned with the right one. That has been solved.</div>
<div class="below_gauge3">I do not want the contents of this DIV to overlap the contents below. This DIV can contain any ammount of text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.</div>
</div>
</div>
<div id="thermometer">
<canvas id="termometar_cnv" width="160" height="600"></canvas>
</div>
<div id="inner2">
<div id="gauge2_div"></div>
<div class="below_gauge">Text #2</div>
</div>
<div id="thermometer2">
<canvas id="termometar2_cnv" width="160" height="600"></canvas>
</div>
</div>
<div id="below">Is there a way to make the DIV with the red border to push down this DIV so the DIV with the red border would not overlap what is below?
</div>
</div>
</div>
I made this code based on the answer (that I accepted) to my question when I had problems with how to allign two green DIVs. As can be seen the solution was to use absolute positioning but now that caused a problem because every absolute positioned element is according to CSS specification removed from the flow.

Try once Left-margin and right-margin.

Related

How to best make curved edges of Divs outside of the functionality of border-radius? [duplicate]

This question already has an answer here:
How to create uneven rounded sides on a div?
(1 answer)
Closed 10 months ago.
I'm trying to create a web element like this, but am having trouble figuring out how to make a curved border between two divs. I understand the functionality of border-radius (very bad implementation in codepen below), bit wanted to see if anyone had ideas on how to implement the picture above? I thought about having a border-radius with a much larger radius, then hiding overflow, but not sure if that makes sense.
https://codepen.io/unsure-of-name/pen/LYeBdbX
.circle {
height: 100px;
width: 100px;
background-color: #eee;
border-radius: 100px;
box-shadow: 0 0px 8px 0 rgba(0, 0, 0, 0.2), 0 0px 20px 0 rgba(0, 0, 0, 0.19);
display: inline-block;
vertical-align: top;
position: relative;
z-index: 2;
}
.bar {
display: inline-block;
margin-top: 25px;
background-color: #eee;
margin-left: -50px;
padding-left: 50px;
height: 50px;
text-align: center;
positive: relative;
z-index: 1;
}
.bar div:nth-child(1) {
background-color: red;
border-radius: 10px;
}
.bar div:nth-child(2) {
background-color: #bbb;
}
.bar div:nth-child(3),
.bar div:nth-child(4) {
background-color: #eee;
border-right: 1px solid black;
}
.bar div {
display: inline-block;
vertical-align: middle;
text-align: center;
line-height: 50px;
}
.row {
}
.row > div {
}
<div class='container'>
<div class='row'>
<div class='circle'>
</div>
<div class='bar'>
<div>
Group 1
</div>
<div>
Description
</div>
<div>
Cell 1
</div>
<div>
Cell 2
</div>
</div>
</div>
<div class='row'>
<div class='circle'>
</div>
<div class='bar'>
<div>
Group 1
</div>
<div>
Description
</div>
<div>
Cell 1
</div>
<div>
Cell 2
</div>
</div>
</div>
</div>
Thanks!
That's some very confusing css you have written. The css below will get you what you want. You still have to organize the rest of it. Hope this helps.
.row{
display: flex;
align-items: center;
}
.bar {
display: inline-block;
background-color: #eee;
margin-left: -50px;
padding-left: 50px;
height: 50px;
display: flex;
text-align: center;
positive: relative;
z-index: 1;
}
.bar div{
padding: 0 10px;
width: 100px;
}
.bar div:nth-child(1) {
position: relative;
background: red;
color: black;
height: 50px;
}
.bar div:nth-child(1)::before{
content: '';
width: 20px;
height: 100%;
position: absolute;
bottom: 0;
right: -5px;
background: red;
border-radius: 100%;
}
You can try using ellipse to define the how 'curvy' the side should look
#box1 {
background: red;
width: 10rem;
height: 3rem;
padding: 0.5rem;
clip-path: ellipse(10rem 7.5rem at left);
}
.wrapper {
background: blue;
width: 20rem;
}
<div class="wrapper">
<div id="box1">
</div>
</div>

How to position DIV without destroying the vertical alignment?

I've been struggling with this for hours and cannot find the solution. I've made a simple layout to display two pairs of gauge+thermometer visualizations to show the temperatures uploaded by ESP8266. The basic layout is:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>The title</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container_main">
<div id="heading"><h1>The title</h1></div>
<div class="graph">
<div id="container">
<div id="inner">
<div id="gauge_div"></div>
<div class="below_gauge">Text #1</div>
<div class="below_gauge2">Here I would like to display some text but would not like the left square to be misaligned with the right one.</div>
</div>
<div id="thermometer">
<canvas id="termometar_cnv" width="160" height="600"></canvas>
</div>
<div id="inner2">
<div id="gauge2_div"></div>
<div class="below_gauge">Text #2</div>
</div>
<div id="thermometer2">
<canvas id="termometar2_cnv" width="160" height="600"></canvas>
</div>
</div>
<div id="below">Description.
</div>
</div>
</div>
</body>
</html>
body {
background-color: #ddd;
}
h1 {
color: #FFFFFF;
background-color: #0000FF;
padding: 5px;
}
#container {
height: 100%;
width: 100%;
display: table;
}
#inner {
vertical-align: middle;
display: table-cell;
}
#inner2 {
vertical-align: middle;
display: table-cell;
}
#gauge_div {
width: 240px;
height: 240px;
margin: 0 auto;
background-color: green;
}
#gauge2_div {
width: 240px;
height: 240px;
margin: 0 auto;
background-color: green;
}
#heading {
width: 100%;
margin: 0 auto;
text-align: center;
color: blue;
}
#below {
margin: 0 20px;
text-align: center;
color: blue;
}
.graph {
margin: 0 auto;
padding: 10px 0;
text-align: center;
color: blue;
border: thin solid #00F;
}
#container_main {
padding-right: 100px;
padding-left: 100px;
}
#thermometer {
margin: 0 auto;
padding: 10px 0px 10px 0;
background-color: gray;
}
#thermometer2 {
margin: 0 auto;
padding: 10px 20px 10px 0;
background-color: gray;
}
.below_gauge {
font-weight: bold;
color: blue;
}
.below_gauge2 {
width: 240px;
margin: 0 auto;
color: blue;
}
When <div class="below_gauge2"> is removed from the HTML the layout is exactly how I would like it to be. However, after adding that DIV, the green div moves up so it is not anymore vertically aligned with the second green div at the right.
What can be done so <div class="below_gauge2"> would be displayed below the left green DIV, but in a such way the green DIV would stay where it was before adding the <div class="below_gauge2">?
check this fiddle
#inner {
vertical-align: middle;
display: table-cell;
//added
position: relative;
}
.below_gauge2 {
width: 240px;
margin: 0 auto;
color: blue;
//added
position: absolute;
left: 0;
right: 0;
margin: auto;
}

Creating Nested Divs

I'm having trouble with creating a nested divs like in the attached image.
Image
I would love if some one can show me how.
.demo-container {
padding: 30px;
border: 1px solid #e2e4e7;
background-color: #f5f7f8;
text-align: left;
display: inline-block;
vertical-align: top;
}
.header {
display: block;
padding: 15px 25px 0;
overflow: hidden;
}
<div id="warp">
<div class="header">
New Alerts
</div>
<div class="demo-container">
</div>
</div>
You need to set height and width to your parent #wrap , see full snippet below:
snippet
* {
box-sizing: border-box
}
#wrap {
height: 200px;
width: 200px;
text-align: center;
}
.header {
display: block;
padding: 15px 25px;
background: blue;
color: white;
}
.demo-container {
width: 100%;
padding: 30px;
border: 1px solid #e2e4e7;
background-color: #f5f7f8;
display: inline-block;
vertical-align: middle;
color:black;
}
<div id="wrap">
<div class="header">
New Alerts
</div>
<div class="demo-container">
X Alerts
</div>
</div>

box-shadow should appear inside border on right hand side

I am trying to achieve the box-shadow inside the right-border, currently everything is working fine except the shadow is getting display outside the right border. Following is the js-fiddle sample code I have tried...
http://jsfiddle.net/5y1guk6d/1/
HTML:
<div class="header">
<div class="header-bar">
<h1 class="title">Page title</h1>
</div>
</div>
<div class="main">
<div class="left-bar">
<div class="menu">
Menu Content
</div>
</div>
<div class="content">
Main content area
</div>
</div>
CSS:
.header {
width: 100%;
height: 40px;
top: 0;
color: white;
}
.header-bar {
height: 100%;
overflow: hidden;
background-color: #009BE1;
}
h1.title {
display: inline-block;
font: bold 16px Arial, sans-serif;
margin: 0 5px 0 15px;
position: relative;
top: 25%;
}
.main {
width: 100%;
overflow: hidden;
position: absolute;
top: 48px;
bottom: 0;
}
/* left bar */
.left-bar {
width: 160px;
float: left;
padding:10px;
background-color: #F0F0F0;
height: 100%;
position: relative;
border-right:1px solid #aaa;
box-shadow:5px 0 5px #ccc;
}
.content {
overflow: hidden;
left: 12px;
padding: 5px 17px 5px 5px;
height: 100%;
position: relative;
}
Appreciated your help..
If you want the box shadow to appear inside of the element instead of outside, use inset. Then you want to invert the x-offset so it appears on the right side.
box-shadow:inset -5px 0 5px #ccc;
http://jsfiddle.net/5y1guk6d/3/

How to align a variable-height div next to a fixed-height div?

In my HTML I'm trying to align a Title next to the title's Bullet, so that the first line of the title always is next to the bullet, and the second line (if any) doesn't change the title's position - it just trails to the next line.
JSFiddle:
http://jsfiddle.net/Ebqq8/
HML:
<div class="bullet-container">
<div class="bullet-title-container">
<div class="circle-container">
<div class="circle"></div>
</div>
<p class="bullet-title">Short Title</p>
</div>
<div class="bullet-details-container">
<p>Body Text</p>
</div>
</div>
CSS:
.circle-container {
height: 34px;
display: inline-block;
position: relative;
width: 14px;
border: 1px solid blue;
}
.circle {
border-radius: 50% !important;
width: 12px;
height: 12px;
background-color: red;
display: inline-block;
position: absolute;
top: 0px;
/* width and height can be anything, as long as they're equal */
}
.bullet-title {
display: inline-block;
font-size: 16px;
font-weight: bold;
margin-left: 10px;
min-height: 34px;
width: 200px;
margin: 0px;
}
.bullet-title-container {
color: black;
display: inline-block;
position: relative;
width: 250px;
}
.bullet-details-container {
color: black;
}
.bullet-container {
max-width: 600px;
float: left;
text-align: left;
}
What's happening now is that the first line is always too low, and if there are multiple lines, the whole title gets pushed up too high. I thought that aligning two inline-block elements would do the trick, but it doesn't seem to be working. What am I doing wrong?
You could try adding:
position: absolute;
top: 0;
to .bullet-title { }
http://jsfiddle.net/Ebqq8/2/

Resources