How to link between circles with a dash line from the center? - html

I have 3 circles in a row and I want to link between them from the center with a dash line, Here is a screenshot similar to what I want:
Here is the html code:
<div class="container-fluid">
<div class="row">
<div class="col-xs-push-3 col-xs-6 text-center">
<div class="col-xs-3">
<div class="wrapper">
<span class="circle text-center">A</span>
<span class="dash_line" style="transform: translate(232%, -215%);">---</span>
</div> <!-- wrapper -->
</div> <!-- col-xs-3 -->
<div class="col-xs-6">
<div class="wrapper">
<!--<span class="dash_line">---</span>-->
<span class="circle text-center">B</span>
<!--<span class="dash_line">---</span>-->
</div> <!-- wrapper -->
</div> <!-- col-xs-6 -->
<div class="col-xs-3">
<div class="wrapper">
<span style=" transform: translate(-114%, 135%);" class="dash_line">-----</span>
<span class="circle text-center">C</span>
</div> <!-- wrapper -->
</div> <!-- col-xs-3 -->
</div> <!-- col-xs-6 -->
</div> <!-- row -->
</div> <!-- container-fluid -->
Here is the custom CSS:
.row{
margin:5% auto
}
.circle {
border-radius: 50%;
border: 1px solid #d1cfc8;
background-color: #f7eebe;
padding: 15% 35%;
font-size: 300%;
display: inline-block
}
.dash_line{
position: absolute;
transform: translateY(50%);
}
Here is a fiddle to see it live:
http://jsfiddle.net/mpvf5rxa/37
As you see i'm using specific values for each dash line, I want it to be dynamic.
I don't mind changing the elements, Adding/removing elements.
Also I don't mind using Javascript/Jquery to achieve that.

Edit, since you use bootstrap 3 , another approach with pseudo and margins could be used instead:
.ABC {
text-align: center;
}
.ABC span {
padding: 1vw 2.8vw; /* any values of yours */
font-size: 5vw; /* any values of yours */
border: 1px solid; /* any values of yours */
border-radius: 50%;
display: inline-block;/* to trigger block formatting context .vertical padding + pseudo */
}
span + span /* filter out first span */{
margin-left:5vw;/* equals width of dashed line */
}
span + span::before {/* do not draw anything from first span */
content:'';
display:inline-block;
vertical-align:middle;
margin-left:-7.8vw;
margin-right:2.8vw;/* equal span padding*/
width:5vw;
border-top:dashed;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row ABC">
<span>A</span>
<span>B</span>
<span>C</span>
</div>
</div>
Original answers thinking bootsrap 4 was involved .
If you have only 3 elements to separate with a dashed line, you can use pseudos, order, built-in bootsrap class and much less markup:
here i added the ABC class to easily select this row, but you can use any other class or id.
.ABC span {
padding:1vw 2.8vw;/* any values of yours */
font-size:5vw;/* any values of yours */
border:1px solid;/* any values of yours */
border-radius:50%;
order:0;/* defaut*/
}
.ABC span + span {
order:2;/* leave order:1 for one pseudo */
}
.ABC span:last-of-type {
order:4;/* leave order:3 for the other pseudo */
}
.ABC:before,
.ABC:after {
content:'';
width:5vw;/* whatever size you need */
order:1;
border-top:dashed;
}
.ABC:after {
order:3;
}
.ABC:after {
order: 3;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet"/>
<div class="container">
<div class="row justify-content-center align-items-center ABC">
<span>A</span>
<span>B</span>
<span>C</span>
</div>
</div>

I'd certainly look into using Grid or Flex for this.
Here's a rough example I built with flex that could hopefully meet your needs with a few modifications!
http://jsfiddle.net/kh2q6vo7/7/
.container {
border: 1px solid black;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 200px;
}
.a {
width: 50px;
height: 100px;
margin-right: 10px;
border: 1px solid red;
}
.b {
width: 75px;
height: 60px;
margin-right: 10px;
border: 1px solid blue;
}
.c {
width: 100px;
height: 25px;
border: 1px solid green;
}
.line--right {
position: relative;
}
.line--right:after {
content: "";
display: block;
width: 10px;
height: 1px;
background: black;
position: absolute;
right: -11px;
top: 50%;
}
<div class="container">
<div class="a line--right">A</div>
<div class="b line--right">B</div>
<div class="c">C</div>
</div>
You would want to change the elements to meet your needs. Container size, line size, even position and shape could change. Etc...
But with display: flex; You are able to center your elements vertically within a container. Allowing them to match up in the middle!
More References:
https://hackernoon.com/the-ultimate-css-battle-grid-vs-flexbox-d40da0449faf
https://rachelandrew.co.uk/archives/2016/03/30/should-i-use-grid-or-flexbox/

Related

Center parent div vertically based on child element

I am hoping to center my parent div height based on my child div height. My goal is to have 3 boxes with a shorter, but wider rectangle centered vertically behind it. Right now I have my parent div shorter and wider than the children, however I cannot seem to center it vertically.
Here is the ideal outcome:
Here is my current version (Please ignore minor differences with text and box colors). :
.content {
width: 80%;
margin: 0px auto;
}
#container .col {
border: 1px solid #00acd4;
background-color: white;
padding-top: 2em;
padding-bottom: 2em;
position: relative;
}
#parent {
background-color: #f0f9fb;
max-height: 80px;
}
#container {
margin-top: 50px;
margin-bottom: 50px;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<div id="container">
<div id="parent">
<div class="content">
<div class="row">
<div class="col ">
<h3>$500</h3>
</div>
<div class="offset-1 col">
<h3>$3500</h3>
</div>
<div class="col offset-1">
<h3>50%</h3>
</div>
</div>
</div>
</div>
</div>
Don't use a negative margin unless absolutely necessary. In this case, it is not. Use flex on parent with align-items: center;
.content {
width: 80%;
margin: 0px auto;
}
#container .col {
border: 1px solid #00acd4;
background-color: white;
padding-top: 2em;
padding-bottom: 2em;
position: relative;
}
#parent {
background-color: #f0f9fb;
max-height: 80px;
display: flex;
align-items: center;
}
#container {
margin-top: 50px;
margin-bottom: 50px;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<div id="container">
<div id="parent">
<div class="content">
<div class="row">
<div class="col ">
<h3>$500</h3>
</div>
<div class="offset-1 col">
<h3>$3500</h3>
</div>
<div class="col offset-1">
<h3>50%</h3>
</div>
</div>
</div>
</div>
</div>
Without a sketch of what you are trying to do, I believe this is what you are wanting... You can just set a negative margin in the col divs in order to take them outside of the parent...
#container {
margin-top: 50px;
margin-bottom: 50px;
}
#parent {
background-color: #f0f9fb;
}
.content {
width: 80%;
margin: 0px auto;
}
#container .col {
border: 1px solid #00acd4;
background-color: white;
padding-top: 2em;
padding-bottom: 2em;
position: relative;
margin-top: -20px;
margin-bottom: -20px;
}
<div id="container">
<div id="parent">
<div class="content">
<div class="row">
<div class="col">
<h3>$500</h3>
</div>
<div class="offset-1 col">
<h3>$3500</h3>
</div>
<div class="col offset-1">
<h3>50%</h3>
</div>
</div>
</div>
</div>
</div>
Forked your fiddle: https://jsfiddle.net/jstgermain/o6xhL92s/
*** RECOMMEND BELOW SOLUTION ***
#Betsy, I would recommend simplifying your HTML and using flexbox over the previous solution to your fiddle. You will want to make sure your behavior is consistent across browsers and devices. You can use media queries to change the size to eht col items for smaller devices.
#container {
margin-top: 50px;
margin-bottom: 50px;
}
#parent {
background-color: red;
/*#f0f9fb;*/
display: flex;
justify-content: space-evenly;
}
.col {
border: 1px solid #00acd4;
background-color: white;
padding: 1em;
width: 25%;
margin: -20px auto;
}
<div id="container">
<div id="parent">
<div class="col">
<h3>$500</h3>
</div>
<div class="col">
<h3>$3500</h3>
</div>
<div class="col">
<h3>50%</h3>
</div>
</div>
</div>

How can I set height higher than 100% in a flexbox flex-column class div?

I have created a grid with bootstrap, and in one of the columns I would like to have a grid of divs. Every div should become bigger on hover, and should go over surrounding ones.
Divs have images and text inside. There should be 3 divs on mobile (one above the other, single div in every 'row') ,and 3 'rows' with 3 divs inline on bigger screens. I have achieved that by putting following classes on a bootstrap div that contains previously mentioned: col d-flex flex-column flex-md-row.
<div class="container">
<div class="row">
<div class="col-lg-3">
<p>Place for some other content</p>
</div>
<div class="col-lg-9 ">
<div class="row">
<div class="col d-flex flex-column flex-md-row justify-content-
around">
<div class="image-container">
<div class="left">
<img src="./img/flag.png" alt="">
</div>
<div class="main">
<img src="some image" alt="">
<p>Some text</p>
</div>
<div class="lower">
<button class="btn">Link me</button>
</div>
</div>
/* two more .image-container divs */
</div>
</div>
/* two more times the same: div.row, div.col.d-flex etc.*/
</div>
</div>
</div>
One major point is this: every div with image has two hidden divs on the sides, so when you hover over the div - the div kindda expands (hidden divs get the display: block), AND its content goes over divs on the left and bottom (I have set z-index) without moving those surrounding divs.
Everything works as I wanted, EXCEPT on the mobile where I have set flex-column direction. There divs simply don't expand towards bottom, only on the left. The hidden div on the bottom shows on hover INSIDE the parent, instead bellow and above the following lower positioned element.
SCSS:
.col-lg-3 {
display: none;
#media only screen and (min-width: 992px) {
display: flex;
}
}
.image-container {
margin:15px;
width: 250px;
position: relative;
.main {
padding: 0 10px;
border: 1px solid black;
}
.lower {
display: none;
position: absolute;
background-color: white;
bottom: 0;
right: 0;
width: 100%;
height: 21%;
border: 1px solid black;
border-top: none;
padding: 0 10%;
button {
width: 100%;
background-color: orange;
color: white;
}
}
.left {
display: none;
position: absolute;
background-color: gray;
left: -50px;
top: 0;
height: 100%;
width: 50px;
border: 1px solid black;
border-right: none;
img {
width: 50%;
margin: auto;
}
}
&:hover {
z-index:1;
height: 115%;
.lower, .left {
display: block;
}
}
}
Why is that happening, and how can I make it work the way I intended.
Also, I would be very happy to hear if you have suggestions about other possible solutions for creating these get-bigger-on-hover divs.
If I understood your question correctly, are you looking to increase the size of the tile in-place without affecting the layout of other. If yes, then I have created a small fiddle HERE.
This uses flexbox and scale transformation to increase the size of tile in-place.
.container {
width: 600px;
height: 400px;
background-color: #eee;
border: 1px solid #aaa;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.tile {
border: 1px solid #888;
height: 190px;
width: 190px;
}
.tile:hover {
transform: scale(1.3);
}
<div class="container">
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
</div>
A better approach would be to use CSS grids. It will allow you to evenly space out tiles around your workspace.

center vertically div inside bootstrap grid

I would center a div inside another div vertically.
I have tried using table cell as mentioned in some answers in the site but that does not work I always get the div in top
CSS
.height1 {
height:60px;
line-height:60px
}
.row {
border: 1px solid black;
}
.indicator {
width :20px;
height:20px;
background-color: black;
vertical-align: middle
}
.badge {
display:inline-block;
}
.parent {
display: table-cell;
}
HTML
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-md-8 height1"> TEXTE</div>
<div class="col-md-4 parent">
<div class="badge indicator">testing</div>
</div>
</div>
</div>
Here's a demo
See the updated snippet below.
.height1, .parent {
line-height:60px
}
.row {
border: 1px solid black;
}
.indicator {
height:20px;
background-color: black;
vertical-align: middle
}
.badge {
display:inline-block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-xs-8 col-md-8 height1"> TEXTE</div>
<div class="col-xs-4 col-md-4 parent">
<div class="badge indicator">testing</div>
</div>
</div>
</div>
HTML
<div class="parent">
<div class="child"></div>
</div>
By using the following method you can get that approach. And it will be better solution to maintain the div's.
.parent {
width: 100px;
height: 100px;
background-color: yellow;
position: relative;
}
.child {
height: 50px;
width: 50px;
background-color: blue;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}

Display 2 div in block and vertical div beside them

I am trying to design a section which 3 image. I can get the two images to display by block easily. I can float the third image to the right and adjust the height easily. However my issue is it does not align side by side.Below is an example of what I am trying to achieve
This is an example of what I have so far
.image-one,
.image-two {
width: 250px;
background-color: green;
display: block;
margin-top: 10px;
}
.image-three {
float: right;
background-color: lightblue;
width: 250px;
height: 200px;
}
<div class="container">
<div class="image-one">Hello</div>
<div class="image-two">Image two</div>
<div class="image-three"> Image three </div>
</div>
You should be able to simple add flex to the container, and then add the content within a left and a right div.
Here's a working example:
.container {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.image-one,
.image-two {
width: 250px;
height: 95px;
background-color: green;
margin-bottom: 10px;
}
.image-three {
background-color: lightblue;
width: 240px;
height: 200px;
margin-left: 10px;
}
<div class="container">
<div class="left">
<div class="image-one">Hello</div>
<div class="image-two">Image two</div>
</div>
<div class="right">
<div class="image-three"> Image three </div>
</div>
</div>
You can use flexbox for this:
.container {
display: flex;
flex-direction: column; /* align items in columns */
flex-wrap: wrap; /* wrap to a new column when height is reached */
justify-content: space-between; /* add spacing in between top and bottom image */
height: 210px; /* height of your 2 images plus and spacing you want */
width: 510px; /* width of 2 columns plus any spacing */
}
.image-one,
.image-two {
width: 250px;
height: 100px;
background-color: green;
display: block;
}
.image-three {
background-color: lightblue;
width: 250px;
height: 210px; /* I would make this image the height of the other 2 plus spacing */
align-self:flex-end; /* align this to the right of the container */
}
<div class="container">
<div class="image-one">Hello</div>
<div class="image-two">Image two</div>
<div class="image-three"> Image three </div>
</div>
Maybe you can add some internal divs like this:
<div class="container">
<div class="container-left">
<div class="image-one">Hello</div>
<div class="image-two">Image two</div>
</div>
<div class="container-right">
<div class="image-three"> Image three </div>
</div>
</div>
Then, add css to container-left and container-right to properly set the width and the float. Like this:
.container-left, .container-right{
width:250px;
float:left;
}
Why don't you make use of bootstrap columns?
HTML
<div class="container">
<div class="row main-row">
<div class="col-6 left-col">
<div class="row left-col-top">
<!-- Top left image here -->
</div>
<div class="row left-col-bottom">
<!-- Bottom left image here -->
</div>
</div>
<div class="col-6 right-col">
</div>
</div>
</div>
CSS
.main-row {
height:300px;
}
.left-col-top {
background-color:blue;
height:50%;
}
.left-col-bottom {
background-color:red;
height:50%;
}
.right-col {
background-color:green;
height:100%;
}
Easy flexbox solution :)
#main, #left {
display:flex;
}
#left {
flex-direction: column;
flex: 1;
}
.section {
flex: 1;
margin: 2px;
background-color: green;
}
<div id="main">
<div id="left">
<div class="section">Hello</div>
<div class="section">Hello</div>
</div>
<div id="right" class="section">Hello</div>
</div>

HTML/CSS Float Left and Top/Bottom without position absolute/fixed

I'm working on my Chemistry application, and I'm struggling with displaying div element how I imagined it could work.
My goal is to have divs floating left as on image: so when hiding red/green div everything stays in order.
Is it even possible without using absolute/fixed positioning? I really need those divs to float left and be aware of each other so I can't solve it by position absolute. I tried experimenting with adding margin, but other div cannot fit into place taken by other element margin.
Thank you for your time spent on reading this post!
Code added:
<div class='container'>
<div class='base-cell'>S</div>
<div class='base-cell'>O</div>
<div class='index-cell'>3</div>
<div class='charge-cell'>2-</div>
</div>
.container{
border: 1px solid red;
height: 1.5em;
text-align: center;
position: relative;
}
.base-cell{
position: relative;
background: red;
height: 1em;
float: left;
margin-top: 0.2em;
font-size: 1em;
border: 1px solid orange;
display: inline-block;
}
.index-cell{
position:relative;
height:0.7em;
margin-top:1.5em;
font-size:0.7em;
display:table;
background: blue;
float:left;
}
.ion-index-cell{
position: relative;
height: 1em;
font-size: 0.7em;
border: 1px solid cyan;
display: table;
background: green;
}
.charge-cell{
height: 1em;
font-size: 0.7em;
border: 1px solid blue;
display: inline-block;
float:left;
}
Edit:
Thank you for your replies, I really don't want to use middle column solution, because of another requirement: sorry for not showing full context before.
As you can see in the picture, all elements flow to the left, and I may need to hide some by using display: none. Thats why I'm looking for parentless solution:
If you flip the diagram on its side then its a lot easier to build using floats. You can use transforms to flip it back up the correct way.
.wrap {
max-width: 100px;
-webkit-transform: rotate(90deg) translate(-170px, -10px);
-moz-transform: rotate(90deg) translate(-170px, -10px);
-ms-transform: rotate(90deg) translate(-170px, -10px);
transform: rotate(90deg) translate(-170px, -10px);
-webkit-transform-origin: 0% 100%;
-moz-transform-origin: 0% 100%;
-ms-transform-origin: 0% 100%;
transform-origin: 0% 100%;
overflow: hidden;
}
.block {
height: 40px;
width: 100%;
float: left;
border: 1px solid #000;
box-sizing: border-box;
margin: 10px 0;
}
.block-left {
max-width: 40%;
border-color: #f00;
}
.block-right {
max-width: 40%;
float: right;
border-color: #0f0;
}
<div class="wrap">
<div class="block block-top"></div>
<div class="block block-left"></div>
<div class="block block-right"></div>
<div class="block block-bottom"></div>
</div>
<div class="wrap">
<div class="block block-top"></div>
<div class="block block-right"></div>
<div class="block block-bottom"></div>
</div>
<div class="wrap">
<div class="block block-top"></div>
<div class="block block-left"></div>
<div class="block block-bottom"></div>
</div>
This may help you somewhat. Its very crude html but I believe does what your looking for. It should at least help you in the direction your looking to go.
<div style="height:100%;">
<div style="float:left; width: 33%;">
Content 1
</div>
<div style="float:left; width: 33%;">
<div style="height:50%">
<div>Content 2</div>
</div>
<div style="height:50%;">
<div>Content 3</div>
</div>
</div>
<div style="float:left; width: 33%;">
Content 4
</div>
</div>
From your question, it looks like you just want to use float:left instead of position:absolute which you are using currently and still want to hide the green and red boxes, while keeping all other boxes intact.
This can be achieved by using float:left; on the boxes while setting the opacity:0; on the red and green boxes (also visibility:hidden work).
So I'm not sure how you are handling the mark up but hopefully you are doing it the proper way. It seems like you have a grid-format in place but you are not applying this on the middle column.
What you should be doing is creating three columns and then when necessary, you can hide the middle column. The red and green box can exist within the middle column. This way if you ever say wanted to add those red/green sections in the left or right column, you can easily do that.
I have created an example below. I have also added a class called hide which can apply to the different columns and/or inner boxes. Like I was mentioning above, you should be adding hide to the middle col if you want to hide everything in the middle column. Apply hide to the inner elements if you want to hide one of those.
I do some absolute positioning in the middle column but you don't actually need to do this -- you can change this to float: left and simply set a margin-top for the bottom box.
.col {
float: left;
width: 100px;
height: 200px;
border: 1px solid black;
margin-left: 10px;
position: relative;
}
.inner {
width: 100px;
height: 75px;
margin-left: auto;
margin-right: auto;
position: absolute;
}
.top {
top: 0;
border: 1px solid red;
}
.bottom {
bottom: 0;
border: 1px solid green;
}
.hide {
display: none;
<div class="col left"></div>
<div class="col middle">
<div class="top inner"></div>
<div class="bottom inner"></div>
</div>
<div class="col right"></div>
EDIT: I notice you posted your CSS and you're using display: table. For that I would like to refer you to this link.
shouldiusetablesforlayout.com
EDIT2: I see you updated your question but the overall concept applies. You are still dealing with columns but I guess in your case now, you kind of want those columns in containers.
.col-container {
float: left;
margin-bottom: 10px;
}
.col {
float: left;
width: 100px;
height: 200px;
border: 1px solid black;
margin-left: 10px;
position: relative;
}
.inner {
width: 100px;
height: 75px;
margin-left: auto;
margin-right: auto;
position: absolute;
}
.top {
top: 0;
border: 1px solid red;
}
.bottom {
bottom: 0;
border: 1px solid green;
}
.hide {
display: none;
}
<div class="col-container">
<div class="col left"></div>
<div class="col middle">
<div class="top inner"></div>
<div class="bottom inner hide"></div>
</div>
<div class="col right"></div>
</div>
<div class="col-container">
<div class="col left"></div>
<div class="col middle">
<div class="top inner hide"></div>
<div class="bottom inner"></div>
</div>
<div class="col right"></div>
</div>
<div class="col-container">
<div class="col left"></div>
<div class="col middle">
<div class="top inner"></div>
<div class="bottom inner"></div>
</div>
<div class="col right"></div>
</div>
If you view it in full page, and shrink the window size, you'll see the 3rd col-container to appear on the second line. If you want to make sure it only has two columns or things break at certain points you can adjust for that by either adding clear to certain elements, distinguishing row classes, etc.
I would use flexbox and justify-content: space-between; should be the thing you are asking for.
<article>
<div>left</div>
<div class="content">
<p>top</p>
<p>bottom</p>
</div>
<div>right</div>
</article>
article {
display: flex;
min-height: 10em;
}
article > div {
flex: 1 1 calc(33.3333% - 1em);
margin: 0.5em;
}
.content {
display: flex;
flex-direction: column;
justify-content: space-between;
}
Codepen sample (w/ -prefix-free, styling and as SCSS)
Simple ;)