CSS - float:left not pushing div away/working properly - html

I have two div's next to each other but I cannot seem to get float: left to work properly and achieve what I want. Every time, the left div will still cut into/overlap onto the right div like so (This the dynamic version of my code with some jQuery code which changes the size of the divs based on user input): https://gyazo.com/b373205412f4ba18f32dad0f3cf877d2
Here is the static version of my code where I change the width/height manually. As you can see I have float: left on div5brother, but div5 still overlaps onto it. jsFiddle: https://jsfiddle.net/Kaevonz/92etqaxk/10/
This is what I am trying to recreate:
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: start;
height: 500px;
border: 1px solid gray;
}
.elem {
box-sizing: border-box;
}
.div1 {
border-top: 3px solid #0DA8AA;
border-left: 1px solid #0DA8AA;
border-right: 1px solid #0DA8AA;
height: 60px;
width: 205px;
background: white;
}
.div2 {
border: 1px solid #0DA8AA;
border-radius: 50%;
width: 290px;
height: 290px;
background: white;
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
.div3 {
border: 1px solid #0DA8AA;
border-radius: 50%;
width: 280px;
height: 280px;
background: white;
text-align: center;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.div3 > span {
transform: translate(-10%, -55%) rotate(-45deg);
font-size: 11px;
}
.div4 {
border-top: 0.5px dashed black;
width: 100%;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%) rotate(-45deg);
}
.div5container {
width: 205px;
height: 50px;
position: absolute;
top: 0;
}
.div5 {
border: 0.5px dashed black;
width: 235px;
height: 50px;
top: 0;
transform: translateX(-50%);
left: 50%;
position: absolute;
}
.div5brother {
position: absolute;
top: 0;
right: -80px;
width: 80px;
height: 50px;
border-top: 1px solid black;
border-bottom: 1px solid black;
float: left;
}
.div5brother > span {
font-size: 9px;
line-height: 50px;
display: block;
position: absolute;
right: -40px;
text-transform: uppercase;
}
<div class="container">
<div class="elem div1"></div>
<div class="elem div2">
<div class="elem div3"><span>Pipe O.D.</span>
<div class="div5container">
<div class="elem div5">
</div>
<div class="elem div5brother">
<span>Min. Cutter Travel</span>
</div>
</div>
<div class="elem div4">
</div>
</div>
</div>
</div>

As far as I can see the overlapping is due to you making the div5 element 30px wider than its container. I changed its width from width: 235px; to width: 205px; and the overlapping is gone and it seems to match the image. Here is a JSFiddle with my changes.

Related

Why does browser zoom cause line artifacts in my web css html element

In a css/html element on a webpage I've made, if a user zooms in or out on their browser, artifacts emerge showing a line. Here is a code pen of the issue. Zoom in or out on your browser to see the red line at top emerge like below:
I've read that these problems can emerge because a browser can set the zoom to 1.5x, thus creating rounding issues for pixels. See slack post here. But I'm not sure what the appropriate fix should be. In my case I want the triangles at each end of my rectangle element which I create via css styling. Besides recreating the graphic via svg, is there any good tricks?
Here is the html/css in codepen:
#root {
display: block;
width: 100%;
height: 100%;
background-color: lightgrey;
padding: 24px;
max-width: 400px;
float: center;
position: relative;
}
#gridRoot {
display: flex;
flex-flow: column wrap;
top: 50%;
left: 50%;
align-content: center;
}
#LegendContainer {
box-sizing: border-box;
display: flex;
flex-flow: row nowrap;
width: 100%;
align-items: center;
justify-content: space-between;
}
#container {
background-color: grey;
postion: relative;
height: 120px;
justify-content: center;
left: calc(50% - 60px);
text-align: center;
top: calc(50% - 60px);
}
#circle {
transform: rotate(7.39deg);
}
#jss {
display: flex;
position: absolute;
background: red;
top: 40px;
width: 110px;
opacity: 80%;
height: 20px;
}
#jss::before {
left: 0;
width: 0;
bottom: 0;
height: 0;
content: '';
position: absolute;
transform: rotate(180deg);
border-top: 10px solid white;
border-left: 10px solid #00007f;
border-bottom: 10px solid white;
}
#jss::after {
right: 0;
width: 0;
bottom: 0;
height: 0;
content: '';
position: absolute;
border-top: 10px solid white;
border-left: 10px solid #7f0000;
border-bottom: 10px solid white;
}
<div id="root">
<div id="gridRoot">
<div id="LegendContainer">
<div id="container">
<div id="circle">
</div>
<div id="jss">
</div>
</div>
</div>
</div>
</div>
The ::before and ::after elements seemed to be causing the issue. Solution;
body {
margin: 0;
}
#container {
background-color: grey;
position: relative;
display: flex;
height: 120px;
justify-content: center;
text-align: center;
}
#jss {
display: flex;
position: absolute;
top: 40px;
width: 110px;
opacity: 80%;
height: 20px;
}
#jss-internal {
background: red;
width: 100%;
}
#jss-before {
content: '';
transform: rotate(180deg);
border-top: 10px solid white;
border-left: 10px solid #00007f;
border-bottom: 10px solid white;
}
#jss-after {
border-top: 10px solid white;
border-left: 10px solid #7f0000;
border-bottom: 10px solid white;
}
<div id="root">
<div id="LegendContainer">
<div id="container">
<div id="circle">
</div>
<div id="jss">
<div id="jss-before">
</div>
<div id="jss-internal">
</div>
<div id="jss-after">
</div>
</div>
</div>
</div>
</div>

CSS - Align diagonal line inside concentric circles

I am stuck on how to align this diagonal line inside the inner circle. I have tried using position: absolute and display: flex and other methods, but cannot seem to get something that works.
jsFiddle: https://jsfiddle.net/Kaevonz/7edw8yuq/20/
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: start;
height: 500px;
border: 1px solid gray;
}
.elem {
box-sizing: border-box;
}
.div1 {
border-top: 3px solid #0DA8AA;
border-left: 1px solid #0DA8AA;
border-right: 1px solid #0DA8AA;
height: 70px;
width: 70px;
background: white;
}
.div2 {
border: 1px solid blue;
border-radius: 50%;
width: 200px;
height: 200px;
background: white;
display: flex;
align-items: center;
justify-content: center;
}
.div3 {
border: 1px solid green;
border-radius: 50%;
width: 180px;
height: 180px;
background: white;
}
.div4 {
border-top: 1px dashed #f00;
width: 50%;
transform: rotate(-45deg);
transform-origin: top middle;
}
<div class="container">
<div class="elem div1"></div>
<div class="elem div2">
<div class="elem div3">
<div class="elem div4">
</div>
</div>
</div>
</div>
You can center the line using flexbox on div3
display: flex;
align-items: center;
justify-content: center;
Then adjust the transform of the line as required.
I'm assuming from the design this is supposed to be an clock of some kind and this a "second hand".
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
height: 500px;
border: 1px solid gray;
}
.elem {
box-sizing: border-box;
}
.div1 {
border-top: 3px solid #0DA8AA;
border-left: 1px solid #0DA8AA;
border-right: 1px solid #0DA8AA;
height: 70px;
width: 70px;
background: white;
}
.div2 {
border: 1px solid blue;
border-radius: 50%;
width: 200px;
height: 200px;
background: white;
display: flex;
align-items: center;
justify-content: center;
}
.div3 {
border: 1px solid green;
border-radius: 50%;
width: 180px;
height: 180px;
background: white;
display: flex;
align-items: center;
justify-content: center;
}
.div4 {
border-top: 1px dashed #f00;
width: 50%;
transform: translateX(-50%) rotate(90deg);
transform-origin: right;
animation: spin 5s linear infinite;
}
#keyframes spin {
0% {
transform: translateX(-50%) rotate(90deg);
}
100% {
transform: translateX(-50%) rotate(450deg);
}
}
<div class="container">
<div class="elem div1"></div>
<div class="elem div2">
<div class="elem div3">
<div class="elem div4">
</div>
</div>
</div>
</div>
Use position:absolute and make it relative to the outer container:
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: start;
height: 500px;
border: 1px solid gray;
}
.elem {
box-sizing: border-box;
}
.div1 {
border-top: 3px solid #0DA8AA;
border-left: 1px solid #0DA8AA;
border-right: 1px solid #0DA8AA;
height: 70px;
width: 70px;
background: white;
}
.div2 {
border: 1px solid blue;
border-radius: 50%;
width: 200px;
aspect-ratio: 1;
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
.div3 {
border: 1px solid green;
border-radius: 50%;
width: 180px;
aspect-ratio: 1;
}
.div4 {
border-top: 1px dashed #f00;
position: absolute;
width: 100%;
left: 50%;
top: 50%;
transform: translate(-50%, -50%) rotate(-45deg);
}
<div class="container">
<div class="elem div1"></div>
<div class="elem div2">
<div class="elem div3">
<div class="elem div4">
</div>
</div>
</div>
</div>
I would also simplify your code a little like below:
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: start;
height: 500px;
border: 1px solid gray;
}
.elem {
box-sizing: border-box;
}
.div1 {
border: solid #0DA8AA;
border-width: 3px 1px 0;
height: 70px;
aspect-ratio: 1;
}
.div2 {
border: 1px solid blue;
border-radius: 50%;
width: 200px;
aspect-ratio: 1;
display: grid;
position: relative;
}
.div2:before {
content:"";
border-top: 1px dashed #f00;
position: absolute;
width: 100%;
left: 50%;
top: 50%;
transform: translate(-50%, -50%) rotate(-45deg);
}
.div2:after {
content: "";
border: 1px solid green;
border-radius: 50%;
margin: 10px;
}
<div class="container">
<div class="elem div1"></div>
<div class="elem div2"></div>
</div>

CSS - Add tangent rectangle onto top of concentric circles

I am trying to recreate this graphic but I am a bit stuck on how to add the tangent rectangle on top of the outer concentric circle and below the 3 sided rectangle object as shown below. Additionally, the height of the rectangle should be tall enough so that it only touches the outside of the inner circle. This is what I have so far on jsFiddle.
jsFiddle: https://jsfiddle.net/Kaevonz/mowahL2v/35/
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: start;
height: 500px;
border: 1px solid gray;
}
.elem {
box-sizing: border-box;
}
.div1 {
border-top: 3px solid #0DA8AA;
border-left: 1px solid #0DA8AA;
border-right: 1px solid #0DA8AA;
height: 70px;
width: 120px;
background: white;
}
.div2 {
border: 1px solid #0DA8AA;
border-radius: 50%;
width: 200px;
height: 200px;
background: white;
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
.div3 {
border: 1px solid #0DA8AA;
border-radius: 50%;
width: 180px;
height: 180px;
background: white;
}
.div4 {
border-top: 0.5px dashed black;
width: 100%;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%) rotate(-45deg);
}
.div5 {
border: 0.5px dashed black;
width: 120px;
height: 80px;
}
<div class="container">
<div class="elem div1"></div>
<div class="elem div2">
<div class="elem div3">
<div class="elem div5">
<div class="elem div4">
</div>
</div>
</div>
</div>
</div>
You are already using a relative position for div2, so i would use a position: absolute on div5:
.div5 {
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%);
border: 0.5px dashed black;
width: 120px;
height: 80px;
}
The transform property, combined with the left property is to make sure that your element is centered.
Then, i would remove your div4 from div3, because it looks like you're creating relationships between divs that don't seem to be necessary (Unless there is a mathematical reason for that):
<div class="container">
<div class="elem div1"></div>
<div class="elem div2">
<div class="elem div3">
<div class="elem div5">
</div>
<div class="elem div4">
</div>
</div>
</div>
</div>
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: start;
height: 500px;
border: 1px solid gray;
}
.elem {
box-sizing: border-box;
}
.div1 {
border-top: 3px solid #0DA8AA;
border-left: 1px solid #0DA8AA;
border-right: 1px solid #0DA8AA;
height: 70px;
width: 120px;
background: white;
}
.div2 {
border: 1px solid #0DA8AA;
border-radius: 50%;
width: 200px;
height: 200px;
background: white;
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
.div3 {
border: 1px solid #0DA8AA;
border-radius: 50%;
width: 180px;
height: 180px;
background: white;
}
.div4 {
border-top: 0.5px dashed black;
width: 100%;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%) rotate(-45deg);
}
.div5 {
border: 0.5px dashed black;
width: 120px;
height: 80px;
position: absolute;
top: 0;
transform: translateX(-50%);
left: 50%;
}
<div class="container">
<div class="elem div1"></div>
<div class="elem div2">
<div class="elem div3">
<div class="elem div5">
</div>
<div class="elem div4">
</div>
</div>
</div>

Aligning a div created using :before & :after horizontally to other elements

I am using :before to create a black circle (which should display white text exactly centered within, can't work out why it isn't white) and :after to display a dashed line (as seen). I'd like the black circle (with text inside it) to sit horizontally level with the input but I've been having issues with it as it also creates a big gap between it & the after dashed line. I've played around margin but I don't want to push elements above too far away.
.progress-container {
display: flex;
position: relative;
}
.progress-indicator {
position: relative;
display: inline-block;
margin-bottom: 40px;
color: #fff;
}
.progress-indicator::before {
content: "";
width: 22px;
height: 22px;
background: #000;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 50%;
}
.progress-indicator::after {
content: "";
height: 85px;
border: 2px dashed #a9b4b8;
position: absolute;
left: 50%;
top: 49px;
transform: translateX(-50%);
margin-bottom: 10px;
}
.input-container {
display: flex;
align-items: center;
}
.input-wrapper {
border: 1px solid #ced4da;
border-radius: 2px;
overflow-y: hidden;
padding: 0.375rem 1.75rem 0.375rem 0.75rem;
margin-left: 30px;
}
<div class=progress-container>
<div class="progress-indicator">1</div>
<div class="input-container">
<div class="input-wrapper">
<div>Input</div>
</div>
</div>
</div>
Caution: you have a typo in your .progess-container selector correct: .progress-container
Edited your CSS:
.progress-container {
display: flex;
flex-direction: row;
align-items: center;
position: relative;
}
.progress-indicator {
position: relative;
display: inline-block;
color: #fff;
}
.progress-indicator::before {
content: "";
width: 22px;
height: 22px;
background: #000;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 50%;
z-index: -1;
}
.progress-indicator::after {
content: "";
height: 85px;
border: 2px dashed #a9b4b8;
position: absolute;
left: 50%;
transform: translateX(-50%);
margin-bottom: 10px;
z-index: -2;
}
.input-container {
display: flex;
align-items: center;
}
.input-wrapper {
border: 1px solid #ced4da;
border-radius: 2px;
overflow-y: hidden;
padding: 0.375rem 1.75rem 0.375rem 0.75rem;
margin-left: 30px;
}
<div class=progress-container>
<div class="progress-indicator">1</div>
<div class="input-container">
<div class="input-wrapper">
<div>Input</div>
</div>
</div>
</div>

Creating a line with circle in the middle

So, I'm trying to achieve this result:
This is what I got when I tried: https://jsfiddle.net/wvdkmjge/
.container {
width: 100px;
height: 1px;
background-color: black;
}
.circle {
display: inline-block;
vertical-align: middle;
width: 10px;
height: 10px;
background-color: transparent;
border: solid 1px black;
border-radius: 50%;
}
<div class="container">
<div class="circle">
</div>
</div>
Moreover, I want that I'll not see the border line on the circle. Any suggestions?
A small amendment to your code to position the elements and you get the effect you want to achieve.
.container {
width: 100px;
height: 1px;
background-color: black;
position: relative;
}
.circle {
display: inline-block;
vertical-align: middle;
width: 10px;
height: 10px;
background-color: white;
border: solid 1px black;
border-radius: 50%;
position: absolute;
top: -6px;
left: calc(50% - 5px);
}
.blue {
margin-top: 20px;
background: #3EB2EF;
}
.blue .circle {
background: #3EB2EF;
border-color: #3EB2EF;
}
<div class="container">
<div class="circle">
</div>
</div>
<div class="container blue">
<div class="circle">
</div>
</div>
If you want to position an element depending on its parent, use position:relative for the parent and then add position relative or absolute to the child. to center something in the middle, use margin:0 auto and if it has absolute positioning also add left:0; right:0;
https://jsfiddle.net/azizn/e4ev3awj/1/
.container {
width: 100px;
height: 1px;
background-color: blue;
position:relative;
}
.circle {
display:inline-block;
width: 10px;
height: 10px;
position: absolute;
background:blue;
left:0;
right:0;
margin:0 auto;
border-radius: 100%;
top:-4px;
}
<div class="container">
<div class="circle">
</div>
</div>
a bit late to answer, but this looks like a typical <hr/> that needs some makup.
/* restyle however your needs are hr and its pseudo elements , here only one is used */
hr {
color: turquoise;
border-width: 3px;
margin: 1em;
box-shadow: 0 0 5px gray;
}
hr:before {
content: '';
border-radius: 100%;
position: absolute;
height: 20px;
width: 20px;
background: turquoise;
left: 50%;
margin: -10px;
box-shadow: inherit
}
<hr/>
Try this:
.container {
width: 100px;
height: 1px;
background-color: black;
position: relative;
}
.circle {
position: absolute;
top: -5px;
left: 50%;
margin-left: -5px;
display: inline-block;
vertical-align: middle;
width: 10px;
height: 10px;
background-color: transparent;
border: solid 1px black;
border-radius: 50%;
}
<div class="container">
<div class="circle">
</div>
</div>
Fiddle
This uses a lot of different codes then above.
class:before and class:after
Hope this helps you!