Style Bottom Center Point of Div as Triangle - html

Here's what I have so far:
.buck-knives-inner-nav {
display: flex;
border: 1px solid #707070;
}
.buck-knives-inner-nav-tab {
text-align: center;
padding: 10px;
width: 100px;
}
.buck-knives-inner-nav-tab:not(:last-child) {
border-right: 1px solid #707070;
}
.active {
background-color: #0B0E55;
color: #ffffff;
}
/*
.active::after {
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-top: 20px solid #0B0E55;
}*/
<div class="buck-knives-inner-nav">
<div class="buck-knives-inner-nav-tab active">
Hold Old is My Knife?
</div>
<div class="buck-knives-inner-nav-tab">
Knife Sharpening
</div>
<div class="buck-knives-inner-nav-tab">
Safety Tips
</div>
<div class="buck-knives-inner-nav-tab">
Knife Care
</div>
<div class="buck-knives-inner-nav-tab">
Choosing the Right Knife
</div>
<div class="buck-knives-inner-nav-tab">
Buck's Forever Warranty
</div>
</div>
I'm wondering - is it possible to style the active tab differently so that it points downward at the bottom center, like I have it in the following mockup?
I tried to implement the downward-facing triangle effect that's used in this article:
https://css-tricks.com/snippets/css/css-triangle/
adding it as an ::after to the active tab - so why didn't that have any effect?
.active::after {
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-top: 20px solid #0B0E55;
}
Also tried something similar - what I found here: Center Triangle at Bottom of Div
All other ideas / suggestions are welcome!

You were missing the position on the after element.
I've added a position: relative; on the buck-knives-inner-nav-tab and some more positioning on the after:
content: "";
position: absolute;
top: 100%;
left: 0;
right: 0;
margin: 0 auto;
.buck-knives-inner-nav {
display: flex;
border: 1px solid #707070;
}
.buck-knives-inner-nav-tab {
text-align: center;
padding: 10px;
width: 100px;
position: relative;
}
.buck-knives-inner-nav-tab:not(:last-child) {
border-right: 1px solid #707070;
}
.active {
background-color: #0B0E55;
color: #ffffff;
}
.buck-knives-inner-nav-tab.active:after {
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-top: 20px solid #0B0E55;
content: "";
position: absolute;
top: 100%;
left: 0;
right: 0;
margin: 0 auto;
}
<div class="buck-knives-inner-nav">
<div class="buck-knives-inner-nav-tab active">
Hold Old is My Knife?
</div>
<div class="buck-knives-inner-nav-tab">
Knife Sharpening
</div>
<div class="buck-knives-inner-nav-tab">
Safety Tips
</div>
<div class="buck-knives-inner-nav-tab">
Knife Care
</div>
<div class="buck-knives-inner-nav-tab active">
Choosing the Right Knife
</div>
<div class="buck-knives-inner-nav-tab">
Buck's Forever Warranty
</div>
</div>

Related

How to get triangle layout without using "polygon"

How to get triangle layout of 'mission' section within the container only without using "polygon". I don't want it to flow outside the container.
You can make triangles using border property of css.
Check out this link for more shapes : https://css-tricks.com/examples/ShapesOfCSS/
.container {
position: relative;
}
.mission {
position: absolute;
width: 0;
height: 0;
border-left: 0px solid transparent;
border-right: 100px solid transparent;
border-top: 150px solid red;
border-bottom: 0px solid transparent;
}
.mission + div {
position: absolute;
}
.content {
position: absolute;
width: 350px;
height: 200px;
background: lightgrey;
padding-left: 100px;
}
<div class="container">
<div class="content">
Content
</div>
<div class="mission">
</div>
<div>
Mission
</div>
</div>

Mail icon using HTML and CSS

I'm trying to create an email icon in CSS. Is this the right way to code as UI or Front-end Developer?
Check out my Codepen here.
.container {
border-left: 10px solid #80BD9E;
border-right: 10px solid #80BD9E;
background: #F98886;
height: 500px;
width: 500px;
margin: 10% auto;
border-radius: 6px;
}
.arrow-down {
width: 0;
height: 0;
border-left: 250px solid transparent;
border-right: 254px solid transparent;
border-top: 250px solid #80BD9E;
}
.arrow-down1 {
top:22%;
left:25.5%;
width: 0;
height: 0;
border-left: 250px solid transparent;
border-right: 254px solid transparent;
position: absolute;
border-top: 250px solid #f98886;
border-radius:6px;
}
.topLayer {
background: #fff;
position: absolute;
width: 505px;
height: 100px;
margin-left: 24.5%;
margin-top: -9.9%;
z-index: 1;
}
<div class="topLayer">
</div>
<div class="container">
<div class="arrow-down">
<div class="arrow-down1">
</div>
</div>
</div>
Try this. I needed it to embed in an email because imaging is so restrictive:
check it out in action (jsfiddle)
SCSS: size should scale and color will change with a change of the variables
$mail-size: 50;
$letter-color: white;
$letter-accent-color: gray;
.container{
border: $mail-size * .06 + px solid $letter-accent-color;
background-color: $letter-color;
height: $mail-size * 1.4 + px;
width: $mail-size * 2 + px;
border-radius:6px;
}
.arrow-down {
border-left: $mail-size + px solid transparent;
border-right: $mail-size + px solid transparent;
border-top: $mail-size + px solid $letter-accent-color;
}
.arrow-down1 {
margin-top:-$mail-size * 1.008 + px;
margin-left: -$mail-size * .92 + px;
border-left: $mail-size * .92 + px solid transparent;
border-right: $mail-size * .92 + px solid transparent;
border-top: $mail-size * .92 + px solid $letter-color;
border-radius:0px;
}
html
<div class="container">
<div class="arrow-down">
<div class="arrow-down1">
</div>
</div>
</div>
as it turns out, this will not work in email templates either lol
Cool to see that you're trying to be creative with html&css. Like suggested before me it is probebly best/easiest to just use fontAwesome, Material Icons or Bootstrap Icons.
But if you do make icons yourself try to use a 'container-div' with position: relative and all the elements of your icon position: absolute. Right now the email does not render the right way:
Delete the third box. After that this looks fine.
.container {
border-left: 10px solid #80BD9E;
border-right: 10px solid #80BD9E;
background: #F98886;
height: 500px;
width: 500px;
margin: 10% auto;
border-radius: 6px;
}
.arrow-down {
width: 0;
height: 0;
border-left: 250px solid transparent;
border-right: 254px solid transparent;
border-top: 250px solid #80BD9E;
}
.topLayer {
background: #fff;
position: absolute;
width: 505px;
height: 100px;
margin-left: 24.5%;
margin-top: -9.9%;
z-index: 1;
}
<div class="topLayer">
<div class="container">
<div class="arrow-down">
</div>
</div>
</div>
But it's easier to use Font Awesome: http://fontawesome.io/

how to dispaly name, current time in message chat box

We developed chat application looks like watts-app. we finished everything but i want to show name and current time in chat message box. how to do that
requirement screen shot
.left {
position: relative;
background: white;
text-align: right;
padding: 10px 15px;
border-radius: 6px;
border: 1px solid #ccc;
float: right;
right: 20px;
}
.left::before {
content: '';
position: absolute;
visibility: visible;
top: -1px;
right: -10px;
border: 10px solid transparent;
border-top: 10px solid #ccc;
}
.left::after {
content: '';
position: absolute;
visibility: visible;
top: 0px;
right: -8px;
border: 10px solid transparent;
border-top: 10px solid white;
clear: both;
}
div{
clear: right;
}
<div class="left">
<p style="margin-top: 0px;margin-bottom: 0px;color:green;font-size: 11px;">Kranti</p>
<span>thanks</span>
<p style="float: left;margin-bottom: 0px;color:red;font-size: 11px;">2:33 PM</p>
</div>
You could create multiple span elements with their own classes and style the username and time to their position.
Use absolute positioning to get the styling as your provided image.
Here you go: https://jsfiddle.net/keqh0cqw/1/
An example of your new html:
<div class="right">
<span class="username">kranthi</span>
<span class="message">thanks</span>
<span class="time">12:08</span>
</div>

2 separate css classes applied to 1 element

I have a wordpress page, and I would like to add a bottom border to the post, according to the post category.
If post has only 1 category, then I use:
.category-daily {
border-bottom: red solid 3px;
}
But there are posts who have 2 categories, and therefore 2 classes, for example: category-weekly and category-daily
What can I do to add a red bottom border for daily category and after that add a yellow bottom border for weekly category
Elements cannot have two borders..but you can fake it with a pseudo-element.
body {
text-align: center;
}
div {
height: 100px;
width: 150px;
display: inline-block;
box-shadow: inset 0 0 1px 0 black;
/* for demo purposes only */
padding-bottom: 6px;
position: relative;
}
.category-daily:after {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 0;
border-bottom: red solid 3px;
}
.category-weekly:after {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 0;
border-bottom: yellow solid 3px;
}
.category-daily.category-weekly:after {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 0;
border-top: red solid 3px;
border-bottom: yellow solid 3px;
}
<div class="category-daily"></div>
<div class="category-weekly"></div>
<div class="category-daily category-weekly"></div>
There is no possibility to define more than one border bottom.
If you wish to achive such visual result you have to add an extra element for each category you're applying.
For example with div element for each category:
html
<div class="post">
<div class="daily"></div>
<div class="weekly"></div>
</div>
css
.post .daily{
background:red;
height:1px;
width:100%;
}
.post .weekly{
background:yellow;
height:1px;
width:100%;
}
Or even better: a hr for each category
html
<div class="post">
<hr class="daily"/>
<hr class="weekly" />
</div>
css
.post .daily{
background-color:red;
color:red;
border:0;
height:1px;
}
.post .weekly{
background-color:yellow;
color:yellow;
border:0;
height:1px;
}
One option is to use box-shadow for the other border, like this:
.daily {
border-bottom: 3px solid red;
}
.weekly {
box-shadow: 0 3px 0 yellow;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="daily">This is daily</div>
<div class="daily">This is daily</div>
<div class="weekly">This is weekly</div>
<div class="daily">This is daily</div>
<div class="daily weekly">This is daily and weekly</div>
<div class="weekly">This is weekly</div>
<div class="daily">This is daily</div>
</body>
</html>
You can't have two border-bottoms, but if you're comfortable with jquery, this may work for you:
$('.category-daily.category-weekly').wrap('<div class="bbottom"></div>');
div{
width: 60px;
height: 60px;
}
.category-daily.category-weekly {
border: 1px solid black;
border-bottom: 9px solid red;
}
.category-daily{
border: 1px solid black;
border-bottom: 9px solid red;
}
.category-weekly {
border: 1px solid black;
border-bottom: 9px solid yellow;
}
.bbottom{
padding-bottom: 9px;
border-bottom: 9px solid yellow;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<div class='category-daily category-weekly'>
</div>
<br>
<div class='category-daily'>
</div>
<br>
<div class='category-weekly'>
</div>
This wraps a div with both classes with another div which contains the secondary border-bottom.

CSS arrow. Only a portion of the arrow is being displayed

I am trying to display a few words inside of a CSS styled arrow. I have figured out how to create an arrow with CSS which works fine. however, when I place the arrow within <h2>, complete arrow is not being displayed.
The source code is as follows
HTML
<div style="background-color: yellow;">
<h2><span style="background: green;">This is what I want</span><span class="arrow-right"></span><span style="margin-left: 50px;">is this what you want?</span></h2>
</div>
STYLE
<style>
.arrow-right::after{
content: "";
width: 0;
height: 0;
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
border-left: 15px solid green;
}
</style>
The output is as follows
The arrow pointer is not being displayed completely. Am I using the elements wrongly? I will need the div / h2 height to be bigger later, but at least that is not my concern right now since the arrow itself is not being displayed as desired.
Edit:
Sorry for my bad drawing. This sample below is what I want but of course the arrow would be lots nicer I just used paints to give it a quick draw.
Is this what you're looking for?
http://jsfiddle.net/61tc5em9/2/
HTML
<div id="container">
<div id="arrow">text text text</div>
<div id="content">text text text text</div>
</div>
CSS
#container {
height: 75px;
background-color: black;
position: relative;
white-space: nowrap;
}
#arrow {
width: 30%;
background-color: red;
text-align: center;
font-size: 1.5em;
line-height: 75px;
}
#arrow::after {
content: "";
border-top: 37px solid transparent;
border-bottom: 38px solid transparent;
border-left: 50px solid red;
position: absolute;
left: 30%;
}
#content {
color: yellow;
font-size: 1.5em;
position: absolute;
left: 50%;
top: 25px;
}
Hope this helps. Let me know if you need any changes.
You need font-size:0; for the arrow.
.arrow-right::after {
content: "";
width: 0;
height: 0;
border-top: 30px solid transparent;
border-bottom: 30px solid transparent;
border-left: 30px solid green;
font-size: 0;
position: relative;
top: -8px;
}
span{
display: inline-block;
}
<div style="background-color: yellow;">
<h2><span style="background: green;">This is what I want</span><span class="arrow-right"></span><span style="margin-left: 50px;">is this what you want?</span></h2>
</div>
Recommendations for improving your code and make it more dynamic:
Use :after in the statement element itself (this way you will avoid
the extra code in html and you can position the arrow relative to the element).
Align it to the right using left: 100% (so it is always position to
the right regardless of the width of the arrow).
Use top: 50% and margin-top: -(height/2)px to center it vertically.
Just like this:
.wrapper {
padding: 2px 0;
background: yellow;
}
.statement {
position: relative;
background: green;
}
.statement:after {
content:"";
border-top: 15px solid transparent; /*change the border width to set the desired hieght of the arrow*/
border-bottom: 15px solid transparent;
border-left: 15px solid green; /*change the border width to set the desired width of the arrow*/
position: absolute;
left: 100%;
top: 50%;
margin-top: -15px; /*the element has height= 30px (border-top + border-bottom) to center it -height /2 */
}
h2{
margin: 0;
}
<div class="wrapper">
<h2>
<span class="statement">This is what I want</span>
<span style="margin-left: 50px;">is this what you want?</span>
</h2>
</div>
Note that in this way you have a more semantic code because you don't have dummy element in your html and if you want more statement it will put the arrow behind automatically like this:
.wrapper {
padding: 2px 0;
background: yellow;
margin-bottom: 10px;
}
.statement {
position: relative;
background: green;
}
.statement:after {
content:"";
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
border-left: 15px solid green;
position: absolute;
left: 100%;
top: 50%;
margin-top: -15px; /*the element has height= 30px (border-top + border-bottom) to center it -height /2 */
}
h2{
margin: 0;
}
<div class="wrapper">
<h2>
<span class="statement">One statement</span>
<span style="margin-left: 50px;">Good</span>
<span class="statement">Two statement</span>
<span style="margin-left: 50px;">Great</span>
</h2>
</div>
<div class="wrapper">
<h2>
<span class="statement">Where is the arrow?</span>
<span style="margin-left: 50px;">Do not worry about it</span>
</h2>
</div>