Add a border to the shape in CSS [duplicate] - html

Fiddle here
I'm trying to set the border color of some irregular shapes (arrowish) I did. The problem is that to achieve those shapes I had to manipulate the borders already so I can't just do border-color: red;
I want to set the color of the borders of each shape 2px
HTML:
<div class="menuTop">
<ul>
<li><div>HOME</div></li>
<li><div>Location</div></li>
<li><div><span>Sub-Location<span></div></li>
</ul>
</div>
CSS:
.menuTop {
background-color: lightgreen;
height: 80px;
margin: auto;
position: absolute;
top: 0;
width: 100%
}
.menuTop ul {
list-style-type: none;
}
.menuTop li {
font-size: 0;
display: inline-block;
}
.menuTop li:before,
.menuTop li:after {
content:'';
display: inline-block;
width:0;
height:0;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
vertical-align: middle;
}
.menuTop li:before {
border-top-color: #fff;
border-bottom-color: #fff;
border-right-color: #fff;
}
.menuTop li:first-of-type:before {
border:0;
}
.menuTop li:first-of-type {
border-left: 2px solid #dfdfdf;
}
.menuTop li:after {
border-left-color: #fff;
}
.menuTop li:last-of-type:after {
border:0;
}
.menuTop li:last-of-type {
border-right: 2px solid #F37C31;
border-bottom: 2px solid #F37C31;
border-top: 2px solid #F37C31;
}
.menuTop li div {
width: 185px;
height:40px;
display: inline-block;
background: #fff;
text-align:center;
position: relative;
line-height:40px;
vertical-align: middle;
}
.menuTop li div a, span {
text-decoration: none;
color: #bbb;
font-family: 'open sans', sans-serif;
font-weight: 400;
font-size: 13px;
}
.menuTop li div a:hover {
text-decoration: underline;
color: #000;
}
.menuTop li div span {
color: #000;
font-weight: bold;
}

CSS solution with rectangles
Here is an example that does not use triangles, but instead uses rotated rectangle.
Explanation:
First the before and after create a rotated rectangle.
Give the before rectangle the same color as the background.
After element gets the same color as the arrow.
Then we can apply borders to rectangles to give the perfect illusion of the elements having the border.
body {
background-color: #555;
}
.menu {
display: inline-block;
margin: 0;
padding: 0;
}
.menu .arrow {
position: relative;
display: inline-block;
list-style: none;
font-size: 2em;
width: 150px;
height: 70px;
background-color: white;
margin-right: 90px;
border-top: 2px solid red;
border-bottom: 2px solid red;
}
.arrow:first-of-type {
border-left: 2px solid red;
}
.arrow::after {
position: absolute;
top: 9px;
right: -25px;
content: "";
height: 50px;
width: 50px;
background-color: white;
transform: rotate(45deg);
border-right: 2px solid red;
border-top: 2px solid red;
}
.arrow::before {
content: "";
position: absolute;
top: 9px;
left: -25px;
height: 50px;
width: 50px;
background-color: #555; /*Needs to match body backgrond-color*/
transform: rotate(45deg);
border-right: 2px solid red;
border-top: 2px solid red;
}
.arrow:first-of-type::before {
content: none;
}
.arrow span {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<ul class="menu">
<li class="arrow"><span>Text</span>
</li>
<li class="arrow"><span>Text</span>
</li>
<li class="arrow"><span>Text</span>
</li>
</ul>

Related

creating active state arrow in navigationbar

I have this code in my CSS file:
.blog-nav li {
position: relative;
display: inline-block;
font-weight: 500;
}
.blog-nav li a {
color: #fff;
position: relative;
display: inline-block;
padding: 10px;
font-weight: 500;
color: #cdddeb;
}
.blog-nav li a:hover,
.blog-nav li a:focus {
color: #fff;
text-decoration: none;
}
I would like to add an arrow like this: https://getbootstrap.com/docs/3.4/examples/blog/.
I tried with this code from the basic template from bootstrap:
/* Active state gets a caret at the bottom */
.blog-nav li a .active {
color: #fff;
}
.blog-nav li a .active:after {
position: absolute;
bottom: 0;
left: 50%;
width: 0;
height: 0;
margin-left: -5px;
vertical-align: middle;
content: " ";
border-right: 5px solid transparent;
border-bottom: 5px solid;
border-left: 5px solid transparent;
}
as i saw from your code, the .active class is not a selector of anchor tag, which means the .active is a child of anchor tag, not state class, i hope i understood you well
so it should be like this
/* Active state gets a caret at the bottom */
.blog-nav li a.active {
color: #fff;
}
.blog-nav li a.active:after {
position: absolute;
bottom: 0;
left: 50%;
width: 0;
height: 0;
margin-left: -5px;
vertical-align: middle;
content: " ";
border-right: 5px solid transparent;
border-bottom: 5px solid;
border-left: 5px solid transparent;
}
read more about selectors

CSS hexagon link hover

Trying to implement a hexagon ul list using css and having issues with the hover state. Currently when hovered only the border left and right change color, I need all sides. I think the issue lies somewhere in the li hover before class but trying this doesn't work. Thanks.
ul.pagination li {
display: inline-block;
position: relative;
width: 30px;
height: 17.32px;
margin: 12px 8px;
border-left: solid 2px #d7d7d7;
border-right: solid 2px #d7d7d7;
cursor: pointer;
}
ul.pagination li:before {
top: -10.61px;
border-top: solid 2.83px #d7d7d7;
border-right: solid 2.83px #d7d7d7;
}
ul.pagination li:after, ul.pagination li:before {
content: "";
position: absolute;
width: 21.21px;
height: 21.21px;
-webkit-transform: scaleY(.5774) rotate(-45deg);
transform: scaleY(.5774) rotate(-45deg);
background-color: inherit;
left: 2.39px;
}
Fiddle is: https://jsfiddle.net/91jeee5m/
You've got the right way to do, just do the same with :before and :after state like this :
ul.pagination li:hover:after {
border-left: solid 2px #00A2C6;
border-bottom: solid 2px #00A2C6;
}
ul.pagination li:hover:before {
border-top: solid 2px #00A2C6;
border-right: solid 2px #00A2C6;
}
See it here
You need to set the border color on your :before and :after pseudo-elements as well:
ul.pagination li:hover,
ul.pagination li:hover:before,
ul.pagination li:hover:after {
border-color: #00A2C6;
}
Here is simple hexagon pagination
* {
box-sizing: border-box
}
body {
text-align: center
}
#hexagon,
#hexagon li {
position: relative
}
#hexagon{
margin-top: 40px ;
}
#hexagon li {
position: relative;
display: block;
width: 54px;
height: 30px;
float: left;
margin-right: 30px;
list-style-type:none;
}
#hexagon li,
#hexagon li:before,
#hexagon li:after{
border-left: 4px solid red;
border-right: 4px solid red;
transition: all .6s;
backface-visibility:hidden;
}
#hexagon li:before,
#hexagon li:after {
content: "";
position: absolute;
width: 46px;
height: 30px;
transform-origin: center center 0px;
}
#hexagon li:before {
transform: rotate(-60deg);
left: -4px;
bottom: 0px;
}
#hexagon li:after {
transform: rotate(60deg);
left: -4px;
bottom: 0px;
}
#hexagon li:hover,#hexagon li:hover:before,#hexagon li:hover:after {
border-left: 4px solid green;
border-right: 4px solid green;
cursor:pointer
}
<ul id=hexagon class=pagination>
<li>1
</li>
<li>2
</li>
<li>3
</li>
<li>...
</li>
</ul>

Border on custom shape

Fiddle here
I'm trying to set the border color of some irregular shapes (arrowish) I did. The problem is that to achieve those shapes I had to manipulate the borders already so I can't just do border-color: red;
I want to set the color of the borders of each shape 2px
HTML:
<div class="menuTop">
<ul>
<li><div>HOME</div></li>
<li><div>Location</div></li>
<li><div><span>Sub-Location<span></div></li>
</ul>
</div>
CSS:
.menuTop {
background-color: lightgreen;
height: 80px;
margin: auto;
position: absolute;
top: 0;
width: 100%
}
.menuTop ul {
list-style-type: none;
}
.menuTop li {
font-size: 0;
display: inline-block;
}
.menuTop li:before,
.menuTop li:after {
content:'';
display: inline-block;
width:0;
height:0;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
vertical-align: middle;
}
.menuTop li:before {
border-top-color: #fff;
border-bottom-color: #fff;
border-right-color: #fff;
}
.menuTop li:first-of-type:before {
border:0;
}
.menuTop li:first-of-type {
border-left: 2px solid #dfdfdf;
}
.menuTop li:after {
border-left-color: #fff;
}
.menuTop li:last-of-type:after {
border:0;
}
.menuTop li:last-of-type {
border-right: 2px solid #F37C31;
border-bottom: 2px solid #F37C31;
border-top: 2px solid #F37C31;
}
.menuTop li div {
width: 185px;
height:40px;
display: inline-block;
background: #fff;
text-align:center;
position: relative;
line-height:40px;
vertical-align: middle;
}
.menuTop li div a, span {
text-decoration: none;
color: #bbb;
font-family: 'open sans', sans-serif;
font-weight: 400;
font-size: 13px;
}
.menuTop li div a:hover {
text-decoration: underline;
color: #000;
}
.menuTop li div span {
color: #000;
font-weight: bold;
}
CSS solution with rectangles
Here is an example that does not use triangles, but instead uses rotated rectangle.
Explanation:
First the before and after create a rotated rectangle.
Give the before rectangle the same color as the background.
After element gets the same color as the arrow.
Then we can apply borders to rectangles to give the perfect illusion of the elements having the border.
body {
background-color: #555;
}
.menu {
display: inline-block;
margin: 0;
padding: 0;
}
.menu .arrow {
position: relative;
display: inline-block;
list-style: none;
font-size: 2em;
width: 150px;
height: 70px;
background-color: white;
margin-right: 90px;
border-top: 2px solid red;
border-bottom: 2px solid red;
}
.arrow:first-of-type {
border-left: 2px solid red;
}
.arrow::after {
position: absolute;
top: 9px;
right: -25px;
content: "";
height: 50px;
width: 50px;
background-color: white;
transform: rotate(45deg);
border-right: 2px solid red;
border-top: 2px solid red;
}
.arrow::before {
content: "";
position: absolute;
top: 9px;
left: -25px;
height: 50px;
width: 50px;
background-color: #555; /*Needs to match body backgrond-color*/
transform: rotate(45deg);
border-right: 2px solid red;
border-top: 2px solid red;
}
.arrow:first-of-type::before {
content: none;
}
.arrow span {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<ul class="menu">
<li class="arrow"><span>Text</span>
</li>
<li class="arrow"><span>Text</span>
</li>
<li class="arrow"><span>Text</span>
</li>
</ul>

bottom-right corner of border is missing?

I have borders on the left and right sides of some items in a list, but I'm getting these white gaps that I don't want, but it's only on the right side which is weird and I haven't been able to figure out what I'm doing wrong.
Any help would be great.
The code:
ul {
padding: 0;
list-style: none;
background: #f2f2f2;
}
ul li {
display: inline-block;
position: relative;
line-height: 21px;
width: 150px;
border: 1px solid white;
background: white;
}
ul li:hover {
border: 1px solid black;
}
ul li:hover ul.dropdown {
display: block;
}
ul li:hover li {
border-left: 1px solid black;
border-right: 1px solid black;
}
ul li:hover li.top {
border-top: 1px solid black;
}
ul li:hover li.bottom {
border-bottom: 1px solid black;
}
ul li a {
display: block;
padding: 8px 25px;
color: #333;
text-decoration: none;
}
ul li a:hover {
color: #fff;
background: #939393;
}
ul li ul.dropdown {
font-size: 14px;
width: 150px;
background: #f2f2f2;
display: none;
position: absolute;
z-index: 999;
left: -1px;
}
<ul style="font-size: 16px; width: 500px; margin-left: auto; margin-right: auto; margin-bottom: 0px; margin-top: 4px;">
<li><u>Products</u>
<ul class="dropdown">
<li class="top">Apples
</li>
<li>Cans
</li>
<li>Bowls
</li>
<li class="bottom">Cups
</li>
</ul>
</li>
</ul>
The style in ul li
border: 1px solid white;
is causing extra white lines to be drawn
Remove it and you should be good

Border pixels are overlapping

I cannot figure this out.
I want the colored border to overlap the grey border. However, the border refuses to overlap the bottom border.
Here's a picture:
http://gyazo.com/bc4cbaab9bfa3a173709309ad64f880e.png
The code for the borders is:
<li>
<div class="content blue-border">
<span class="icon-uniE601"></span>
</div>
</li>
.sidebar ul li {
background-color: #f2f2ea;
border-right: 1px solid #dfdfd7;
border-top: 1px solid #dfdfd7;
}
.content
{
border-left: solid 5px #0094ff;
width:100%;
height:100%;
}
.content span
{
height: 70px;
text-align: center;
line-height: 70px;
font-size: 2em;
color: #787878;
}
.sidebar ul li:hover
{
background-color: black;
}
.sidebar ul li:first-child
{
border-top: none;
}
ul li
{
list-style: none;
padding: 0;
margin: 0;
width: 100%;
height: 100%;
}
.blue-border
{
border-left: solid 5px #0094ff;
}
.orange-border
{
border-left: solid 5px #ff6a00;
}
And here's the code:
http://jsfiddle.net/bG8Wb/2/
Thanks in advance!
You can try this
element_that_needs_to_shift {
position:relative;
top:1px;
}
...
Is this what you wanted?
.sidebar ul li {
background-color: #f2f2ea;
border-right: 1px solid #dfdfd7;
/*border-top: 1px solid #dfdfd7;*/
}