Horizontal line in the middle of divs - html

I want to make a line in the middle of the divs. In the following image, the line should be in the middle of the red boxes.
I'm trying to do that using the line height, but not able to.
Here's the code:
HTML/CSS:
.wrap {
text-align: center;
margin: 20px;
}
.links {
padding: 0 10px;
border-top: 1px solid #000;
height: 1px;
line-height: 0.1em;
}
.dot {
width: 20px;
height: 20px;
background: red;
float: left;
margin-right: 150px;
position: relative;
top: -10px;
}
<div class="wrap">
<div class="links">
<div class="dot"></div>
<div class="dot"></div>
<div class="dot"></div>
</div>
</div>
Demo:
https://jsfiddle.net/nkq468xg/

You can use Flexbox on links and for line you can use :before pseudo-element on wrap element.
.wrap {
text-align: center;
margin: 20px;
position: relative;
}
.links {
padding: 0 10px;
display: flex;
justify-content: space-between;
position: relative;
}
.wrap:before {
content: '';
position: absolute;
top: 50%;
left: 0;
border-top: 1px solid black;
background: black;
width: 100%;
transform: translateY(-50%);
}
.dot {
width: 20px;
height: 20px;
background: red;
}
<div class="wrap">
<div class="links">
<div class="dot"></div>
<div class="dot"></div>
<div class="dot"></div>
</div>
</div>

Here's one where the line is actually on top, but it does add another element to the HTML:
https://jsfiddle.net/nkq468xg/2/
.wrap {
text-align: center;
margin: 20px;
}
.links {
height: 20px;
position: relative;
}
hr {
border: 0;
height: 1px;
background: black;
position: absolute;
top: 1px;
width: 100%;
}
.dot {
width: 20px;
height: 20px;
background: red;
float: left;
margin-right: 150px;
}
<div class="wrap">
<div class="links">
<hr>
<div class="dot"></div>
<div class="dot"></div>
<div class="dot"></div>
</div>
</div>

You can use pseudo element, like ::after
.links {
padding: 0 10px;
overflow: auto; // Your div will have the height of the overflowing elements
}
.links::after {
content: '';
width: 100%;
height: 1px;
background: black;
display: block;
position: relative;
top: 10px;
}

Check your code snippet in your question here on SO ("Run code snippet" blue button), is that what you need?
Added position: relative; top: -10px; in your code for .dot.
.dot {
position: relative;
top: -10px;
}
Fiddle: https://jsfiddle.net/nkq468xg/3/

Related

Using CSS, is there a way to float multiple DIVs overlapping a sibling DIV?

The following code does what I want:
.foo {
background-color: lightgray;
display: block;
height: 200px;
width: 300px;
position: relative;
}
.baz {
display: block;
background-color: red;
height: 20px;
width: 20px;
margin-left: 4px;
float: right;
}
.bar {
position: absolute;
display: block;
right: 15px;
top: 20px;
z-index: 2;
}
.qux {
background-color: gray;
position: absolute;
display: block;
height: 150px;
width: 280px;
left: 10px;
top: 10px;
z-index: 1;
}
<div class="foo">
<div class="bar">
<div class="baz"></div>
<div class="baz"></div>
<div class="baz"></div>
</div>
<div class="qux"></div>
</div>
Is there a way to do this without the intervening bar div? In other words, can I achieve the same effect (baz divs floated right, overlaying the qux div) with the following code:
<div class="foo">
<div class="baz"></div>
<div class="baz"></div>
<div class="baz"></div>
<div class="qux"></div>
</div>
It's a small thing, but I have reasons to keep the HTML as simple as possible in this project.
Thanks!
.foo {
background-color: lightgray;
display: block;
height: 200px;
width: 300px;
position: relative;
}
.baz {
display: block;
background-color: red;
height: 20px;
width: 20px;
position: absolute;
z-index: 2;
top: 20px;
}
.baz:nth-child(1) {
right: 15px;
}
.baz:nth-child(2) {
right: 39px; // 15px + 4px margin + 20px width
}
.baz:nth-child(3) {
right: 63px; // 39px + 4px margin + 20px width
}
.qux {
background-color: gray;
position: absolute;
display: block;
height: 150px;
width: 280px;
left: 10px;
top: 10px;
}
<div class="foo">
<div class="baz"></div>
<div class="baz"></div>
<div class="baz"></div>
<div class="qux"></div>
</div>

Center position: absolute and make it full size

I have an item has position: absolute in a container. I centered it by left: 50% and transform: translateX(-50%);. This item just contain text and i want it cover it's content and the text will nowrap as much as possible.
As we can see in the snipet below, the item have enough space but it did not increase width. It broke line. I know i can add white-space: nowrap to stop it breaking line but if the text is longer, one line can not wrap all text.
Adding width: 100% to item can not help because I want the width of item is dynamic base on it's content.
.container {
width: 300px;
height: 200px;
border: solid 1px #123;
position: absolute;
}
.item {
position: absolute;
top: 20px;
left: 50%;
transform: translateX(-50%);
background-color: #303030;
color: #FFF;
border-radius: 20px;
padding: 8px 16px;
}
<div class="container">
<div class="item">
<span>Hello. Its me. How are you?</span>
</div>
</div>
It this what you want? Use left: 0, right: 0 instead to center it then move your other styles in span.
.container {
width: 300px;
height: 200px;
border: solid 1px #123;
position: absolute;
}
.item {
position: absolute;
top: 20px;
left: 0;
right: 0;
text-align: center;
}
.item .content {
display: inline-block;
width: auto;
height: auto;
background-color: #303030;
color: #FFF;
border-radius: 20px;
padding: 8px 16px;
}
<div class="container">
<div class="item">
<div class="content">
<span>Hello. Its me. How are you?</span>
</div>
</div>
</div>
Would flexbox work for you?
.container {
width: 300px;
height: 200px;
border: solid 1px #123;
display: flex;
justify-content: center;
align-items: center;
}
.item {
background-color: #303030;
color: #FFF;
border-radius: 20px;
padding: 8px 16px;
}
<div class="container">
<div class="item">
<span>Hello. Its me. How are you? Hello. Its me. How are you? Hello. Its me. How are you? </span>
</div>
</div>
Please try this.
.container {
width: 300px;
height: 200px;
border: solid 1px #123;
position: relative;
}
.item {
margin-top: 20px;
display: flex;
justify-content: center;
}
.item span{
background-color: #303030;
color: #FFF;
border-radius: 20px;
padding: 8px 16px;
}
<div class="container">
<div class="item">
<span>Hello. Its me. How are you?</span>
</div>
</div>
Try adding center align for span tag
.container {
width: 300px;
height: 200px;
border: solid 1px #123;
position: absolute;
}
.item {
position: absolute;
top: 20px;
left: 0;
right: 0;
width: auto;
text-align: center;
}
.item .itemInner {
background-color: #303030;
color: #FFF;
border-radius: 20px;
padding: 8px 16px;
text-align: left;
margin: 0 auto;
}
<html>
<head>
</head>
<body>
<div class="container">
<div class="item">
<span class="itemInner">Hello. Its me.</span>
</div>
</div>
</body>
</html>

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!

Can't position div below another div

I'm trying to make a website, with my basic knowledge, for my mother. But I've tried many things, but I can't get it to work the way I want it to
This is how it now looks:
And this is how I want it to be:
But somehow I can't get it to work. The div isn't positioning where I want it to position.
This is my source code:
JsFiddle
It's about this part that doesn't position properly:
<div class="wrapper_3">
<div class="main_3">
3
</div>
</div>
Thanks in advance for the help! I really can't get it to work.
Add float:left; to wrapper_1 and wrapper_2
after that, use position:relative; to position wrapper_2.
visit this link if you need more information about syntax.
CSS Position Property
Here is your new CSS.
.wrapper_1 { width: 25%;
display: inline-block;
position: relative;
margin-left: 21%;
margin-top: 14%;
clear: both;
float:left;}
.wrapper_2 {
width: 25%;
display: inline-block;
position: absolute;
margin-left: 16px;
margin-top: 5%;
float:left;
position: relative;
top: 50%;
}
it will be easier if you use bootstrap for your website.
html:
<div class="container">
<div class="row">
<div class="col-xs-2">
<div class="logo text-center">logo</div>
</div>
<div class="col-xs-offset-4 col-xs-3 box">2</div>
<div class="col-xs-offset-4 col-xs-3 box">1</div>
</div>
</div>
css:
.logo {
border-top: 1px solid black;
border-bottom: 1px solid black;
padding: 15px;
}
.box {
padding: 60px;
background-color: red;
margin-top: 30px;
}
http://jsfiddle.net/souraj/sxuqqqgd/
here you can see the code.
you have to link the bootstrap.css file to work. just visit to getbootstrap.com and see how to link bootstrap.css in your code.add this code to your head section of the code.
enter link description here
Here you go :) I edited your fiddle, Why are you using position:absolute; everywhere? There is no need of absolute positioning in your design.
* {
padding: 0;
margin: 0;
}
html, body {
width: 100%;
height: 100%;
}
.main {
position: relative;
width: 100%;
height: 100%;
}
.wrapper_logo {
margin-top: 10px;
margin-left: 10px;
width:20%;
display: inline-block;
position: absolute;
}
.wrapper_logo:after {
padding-top: 45%;
/* 16:9 ratio */
display: block;
content: '';
}
.main_logo {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
padding: 10px;
padding-left: 20px;
font-size: 30px;
border-top: 1px solid black;
border-bottom: 1px solid black;
color: black;
vertical-align: middle;
}
.wrapper_1 {
width: 25%;
display: inline-block;
position: relative;
margin-left: 21%;
margin-top: 14%;
clear: both;
}
.wrapper_1:after {
padding-top: 56.10%;
/* 16:9 ratio */
display: block;
content: '';
clear: both;
}
.main_1 {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
padding: 20px;
font-size: 30px;
background-color: deepskyblue;
color: white;
}
.wrapper_2 {
width: 25%;
margin-left:200px;
}
.wrapper_2:after {
padding-top: 56.10%;
/* 16:9 ratio */
display: block;
content: '';
}
.main_2 {
padding: 20px;
font-size: 30px;
background-color: deepskyblue;
color: white;
}
.wrapper_3 {
width: 15%;
float: left;
display: inline-block;
position: absolute;
}
.wrapper_3:after {
padding-top: 56.10%;
/* 16:9 ratio */
display: block;
content: '';
}
.main_3 {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
padding: 20px;
font-size: 30px;
background-color: deepskyblue;
color: white;
}
.three {
position: absolute;
background: green;
width: 400px;
top: 10px;
left: 50px;
}
<!DOCTYPE html>
<div class="main">
<div class="wrapper_logo">
<div class="main_logo">
LOGO
</div>
</div>
<div class="wrapper_1">
<div class="main_1">
1
</div>
</div>
<div class="wrapper_2">
<div class="main_2">
2
</div>
</div>
<!-- <div class="wrapper_3">
<div class="main_3">
3
</div>
</div> -->
</div>

An Inline Relative Div with Absolute Divs In It

The following is my markup:
.play-controls {
.fa-play, .fa-pause {
font-size: 25px;
}
}
.volume-controls {
display: inline-block;
position: relative;
.overlay {
background-color: $highlight;
height: 10px;
border-radius: 5px;
width: 0px;
position: absolute;
z-index: 15;
}
.background {
background-color: $text-color;
width: 100px;
height: 10px;
border-radius: 5px;
position: absolute;
z-index: 10;
}
.circle {
border-radius: 100%;
position:absolute;
background-color: #fff;
border: 1px solid;
height: 15px;
width: 15px;
z-index: 20;
top: -3px;
}
}
.player {
#album-artwork {
width: 80px;
height: 80px;
vertical-align: middle;
display:inline-block;
margin-right: 10px;
}
.wrapper {
display:inline-block;
.information {
margin-bottom: 5px;
#song-title {
font-size: 22px;
font-weight:bold;
margin-right: 5px;
}
#artist-album {
font-size: 18px;
}
}
.progress-bar {
position: relative;
.overlay {
background-color: $highlight;
height: 10px;
border-radius: 5px;
width: 0px;
position: absolute;
z-index: 15;
}
.background {
background-color: $text-color;
width: 600px;
height: 10px;
border-radius: 5px;
position: absolute;
z-index: 10;
}
.circle {
border-radius: 100%;
position:absolute;
background-color: #fff;
border: 1px solid;
height: 15px;
width: 15px;
z-index: 20;
top: -3px;
}
}
}
}
<div class="play-controls">
<i class="fa fa-play" id="playpause"></i>
</div>
<div class="volume-controls">
<div class="background"></div>
<div class="circle"></div>
<div class="overlay"></div>
</div>
<div class="player">
<img id="album-artwork" src="build/images/guero.jpg">
<div class="wrapper">
<div class="information">
<span id="song-title">Go It Alone</span>
<span id="artist-album">Beck - Guero</span>
</div>
<div class="progress-bar">
<div class="background"></div>
<div class="circle"></div>
<div class="overlay"></div>
</div>
</div>
</div>
The divs with classes background, circle, and overlay in volume-controls are all position: absolute; with volume-controls as position: relative;.
Upon making play-controls, volume-controls, and player inline, play-controls is inline with volume-controls, but volume-controls is overlapping the player.
How would I be able to set everything in one line, without any overlapping?
EDIT: JSFiddle
You could float:left; the 3 main parts or display:inline-block; them the issue the player is over the volume-controls is because of the absolute positioned elements in the volume-controls. You could add a width to volume-controls.
.volume-controls {
display: inline-block;
position: relative;
width:150px;
}
Here is the fiddle