Create a CSS design that features a top border tip

I have been attempting to create a CSS tip.

While I have had some success, the issue arises when the width of the DIV changes, causing the tip to sometimes not be centered.

My Desired Outcome:

The Code I Have Implemented:

.logo {
    color: #000;
    font-size: 1.4em;
    text-align: center;
    padding-top: 1.5em;
    text-transform: uppercase;
    position: relative;
}

.line {
  height: 1px;
  overflow: hidden;
  background: #000;
}

.line.top,
.line.bottom {
  width: 90%;
}

.line.top {
  margin: 0 auto 4px;
}

.line.bottom {
  margin: 4px auto 0;
}

.angle {
  position: absolute;
  top: 19px;
  left: 46%; // I think my problem is here!
}

.angle .line.left,
.angle .line.right {
  width: 20px;
}

.angle .line.left {
  -ms-transform: rotate(45deg);
  -webkit-transform: rotate(45deg);
  transform: rotate(45deg);
  margin: 7px;
}

.angle .line.right {
  -ms-transform: rotate(-45deg);
  -webkit-transform: rotate(-45deg);
  transform: rotate(-45deg);
  margin: -7px;
}
  
<div class="logo">
  <div class="angle">
    <div class="line left"></div>
    <div class="line right"></div>
  </div>
  
  <div class="line top"></div>
  
  MY TEXT
  
  <div class="line bottom"></div>
</div>

How can I address this issue?

I have considered setting .angle width: 30px and margin: 0 auto, however, since it has position: absolute, this approach is not feasible.

Note: LESS can also be utilized in this scenario.

Answer №1

Instead of cluttering your markup with unnecessary elements, simplify by using the .logo element and its pseudo classes. Utilize the letter-spacing CSS property to adjust the spacing between letters. If possible, specify the exact font for a consistent look.

CSS

.logo {
    color: #000;
    font-size: 1.4em;
    text-align: center;
    height: 2em;
    margin-top: 2em;
    letter-spacing: 1em;
    text-transform: uppercase;
    line-height: 2em;
    position: relative;
    border-top: 1px solid #000;
    border-bottom: 1px solid #000;
}
.logo::after, .logo::before {
    content:"";
    border-width: 20px;
    border-style: solid;
    position: absolute;
    left: 50%;
    bottom: 100%;
    transform: translateX(-50%);
}
.logo::after {
    border-width: 18px;
    margin-bottom: 1px;
    border-color: transparent transparent white transparent;
}
.logo::before {
    border-color: transparent transparent black transparent;
}

See it in action - CSS version

See it in action - SCSS version

Answer №2

Triangles Within Triangles!

.outer {
    border: 40px solid transparent;
    border-bottom: 40px solid black;
    width: 0;
    height: 0;
    position: relative;
    margin: 0 auto;
}
.inner {
    border: 36px solid transparent;
    border-bottom: 36px solid white;
    width: 0;
    height: 0;
    position: absolute;
    top: -32px;
    left: -36px;   
}
<div class="outer">
    <div class="inner"></div>
</div>

Answer №3

If you want to create a unique design, consider rotating a div element and adding a border to it. By adjusting the z-index property, you can place this rotated div behind another div that acts as a container for your text. Here's an example of how you could achieve this effect:

<!DOCTYPE html>
<html>
<head>
<style>
html{padding: 10px;}
.triangle {
        width: 10%;
        height: 10%;
        -webkit-transform: rotate(45deg);
        -moz-transform: rotate(45deg);
        -o-transform: rotate(45deg);
        -ms-transform: rotate(45deg);
        transform: rotate(45deg);
        z-index: -1;
        border-top: 1px solid black;
        border-left: 1px solid black;
        position: absolute;
        top: 20px;
        left: 45%;
    }
    .textBox {
        height: 40px;
        border-top: 1px solid black;
        border-bottom: 1px solid black;
        background: white;
        z-index: 2;
        text-align: center;
    }
</style>
</head>
<body>
<div class="logo">
      <div class="triangle"></div>

      <div class="textBox">
      INSERT YOUR TEXT HERE
      </div>
    </div>
</body>
</html>

Answer №4

body{
    margin-top:70px;
}
h2{
    color:#fff;
    text-align:center;
}
.custom_box {
    position: relative;
    background: #88b7d5;
    border: 4px solid #c2e1f5;
}
.custom_box:after, .custom_box:before {
    bottom: 100%;
    left: 50%;
    border: solid transparent;
    content: " ";
    height: 0;
    width: 0;
    position: absolute;
    pointer-events: none;
}
.custom_box:after {
    border-color: rgba(136, 183, 213, 0);
    border-bottom-color: #88b7d5;
    border-width: 30px;
    margin-left: -30px;
}
.custom_box:before {
    border-color: rgba(194, 225, 245, 0);
    border-bottom-color: #c2e1f5;
    border-width: 36px;
    margin-left: -36px;
}

Check out the live example here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Steps for customizing a button's look

After installing the MemberPress plugin, I noticed that when I add my custom class, the "Login" button does not change. How can I rectify this issue and ensure that everything functions correctly? Original code <div class="submit"> <input t ...

Activate Bootstrap to insert a div underneath an anchor tag

I need assistance with positioning the div content directly below the li a tag. Is there a way to accomplish this? Check out the FIDDLE $(document).ready(function() { $('.nav ul li:first').addClass('active'); $(&apos ...

Tips for Providing Real-Time Data for a Dynamic Chart in d3

I have a line chart sample from D3, and the issue I'm facing is that I need to continuously feed live data from a server at certain time intervals and use D3 to draw the chart based on this dynamic data. Despite my efforts to search for a solution, I ...

Steps to create spaces between the bootstrap cards

Just diving into Bootstrap and attempting to incorporate images as cards, I encountered a challenge where the cards were piling up one after another without any spaces between them. Below is the code snippet utilizing Bootstrap4: <body> <div class ...

I'm having trouble getting this text to align properly next to the image. Plus, I can't seem to achieve a horizontal screen alignment either

There seems to be an answer available, but I'm clearly not understanding it, so I've come here seeking further explanation and assistance. CSS can be quite complex, right? Here's a screenshot of my current project: https://i.stack.imgur.com/ ...

What causes the vertical inconsistency in ul li elements?

Can someone help me troubleshoot this HTML5 snippet? The LI elements are not aligning properly and I can't figure out why Item 1 is lower than Item 2. I need them to line up on the same level. Any suggestions would be greatly appreciated. <!DOCT ...

Hide the overlay fullscreen menu upon clicking an anchor link

I'm having trouble with Javascript, but some of you might find this easy. I found a fullscreen overlay menu on Codepen and I'm trying to figure out how to close it when clicking an anchor link. Looking for assistance with adding javascript to c ...

Discovering a CSS value using jQueryUncovering the CSS value with jQuery

Currently, I have a script that allows me to change the color of an event in a calendar to red when clicked. eventClick: function(calEvent, jsEvent, view) { $(this).css('border-color', 'red'); } Now, I want to enhance this featur ...

Positioning a Safari browser relative to a flex container

Seeking assistance with positioning elements in Safari 602.1 on iOS 10 using Bootstrap 4.1. The text isn't positioned correctly, even after auto-prefixing Bootstrap. The issue only occurs in Safari; everywhere else, it works fine and I'm at a lo ...

"Enhance Your Website with Dynamic Text Effects using JavaScript

Is there a way to continuously animate text during the loading process of an AJAX request? I've tried implementing various methods, such as using a setTimeout function or an infinite loop, but nothing seems to work for repeating the animation once it& ...

Mpdf does not support inline CSS rendering

I recently implemented Mpdf into my Symfony project using Composer. The installation process involved running the following command: composer require mpdf/mpdf Next, I included the Mpdf.php file in autoload.php. Here is an example of how to use Mpdf in ...

I'm puzzled as to why the hidden input field consistently returns the same value every time

As a beginner in php, I am facing an issue where I cannot trace the correct value of the hidden input which represents the ID of the image in the products table. Every time I try to delete an image, it always returns the ID of the last image in the product ...

Integrate a resizable sidebar on the webpage's right side that dynamically adjusts the layout

As I develop a Chrome Extension, my goal is to incorporate a sidebar into all webpages without overlapping the existing content. The sidebar should be placed beside the content, effectively reducing the width of the body of the webpage to the initial width ...

What is the best way to eliminate the space between two columns of a row in Bootstrap 5 grid system?

In my quest to achieve the grid layout illustrated in the image below https://i.sstatic.net/4hsjw.jpg .col_1{ background-color: bisque !important; height: 500px; } .col_2 { width: 300px; height: 287px; background-position: cent ...

using mathematical calculations to determine opacity levels in a set of rules

I'm attempting to multiply opacity values. I have experimented with the following: calc(@opacity * 100) @opacity-ruleset { filter:alpha(opacity= (@opacity * 100)); -moz-opacity:@opacity; opacity: @opacity; -webkit-opacity: @opacity; } Is there a wa ...

Ensure that the hover effect remains on the element that emerges from it

I am facing an issue with a list where each item has a title. Upon hovering over the title, an info box appears but disappears when moving the cursor to the box itself. The requirement is for the box to remain visible even when the cursor moves from the t ...

Issue with CSS 3 gradient compatibility in Internet Explorer 8

My CSS3 gradient button is working perfectly on all browsers except for IE8. To make it work on IE8, I am utilizing CSS3 Pie. You can see the search button in action by visiting: Upon inspecting my console, I noticed an error on this line: PIE.htc, lin ...

Incorporating a wide banner with seamless responsiveness using Bootstrap framework

I'm currently working on customizing a bootstrap template to incorporate a full-length 1200 px banner at the top, in place of the smaller 120 x 60 images/logo-company.png logo that is featured on the original website. My attempts so far have been uns ...

Hover-triggered text animation error

Hey there, I'm currently experimenting with creating an animation that involves moving text up and revealing some content when hovering over a card. It seems like everything works fine when I hover over the card, but as soon as my cursor reaches the t ...

One-of-a-kind words in place of a numeric value

Is there a way to replace numbers with unique text of my own choosing? For example, instead of 1., 2., 3., I would like to use Bla, Blabla, Blablabla. https://i.sstatic.net/kf0p4.jpg <style> #menu2 { width: 320px; } #menu2 ol { font-style: talic; f ...