Making border appear at the top - html

I wrote code to make border appear at the top of the website but the border appears on all 4 sides of the code. Please correct me. JSFiddle.
#box1{
height: 50px;
background-color:#DFE4E6;
padding: 20px;
border-style: solid;
border-top: thick single #000;
}
.center{
text-align: center;
}
<div id="box1">
<h3 class="center"> CALL US</h3>
</div>

That is because of:
the rule border-style: solid.
Remove that:
border-style: solid; /* -- remove this */
border-top: thick solid #000; /* make the style solid here */
border-style applies to all borders. You need to keep your style limited to border-top.
single is not a style. You probably meant solid here.
Fiddle: http://jsfiddle.net/abhitalks/jpo80bjr/3/
#box1{
height: 50px;
background-color:#DFE4E6;
padding: 20px;
border-top: thick solid #000;
}
.center{ text-align: center; }
<div id="box1">
<h3 class="center"> CALL US</h3>
</div>

Try to define the other borders to 0px, like:
#box1{
height: 50px;
background-color:#DFE4E6;
padding: 20px;
border-style: solid;
border-top: thick single #000;
border-bottom:0;
border-left:0;
border-right:0;
}
.center{
text-align: center;
}
<div id="box1">
<h3 class="center"> CALL US</h3>
</div>

You can either write three separate properties:
border-width: ..;
border-style: ..;
border-color: ..;
Or you can combine them into one shorthand property:
border: .. .. ..;
border-style is equivalent to setting the style in border, it applies to all sides. If you just want to set the top border style, there's border-top-style for that. But since you're setting the border-top shorthand property anyway, just get rid of border-style.

That's because you set border-style: solid; which applies to all four borders (top, right, bottom, left) and defaults to black and ~4px. Also, single isn't a valid border value.
Try this:
#box1{
height: 50px;
background-color:#DFE4E6;
padding: 20px;
border-top: thick solid #000;
}

fix your css. some browser auto complete css proporties you did not specify, based on those you did, like border, in your case:
#box1{
height: 50px;
background-color:#DFE4E6;
padding: 20px;
border-style: solid;
border-color: #000;
border-width: thick 0 0 0;
}
.center{
text-align: center;
}
<div id="box1">
<h3 class="center"> CALL US</h3>
</div>

Remove border-style: solid; because you are already using in border-top: thick solid #000; and single needs to be solid.
use css:
#box1{
height: 50px;
background-color:#DFE4E6;
padding: 20px;
border-top: thick solid #000;
}
find fiddle demo

Change border-style: solid; to border-top-style: solid;
JSFiddle
#box1
{
height: 50px;
background-color:#DFE4E6;
padding: 20px;
border-top-style: solid;
border-top: thick single #000;
}
.center
{
text-align: center;
}
<div id="box1">
<h3 class="center">CALL US</h3>
</div>

Related

I want my borders of my divs to overlap completely, but get weird staggering when I align them with flex

A big beginner here, but I am trying to align my divs in rows so that the border design doesn't get overly thick where they touch.
For some reason I can't use the pre to write the html so I will write it in plain text.
.site {
display: flex;
flex-direction: row;
height: 100%;
width: 100%;
align-items: stretch;
}
.box1 {
background: #000000;
background: #000000;
background: #000000;
margin: 0px;
padding: 0px;
width: 55px;
height: 100%;
border: 3px solid black;
background-color: white;
}
.box2 {
background: #000000;
background: #000000;
background: #000000;
margin: -3px;
padding: 0px;
width: 730px;
height: 100%;
border: 3px solid black;
background-color: white;
}
<div class="site">
<div class="box1">Box 1</div>
<div class="box2">Box 2</div>
</div>
I haven't gotten to that point yet, but I also want the entire .site to have a 3 px black border around it. I basically want a .site with a 3 px black border, and 3 px dividers between the different components.
I have prepared a small code for you. You can choose any one out of the two snippets.
Case 1: 3px border for your .site class, as well as neat and clean div to differentiate between the .site class and the two divs within.
.site, .box1, .box2{
display: flex;
padding:7px;
border:3px solid black;
}
<div class="site">
<div class="box1">Box 1</div>
<div class="box2">Box 2</div>
</div>
Case 2: Slightly border change, but as per your need, 3px border for your .site class will remain same in this case as well.
.site{
display:flex;
border:3px solid black;
padding: 5px;
}
.box1, .box2{
border: 3px solid black;
}
<div class="site">
<div class="box1">Box 1</div>
<div class="box2">Box 2</div>
</div>
Hope this helps.
Try below CSS for box2:
.box2{
background: #000000;
background: #000000;
background: #000000;
padding: 0px;
width: 730px;
height: 100%;
border: 3px solid black;
border-left: 0;
background-color: white;
}
For the entire site to have a border, you can give your <body> a border.
For your elements, have you tried giving the relevant sides a border of just 1.5px?

when I created border on css and I put the link into that border but it's over border

I created class border for a link and put the link into that border. Then when I see by responsive device link is over length form that border while I try to keep sentence into border it has no problem.
How can I resolve it?
My CSS:
.border {
border: 1px solid #cc0000;
border-radius: 8px;
width: 100%;
padding: 5px;
}
You probably used an element with display: block as a host of your .border class:
.border {
border: 1px solid #cc0000;
border-radius: 8px;
width: 100%;
padding: 5px;
}
<div class="border">
Google
</div>
<div>'s default display value is block, hence full width.
What you need is using an element with display: inline:
.border {
border: 1px solid #cc0000;
border-radius: 8px;
width: 100%;
padding: 5px;
}
<span class="border">
Google
</span>
Or, simply add display: inline to your .border styles:
.border {
border: 1px solid #cc0000;
border-radius: 8px;
width: 100%;
padding: 5px;
display: inline; /* <---- */
}
<div class="border">
Google
</div>

Border top and bottom without triangle cut

I need to create two Horizontal line and between them there is a centered word.
I create this code:
html:
<div class="myRow">preference</div>
css:
.myRow
{color:red;
text-align:center;
border-style:solid;
border-width:medium;
border-color:#b2b2ac white #b2b2ac white;}
Unfortunately, the top border and bottom border are not straight at the ends.
How can I get the perfect rectangle border on the top and bottom of the box?
Borders meet at angles. The angle at which they meet is determined by the relative sizes of each border. If they are equal width, the angle is 45 degrees...if the aren't the same the angle is different.
Example:
.box {
width: 50px;
height: 50px;
margin: 10px 25px;
background: lightblue;
display: inline-block;
}
.large {
border-top: 50px solid red;
border-left: 50px solid green;
}
.medium {
border-top: 50px solid red;
border-left: 10px solid green;
}
<div class="box large"></div>
<div class="box medium"></div>
So, to have a square end, one of the widths needs to zero. In your case as this is needed at both ends, change the side border widths to 0.
.myRow {
color: red;
text-align: center;
border-style: solid;
border-width: medium 0;
border-color: #b2b2ac white;
width: 80%;
margin: 1em auto;
}
<div class="myRow">preference</div>
You can remove the border-left and border-right as below.
.myRow {
color: red;
text-align: center;
border-style: solid;
border-width: medium;
border-color: #b2b2ac white #b2b2ac white;
border-left: none;
border-right: none;
}
<div class="myRow">preference</div>
Try using this below code, hope this works for you.
.myRow {
color:red;
text-align:center;
border-style:solid;
border-width:3px 0;
border-color:#b2b2ac;
}
<div class="myRow">preference</div>
try this out
.myRow {
display: table;
margin: 0 auto;
color: red;
text-align: center;
border-style: solid;
border-width: medium;
border-color: #b2b2ac;
border-left: none;
border-right: none;
}
<div class="myRow">preference</div>

Double border in CSS with gap in the middle?

Is it possible to somehow create a double border in CSS, with these 2 added customizations:
One line is slightly thicker than the other
There is a small gap between the two lines
This is the kind of border I need:
EDIT:
Guys, I cannot make any changes to my existing HTML code. I can only apply CSS for the existing HTML code. As far as you're concerned, consider I have a div named sampleDiv, and I want to apply the border on the top side of this div (see below).
Secondly, if you're using any technique other than border, please note that I only want to apply the this specialized border on the top side of my sampleDiv div.
pure CSS & Cross browser - the thickness and spacing can be customized
After your latest Edit: this is a Working Fiddle
without changing the markup, top border only.
your HTML:
<div class="sampleDiv">
some content
</div>
new CSS
.sampleDiv
{
border-top: 2px solid black;
padding-top: 1px;
}
.sampleDiv:before
{
content: '';
border-top: 1px solid black;
display: block;
width: 100%;
}
If you are allowed to change the DOM:
one line anywhere in the markup: Working Fiddle
HTML:
<div class="SpecialLine"></div>
CSS:
.SpecialLine
{
border-top: 2px solid black;
height: 2px;
border-bottom: 1px solid black;
}
full container border: Working Fiddle
HTML:
<div class="SpecialContainer">
<div class="Content">
here goes the content
<div>
</div>
CSS
.SpecialContainer
{
border: 2px solid black;
padding: 1px;
}
.Content
{
border: 1px solid black;
}
There are various ways you can have multiple borders. One way is to use box-shadow, you can specify multiple box shadows to create the effect you want.
Example
box-shadow: 0 0 0 5px black, 0 0 0 7px red;
Update
I have created a jsFiddle to show you how you can create your borders using box-shadow
Fiddle
There's not a specific property or something for this,but you can easily create one.Something like this:
html:
<div id="wrapper">
<div id="middle">put whatever you want here</div>
</div>
css:
#wrapper{
border: 3px solid black;
padding: 1px;
}
#middle{
border: 1px solid black;
}
here's a js fiddle link:
http://jsfiddle.net/roostaamir/GEqLJ/
UPDATE:
so I saw your edit,and here's the first thing that came to my mind(if you have the width of your sampleDiv this will work):
#sampleDiv
{
border-top: 3px solid black;
width: 500px; //this is an example
position: relative;
}
#sampleDiv:before
{
content: "";
display: block;
position: absolute;
top: 1px;
width: 500px;
height: 1px;
background-color: black;
}
Your div: <div class="framed" />
Simple CSS:
.framed {
border: solid 2px #ccc;
box-shadow: 0 0 0 14px #ccc;
outline: solid 8px #fff;
}
Demo Fiddle: http://jsfiddle.net/uRFsD/
The easiest way to do this would be wrapping the main div in a container div for the second line like so:
.inner {
border: 2px solid #000;
}
.outer {
border: 1px solid #000;
padding: 1px;
}
It's not particularly semantic but it's an easy way to get the job done. You could also use border-image if being semantic is important, but it's more complicated. I guess you could also use both border (inner) and outline (outer) on the same div, but that is not ideal since outline isn't technically part of the box model at all as far as I understand it.
HTML
<div></div>
<div></div>
CSS :
div{
display: block;
background-color: #000;
}
div:nth-child(1){
padding: 2px 0;
}
div:nth-child(2){
margin-top: 1px;
padding: 1px 0;
}
Check this fiddle
May be something like below:
div {
border-top: 3px solid #00f;
position: relative;
z-index: 10;
margin: 10px;
width: 200px;
}
div:before {
content: "";
border-top: 1px solid #f00;
position: absolute;
top: 0;
left: 0;
right:0;
z-index: -1;
}
http://jsbin.com/iWiGEzU/1/edit?html,css,output
Like
demo
css
.outline {
border-top: 2px solid #000;
border-bottom:1px solid #000;
height:3px;
}
CSS
.doubleBorder
{
border: 4px solid black;
padding: 2px;
}
.doubleBorder>div {
border: 2px solid black;
}
HTML
<div class="doubleBorder">
<div>
<p>Hello</p>
<p>World</p>
</div>
</div>
Working demo
Not in pure CSS as far as I know. Instead you could add in a div element to your HTML, set its width to the one below it and set it's border-top, thickness, margin properties to be meet your thicker border requirement.

set css border to end in a 90 instead of a 45 degree angle

I have a div with different colors for both the border-bottom and border-right properties.
So they are separated via a line leaving the box in a 45 degree angle.
How can I make the bottom-border shorter so that the right border goes all the way to the bottom of the element which would yield a 90 degree angle separator-line?
You can do this with box-shadow.
Demo:
Output:
CSS:
#borders {
border-bottom: 20px solid black;
box-shadow: 20px 0 0 0 red;
height: 150px;
margin: 30px;
width: 150px;
}
HTML:
<div id="borders"></div>
I solved this issue using border-width. You simply reduce the width of the border at the edges you don't want to see.
If we don't want the border on the upper edge, we can put border-width to 0.
border-width: 0px 5px 5px 5px;
border-color:#ddd #000 #000 #000;
Sad fact: Border corners are mitered. Always. (It's only visible if using different colors.)
In order to simulate a butt joint, you can stack two divs to get a simulated result:
div {
position: absolute;
left: 0;
top: 0;
height: 100px;
width: 100px;
}
<div style="border-left: 2px solid #ff0000; border-bottom: 2px solid #ff0000;">
</div>
<div style="border-right: 2px solid #00ff00; border-top: 2px solid #00ff00;">
</div>
Stack more or control the top and bottom differently for better control over the appearance of the joint.
For the top border and the bottom border, you can use box-shadow:
.box {
border: 10px solid #ddd;
border-top: 0;
border-bottom: 0;
box-shadow: 0 10px 0 #D03FBE, 0px -10px 0 #D03FBE;
float: left;
width: 100px;
height: 100px;
}
<div class="box"></div>
What you are seeing is that borders on different sides will split diagonally around the corner:
.border {
border: 10px solid;
border-top-color: forestgreen;
border-right-color: gold;
border-bottom-color: steelblue;
border-left-color: firebrick;
width: 40px;
height: 40px;
}
<div class="border"></div>
This is a behavior many use to create CSS triangles
To overcome this I can find 2 solutions: borders on a wrapper element, or linear gradients:
Option 1: Wrapper elements
.wrapper {
border-bottom: 10px solid steelblue;
height: 40px;
width: 50px;
}
.border {
border-right:10px solid gold;
height: 40px;
width: 40px;
}
<div class="wrapper">
<div class="border"></div>
</div>
Note how the wrapper element has height of 5px more then the child. This is essential for the borders to align.
Option 2: Linear Gradients
.border {
border-bottom: 10px solid;
border-right: 10px solid;
border-image: linear-gradient(to top, steelblue, steelblue 10px, gold 5px, gold) 10;
height: 40px;
width: 40px;
}
<div class="border"></div>
If you're looking for square ends on your borders, you can set two of the borders to 0px and then run a dummy animation like so :
#keyframes widthSet {
to{
border-right-width: 10px; //or top and bottom, your choice
border-left-width: 10px;
}
}
with animation-fill-mode: forwards;
You can't.
For 90˚ angles you could just use colored divs.
You could get a similar effect for arbitrary angles by using skew transitions and absolute positioning, but it will be hard (if not impossible) to get it to look the same in older browsers (IE8 and lower will particular be a problem).