CSS Border height different on each side - css

I am wondering if a border like this would be possible in pure css? There will be no content within this box, only an image within the future.
I would like to achieve this in pure CSS, with no jQuery. I have looked around and it seems it isn't really possible, however with CSS constantly evolving I was wondering if it was possible apart from using nested divs etc.
Cheers!

You can fake it. Like this jsFiddle example.
HTML
<div id="wrapper">
<div id="top"></div>
<div id="bottom"></div>
<img src="http://www.placekitten.com/200/100" />
</div>
CSS
#top, #bottom {
width: 200px;
height:50px;
position:absolute;
left:-1px;
}
#bottom {
border-left: 1px solid #f00;
border-right: 1px solid #f00;
border-bottom: 1px solid #f00;
bottom:0;
}
#top {
border-left: 1px solid #f00;
top:0;
}
#wrapper {
position:relative;
width: 200px;
height:100px;
background: #faa;
}

You can do it with only one div if you use pseudo elements. jsFiddle here
HTML:
<div id="wrapper">
<img src="http://www.placekitten.com/200/100" />
</div>
CSS:
#wrapper {
position:relative;
width: 200px;
height:100px;
background: #faa;
border-left: 1px solid #f00;
border-bottom: 1px solid #f00;
}
#wrapper::before {
content: " ";
position: absolute;
width: 100%;
height: 50%;
bottom: -1px;
right: -1px;
border-right: 1px solid #f00;
border-bottom: 1px solid #f00;
}

Just for the 'think' of it, you could also just stick a small graphic at the bottom right of a div (as a background image) and use a border on the left and bottom. Still just manipulating it via css with one small graphic but at least the height and width would be dynamic and not stuck as if using a full image.
Would also avoid A LOT of extra mark-up and css. 1 div, 1 css declaration and 1 small image.

Related

How do I add a border around a div with arrows? [duplicate]

This question already has answers here:
CSS: Make border on pure-CSS arrow
(5 answers)
Closed 7 years ago.
I have four div styles that I need to use: one with no arrows, a right arrow, a left arrow, and both right and left arrows. I want the arrowed divs to have a border surrounding them that matches the div with no arrows. These divs need to be the same exact height and width and the borders need to all match. You'll notice in my code I DO specify a border for the arrowed divs and it's the same color as the background color. I only have that as a placeholder and to make the sizes of the divs the same. I also know that the border on the arrowed divs will specify the darker color on 2-3 sides of the div and the background color on 1-2 sides of the div (and I do know how to do that).
My real question is how do I accomplish that border on just the arrow part? I'm looking for a CSS ONLY solution. I've seen solutions of adding another div and making the arrow 1px (or whatever width) larger to simulate a border but I was hoping to avoid the extra markup. I also realize there are other solutions to making the arrow itself. I'm not opposed to another arrow solution that is CSS ONLY if it helps with this border issue, or even one that works better (I didn't want to use JS to accomplish this, though I know it's possible). My CSS and sample HTML follows:
div.occurrence-wrapper {
position: relative;
margin: 0.1em 0.2em;
}
div.full {
border: 0.1em solid #88b7d5;
background-color: #c2e1f5;
position: relative;
height: 1.4em;
overflow: hidden;
}
div.flow-prev > div.full,
div.flow-next > div.full {
border-color: #c2e1f5;
}
div.flow-prev > div.full {
margin-left: 0.7em;
}
div.flow-next > div.full {
margin-right: 0.7em;
}
div.flow-prev:before,
div.flow-next:after {
content: "";
height: 0;
width: 0;
padding: 0;
margin: 0;
top: 50%;
border: solid transparent;
border-color: rgba(136, 183, 213, 0);
position: absolute;
pointer-events: none;
border-width: 0.7em;
margin-top: -0.7em;
}
div.flow-prev:before {
right: 100%;
border-right-color: #c2e1f5;
margin-right: -0.7em;
}
div.flow-next:after {
left: 100%;
border-left-color: #c2e1f5;
margin-left: -0.7em;
}
<table>
<tbody>
<tr>
<td>
<div class="occurrence-wrapper">
<div class="full">No arrows</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="occurrence-wrapper flow-prev flow-next">
<div class="full">Both arrows</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="occurrence-wrapper flow-prev">
<div class="full">Left arrow</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="occurrence-wrapper flow-next">
<div class="full">Right arrow</div>
</div>
</td>
</tr>
</tbody>
</table>
You can achieve that using a pseudo-element and transform.
div {
position: relative;
width: 150px;
height: 40px;
background: crimson;
border: 2px solid navy;
}
div:before {
content: "";
position: absolute;
height: 29px;
width: 29px;
transform-origin: 0% 0%;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
transform: rotate(45deg);
right: -33px;
top: -2px;
background: crimson;
border-top: 2px solid navy;
border-right: 2px solid navy;
}
<div></div>
FIDDLE
You can create it by becore after css....
below the HTML code is...
<div class="myDiv">This Is My Div</div>
<div class="myDiv right">This Is My Div</div>
<div class="myDiv left">This Is My Div</div>
<div class="myDiv left right">This Is My Div</div>
below the css code is...
.myDiv{
padding:5px 10px;
background:#333;
color:#FFF;
width:120px;
position:relative;
height:30px;
margin-bottom:20px;
}
.myDiv.left{
margin-left:20px;
}
.myDiv.left:before{
content:" ";
width:0px;
background:transparent;
height:0;
position:absolute;
top:0;
left:-40px;
border-right: 20px solid #333;
border-top: 20px solid transparent;
border-left: 20px solid transparent;
border-bottom: 20px solid transparent;
}
.myDiv.right:after{
content:" ";
width:0px;
background:transparent;
height:0;
position:absolute;
top:0;
right:-40px;
border-left: 20px solid #333;
border-top: 20px solid transparent;
border-right: 20px solid transparent;
border-bottom: 20px solid transparent;
}
You can visit the jsfiddle live demo.
To add a border around what appears to be an additional image (supporting transparency) to make the arrow on either side of a typical box, you need to create another image showing the border, because CSS does not handle shapes like triangles to create borders over. This only works on rectangles.

Width not expanding?

I'm working on a map project and for some reason my tooltip's text width will continue to expand as wide as I want until I add a space to my text. If I add a space, it breaks to the next line; what is going on and how do I fix this? I'd like the text on one line without specifying a width so it can automatically set the width, how can I fix this?
In the example below, look at text "Baseball Fields" in the paragraph tag. If it reads "BaseballFields" it will stay on one line. But as soon as I add the space, it will line break.
<div style="width: 750px; height: 1221px; border: 0; padding: 0; margin-top: 10px; display: block; position:relative; background: url('http://www.thefirstacademy.org/filerequest/9701.jpg') no-repeat left top;">
<style type="text/css">
.triangle {
position:absolute;
bottom:-5px;
left:40%;
height:0;
width:0;
border-left:5px solid transparent;
border-right:5px solid transparent;
border-top:5px solid white;
}
.tooltip {
color:#ef4c4c;
background:#ffffff;
padding:17 10;
display:block;
position:absolute;
border-radius:5px;
font:.8em 'MuseoSans-500','Museo Sans';
top:-40px;
box-shadow:0px 3px 3px #000;
border:1px solid #000;
}
</style>
<div class="marker" style="position:absolute;cursor:pointer;left:450px;top:75px;" id="baseball">
<img src="http://www.thefirstacademy.org/filerequest/9702.png" alt="Location Marker" />
<div class="tooltip" >
<div class="triangle"></div>
<p style="padding:0;margin:0;line-height:0;display:block;">Baseball Fields</p>
</div>
</div>
</div>
Just a heads up: in addition to white-space: nowrap; it can be helpful to include display: inline-block; for browser compatibility purposes

PNG and css borders issue

I've used Inkscape to create a very simple icon in a site I'm developing. The icon is absolutely positioned over the border of two side-by-side elements.
In Chrome it looks great:-
But in IE7 not so..:-
Am I doing something wrong? There is no transparency in the coloured part of my image, as far as I can tell.
Here's the code I'm using to display the images:-
<div class="roadmapstep">
<div class="roadmapnumber">1</div>
<h4>Header 1</h4>
<div class="nextarrow"><img src="nextarrow.png"></div>
</div>
<div class="roadmapstep">
<div class="roadmapnumber">2</div>
<h4>Header 2</h4>
<div class="nextarrow"><img src="nextarrow.png"></div>
</div>
CSS for the div containing the image is:-
.nextarrow {
position: absolute;
top: 65px;
margin-right: -35px;
right: 0;
width: 65px;
height: 40px;
}
CSS for the divs with the border:
.roadmapstep {
width: 220px;
height: 150px;
border-left: 1px solid black;
border-top: 1px solid black;
border-bottom: 1px solid black;
float: left;
position: relative;
}
Use z-index to position an image above another
Add z-index:1000; to .nextarrow
DEMO
Try giving the different class name to second div and position:absolute. it works!!
DEMO 2

CSS two column full width

So I have a website which has a header, a footer and two main content columns inbetween.
The left column is for navigation. The right one is a map. I want both to fill the width of the browser. I seem to be facing problems with different resolutions and different browsers. The map always displaces to below the footer or it leaves a white space on the right.
My link: http://www.trashvigil.com/nsdf/www/index1.php
This is my code:
#map{
float:left;
height:572px;
width:79.88%;
border-right: 2px solid #000;
border-bottom: 3px solid #000;
}
#leftnav
{
float:left;
width:250px;
height: 572px;
border-right: 3px solid #000;
border-bottom: 3px solid #000;
}
#map is the map container. #Leftnav is navigation.
Thank you,
Kaushik
You need something like this:
#map {
margin-left:250px;
height:572px;
}
#leftnav {
float:left;
width:250px;
height: 572px;
}
The idea is to float the leftnav and then set a left margin for the map that is equal to the width of the leftnav.
You can see it live here: http://dabblet.com/gist/2767788
#nav {
position:absolute;
left:0px; width:250px;
height:375px; top:50px; /* height of your top bar*/
}
#map{
margin-left:250px;
height:572px;
}
Something like this should be what you need.
<style>
#main
{
width: 900px;
overflow: hidden;
}
#leftnav
{
float: left;
}
#map
{
float: right;
}
</style>
<div id="header">
</div>
<div id="main">
<div id="leftnav">
</div>
<div id="map">
</div>
</div>
<div id="footer">
</div>
Write like this:
#map{
overflow:hidden;
height:572px;
border-right: 2px solid #000;
border-bottom: 3px solid #000;
}
#leftnav{
float:left;
width:250px;
height: 572px;
border-right: 3px solid #000;
border-bottom: 3px solid #000;
}

How do I make corners angled like this using css?

Here is an image of what I'm talking about:
Is there a way to get the corners like this using css3 or do I have to resort to images? I believe I saw a tutorial on this somewhere but I can't seem to find it.
Do you mean something like this demo fiddle?
HTML:
<div class="box">
<div class="head">
<div class="like"></div>
<h3>User927</h3>
</div>
<div class="cont">
<p>Lorem ipsum...</p>
</div>
<div class="foot">
More
</div>
</div>
CSS:
.box {
width: 310px;
position: relative;
}
.head {
background: black;
color: white;
}
.cont {
border-left: 1px solid silver;
border-right: 1px solid silver;
}
.foot {
background: lightgray;
border: 1px solid silver;
border-bottom-width: 3px;
}
.head:before,
.head:after,
.foot:before,
.foot:after {
font-size: 0px;
content: ".";
position: absolute;
}
.head:before {
border-top: 5px solid white;
border-right: 5px solid black;
left: 0;
top: 0;
}
.head:after {
border-top: 5px solid white;
border-left: 5px solid black;
right: 0;
top: 0;
}
.foot:before {
border-bottom: 7px solid white;
border-right: 7px solid transparent;
left: 0;
bottom: 0;
}
.foot:after {
border-bottom: 7px solid white;
border-left: 7px solid transparent;
right: 0;
bottom: 0;
}
Downside: for IE7 you would need extra span's in the markup because the :after and :before specifiers are not supported, see this revised fiddle.
I've had great luck with jQuery Corners:
http://malsup.com/jquery/corner/
It can do slanted corners as well as many other varieties, and works well in older browsers too:
You can do rounded corners (such as on the 28/like in the image) with CSS, but corners cut like those at the top of the container require images.
If you aren't afraid of CSS3, then dive into either border-images or multiple backgrounds. It's both css and images.
[IMPORTANT] Go for this approach if you really want to stick to CSS 2.0.
It may seem weird, but I have seen this in Google rendered pages! (that was for rounding but the same technique can be used here):
.border-line {background:blue; border:solid 3px gray; border-width: 0 3px; height:1px;}
<div class='top-border-line'></div>
<div class='border-line' style='margin:0 5px;'></div>
<div class='border-line' style='margin:0 4px;'></div>
<div class='border-line' style='margin:0 3px;'></div>
<div class='border-line' style='margin:0 2px;'></div>
<div class='border-line' style='margin:0 1px;'></div>
Got the idea? each of those divs are one single row steping backward linearly to form the "angle". and there is a top solid line above them.
This javascript library
Cross browser simplicity! Why use CSS anyway...

Resources