Simple CSS Float Issue - html

I am a beginner and I am trying to create something like this
But I am having trouble getting the lines to stack on top of each other to the left of the text.
Can someone help nudge me in the right direction here?
#topbar {
width: 15%;
background-color: #000000;
height: 3px;
float: left;
}
#bottombar {
width: 15%;
background-color: #000000;
height: 1px;
float: none;
clear: both;
}
#LocationText {
float: left;
font-size: 50px;
}
<div id="topbar"></div>
<div id="LocationText">Location</div>
<div id="bottombar"></div>
here is my http://jsfiddle.net/y0sv7shs/

Use ::before and ::after :pseudo-elements.
span {
position: relative;
margin-left: 100px;
font-size: 50px;
}
span::before, span::after {
position: absolute;
content: '';
width: 50%;
height: 100%;
border-top: 1px solid black;
border-bottom: 1px solid black;
right: -50%;
top: 0;
}
span::before {
left: -50%;
}
<span>Location</span>
Or you could do something like this:
span {
position: relative;
margin-left: 100px;
font-size: 50px;
}
span::before, span::after {
position: absolute;
content: '';
width: 50%;
height: 25%;
border-top: 2px solid black;
border-bottom: 1px solid black;
right: -50%;
top: 37.5%;
}
span::before {
left: -50%;
}
<span>Location</span>
The one that you requested.
span {
position: relative;
font-family: 'Bree Serif', serif;
margin-left: 100px;
font-size: 50px;
color: #A0001F;
font-weight: bold;
}
span::before, span::after {
position: absolute;
content: '';
width: 100%;
height: 15%;
border-top: 2px solid #A0001F;
border-bottom: 2px solid #A0001F;
right: -100%;
top: 42.5%;
}
span::before {
left: -45%;
width: 45%;
}
<link href='http://fonts.googleapis.com/css?family=Bree+Serif' rel='stylesheet' type='text/css'>
<span>CONTACT</span>

In addition to chipChocolate's answer, you may also contain the elements so as to force them to reside above one another in a particular location relative to the text (However, this would take more elements, and isn't as clean):
<div class="locationcontainer">
<div id="topbar"></div>
<div id="bottombar"></div>
</div>
<div id="LocationText">Location</div>
#topbar {
width: 100%;
background-color: #000000;
height: 2px;
}
#bottombar {
width:90%;
background-color: #000000;
height: 2px;
margin-top: 10px;
float:right;
}
.locationcontainer
{
float:left;
width:15%;
margin-right:5px;
}
#LocationText {
float: left;
}
http://jsfiddle.net/fstqdxeu/

Related

how to put line and dots under a title with css

I want to put a line under a titlw with dots. like so: How can I do that? I am beginner at CSS. I tried to do it using before and after I could not achieve it though. Thanks in advance
This can help,
.text-wrapper {
max-width: 150px;
margin: 0 auto;
padding: 50px;
text-align: center;
}
.text-wrapper h2 {
margin: 0;
position: relative;
padding-bottom: 3px;
font-family: sans-serif;
}
.text-wrapper h2:after {
width: 50px;
content: '';
position: absolute;
left: 0;
height: 2px;
background: #adadad;
bottom: -4px;
left: 0;
}
.text-wrapper h2:before {
width: 50px;
content: '';
position: absolute;
height: 2px;
background: #adadad;
bottom: -4px;
right: 0;
}
.dots {
width: 4px;
height: 4px;
display: inline-block;
background: #ff9800;
border-radius: 100px;
position:relative;
margin: 0 2px;
}
.dots-wrapper {
display: inline-block;
width: 100%;
position: relative;
top: -10px;
}
<div class="text-wrapper">
<h2>Title</h2>
<div class="dots-wrapper">
<div class="dots"></div>
<div class="dots"></div>
<div class="dots"></div>
</div>
</div>

Design Border Bottom

I would like to design a border like below picture. But I am running out of ideas about how to do it.
https://codepen.io/szn0007/pen/VRGPyE
div.about-me h2{
color: #000;
border-bottom: 1px solid #efefef;
width: 20%;
margin: 0 auto;
padding: 20px;
}
THank you in advance.
Luckily with CSS you have access to two pseudo elements on every container. I added the Asterix to one of the pseudo elements :after and the line to another :before.
For example:
.fancy-underline {
position: relative;
display: inline-block;
}
.fancy-underline:before {
content: '';
position: absolute;
top: calc(100% + 10px);
left: 0;
width: 100%;
height: 1px;
background: grey;
}
.fancy-underline:after {
content: '*';
position: absolute;
top: 100%;
left: 50%;
transform: translateX(-50%);
background: #fff;
}
<h2 class="fancy-underline">About Me</h2>
try this out:
<div class="about-me">
<h2>About Me</h2>
<p>*</p>
</div>
css:
div.about-me{
width: 100%;
text-align: center;
}
div.about-me h2{
color: #000;
border-bottom: 1px solid #efefef;
width: 20%;
margin: 0 auto;
padding: 20px;
}
p {
font-size: 50px;
transform: translatey(-72px);
}

Overlap of rectangle

Below is the image I am trying for; I managed to get a rectangle using CSS, but I am trying for a rectangle above another one .
#dragtarget2 {
float: left;
clear: left;
width: 176px;
height: 76px;
background: #968282;
border-radius: 13px;
}
<div ondragstart="dragStart(event)" draggable="true" id="dragtarget2">
<p>meter</p>
</div>
Make your rectangles position: absolute and the container as position: relative.
This is the code you're looking for.
.container{
position: relative;
}
.first , .second, .third {
position: absolute;
top: 0;
left: 0;
width: 100px;
height: 40px;
background-color: gray;
border-radius: 4px;
border: 2px solid red;
}
.second{
top: 4px;
left: 4px;
}
.third{
top: 8px;
left: 8px;
}
<div class="container">
<div class="first"></div>
<div class="second"></div>
<div class="third"></div>
</div>
Use position: absolute/position: relative to move element from it's origin position. Use z-index to move element above/below other elements (higher z-index - higher element is positioned).
.border {
border: 2px solid red;
background-color: #aaa;
width: 200px;
height: 50px;
line-height: 50px;
position: absolute;
left: 0;
top: 0;
z-index: 5;
}
.border:nth-child(2) {
left: 5px;
top: 5px;
z-index: 6;
}
.border:nth-child(3) {
left: 10px;
top: 10px;
z-index: 7;
}
.wrapper {
margin: 10px;
/* NOTE: this does not effect absolute elements */
padding: 10px;
/* NOTE: this will be origin of absolute elements coordinates */
position: relative;
}
<div class="wrapper">
<div class="border">1</div>
<div class="border">2</div>
<div class="border origin">SmartMeter</div>
</div>
With less HTML:
.wrapper {
position: relative;
margin: 10px;
}
.border {
position: relative;
}
.border span,
.border:before,
.border:after {
content: '';
position: absolute;
left: 0;
top: 0;
border: 2px solid red;
background: #aaa;
display: inline-block;
width: 200px;
height: 50px;
line-height: 50px;
}
.border:after {
left: 5px;
top: 5px;
z-index: 6;
}
.border span {
left: 10px;
top: 10px;
z-index: 7;
}
<div class="wrapper">
<div class="border"><span>SmartMeter</span>
</div>
</div>
I have added two outer divs so that the code is as follows.
#dragtarget2 {
float: left;
clear: left;
width: 176px;
height: 76px;
background: #968282;
border-radius: 13px;
border: 2px solid;
padding: 2px;
}
.dragtarget0 {
float: left;
clear: left;
width: 176px;
height: 76px;
border: 2px solid;
border-radius: 13px;
padding: 2px;
margin: 2px;
}
.dragtarget1 {
float: left;
clear: left;
width: 176px;
height: 76px;
border: 2px solid;
border-radius: 13px;
padding: 3px;
}
<div class="dragtarget0">
<div class="dragtarget1">
<div id="dragtarget2">
<p>meter</p>
</div>
</div>
</div>

add an arrow infront and after a div

I tried to add an arrow shape to a div. i managed to add it to the end of the div but i am struggling to figure out how to add it to the front as well without using a new class. Is it possible to achieve it with only one class?
edit: my answer to the question with a different shape approach,
i think they are all 3 very useful:
.arrow {
margin-left: 100px;
position: relative;
background: pink;
width: 400px;
height: 100px;
text-align:center;
line-height:100px;
margin-bottom:10px;
}
.arrow:after {
border: solid transparent;
content: " ";
position: absolute;
border-bottom-color: white;
border-width: 50px;
left: 0;
top: 0;
transform: rotate(90deg);
}
.arrow:before {
border: solid transparent;
content: " ";
position: absolute;
border-bottom-color: pink;
border-width: 50px;
left: 400px;
top: 0;
transform: rotate(90deg);
}
<div class="arrow">
1
</div>
<div class="arrow">
2
</div>
You will need an inner element. What that element is, is purely up to you. Here I've used a <span> to make the left arrow appear.
.arrow {
float: left;
width: 128px;
height: 50px;
background-color: white;
border: 1px solid green;
position: relative;
margin-right: 40px;
text-align: center;
border-left: none;
}
.arrow:after,.arrow span:after {
content: '';
position: absolute;
top: 0px;
left: 128px;
width: 0;
height: 0;
border: 25px solid transparent;
border-left: 12px solid white;
z-index: 2;
}
.arrow:before,.arrow span:before {
content: '';
position: absolute;
top: 0px;
left: 129px;
width: 0;
height: 0;
border: 25px solid transparent;
border-left: 12px solid green;
z-index: 1;
}
.arrow span:after {
left: 0;
}
.arrow span:before {
left: 1px;
}
<div class="arrow"><span></span>1</div>
<div class="arrow"><span></span>2</div>
<div class="arrow"><span></span>3</div>
<div class="arrow"><span></span>4</div>
<div class="arrow"><span></span>5</div>
I have modified chevron shape, from this page: https://css-tricks.com/examples/ShapesOfCSS/ (borrowed idea, credits to mr Anthony Ticknor:))
.chevron {
position: relative;
text-align: center;
height: 60px;
width: 260px;
line-height:60px;
margin-bottom:10px;
}
.chevron:before {
content: '';
position: absolute;
top: 0;
left: 3%;
height: 50%;
width: 100%;
transform: skew(25deg, 0deg);
border:1px solid red;
border-bottom:none;
}
.chevron:after {
content: '';
position: absolute;
top: 50%;
left: 3%;
height: 50%;
width: 100%;
transform: skew(-25deg, 0deg);
border:1px solid red;
border-top:none;
}
<div class="chevron">1</div>
<div class="chevron">2</div>
So, one div, and two pseudo-elements, properly scewed, with borders hidden, where needed.

Link/button is going off of the box i made for it

I made a link/button named Friends and when I re-size my window it goes out of the box I made for it. I have tried adding margins and padding but that didn't help me. Every thing I do still makes it go out of the box.
body {
background-color: black;
}
.Forum-Block {
position: absolute;
border-radius: 5%;
left: 10%;
top: 0%;
width: 70%;
height: 140%;
margin: 5%;
background-color: #888888;
border-style: solid;
border-width: medium;
border-color: orange;
}
.Top-Bar {
position: absolute;
top: 8%;
left: 5%;
width: 90%;
height: 6%;
background-color: black;
}
.welcome-msg {
position: absolute;
top: 30%;
left: 2%;
}
.friends-box {
position: relative;
top: 0%;
left: 90%;
width: 10%;
height: 100%;
color: white;
background-color: black;
}
.friends-box:hover {
position: absolute;
top: 0%;
left: 90%;
width: 10%;
height: 100%;
background-color: #262626;
}
try this
.friends-box {
position: relative;
top: 0%;
right:2%;
width: 15%;
height: 100%;
color: white;
font-size:100%;
background-color: black;
}
.friends-box:hover {
background-color: #262626;
}
You should work to a grid as well - make the .welcome-msg{width:75%;left:0;} and the .friend-box{width:25%;right:0}
Wrap the text with tags, Welcome in H1, h2, or h4, and the friends in a p tag maybe and add padding to that instead.
Hope this helps.
I just added floats and removed the position:absolute and position:relative... I also set the height of the Top-Bar to auto so that it takes the height of the content inside. I changed the background colors so you can see what is happening. Hope this helps!
<style type="text/css">
body {
background-color: black;
}
.Forum-Block {
position: absolute;
border-radius: 5%;
left: 10%;
top: 0%;
width: 70%;
height: 140%;
margin: 5%;
background-color: #888888;
border-style: solid;
border-width: medium;
border-color: orange;
}
.Top-Bar {
position: absolute;
top: 8%;
left: 5%;
width: 90%;
height:auto;
background-color: black;
}
.welcome-msg {
float:left;
color: #FFFFFF;
padding:10px;
background: red;
}
.friends-box {
float:right;
color: white;
background-color: green;
padding:10px;
}
.friends-box:hover {
background-color: #262626;
}
</style>
<div class="Forum-Block">
<div class="Top-Bar">
<div class="welcome-msg">Hello, Admin</div>
<div class="friends-box">Friends</div>
</div>
</div>