Fade Border Box

I'm aiming to design a box with a unique 'highlight' effect along its sides and at the top.

The CSS for creating the box was fairly straightforward, but adding this 'highlight' has made the CSS more complex...

I've experimented with various approaches, although uncertain if they'll be effective. Here's my latest attempt:

/* Define the Main Navigation Drop Downs */
#mn_navigation .dd {position:relative;width:226px;padding:29px 0 0;background:transparent url("//beta.example.co.uk/_images/_global/dd_handle.png") no-repeat;z-index:1000;}
#mn_navigation .dd nav {padding:30px 0;background:#3E5032 url("//beta.example.co.uk/_images/_global/dd_bg.png");border-radius:3px;}
#mn_navigation .dd nav a {font-family:Arial, Helvetica, sans-serif;font-size:12px;color:#fff !important;height:25px;line-height:25px;}

Please bear in mind that I've shared the above code to demonstrate my efforts. It may not serve as a starting point due to potential restructuring required!

Here's the current HTML structure (likely needing revision):

<div id="dd_foo" class="dd">
    <nav>
        <a href="//beta.example.co.uk/menu/" title="LINK TITLE">LINK</a>
    </nav>
</div>

A possible restructuring could look like this:

<div id="dd_foo" class="dd">
    <div class="handle"><!-- Dropdown Handle --></div>
    <nav>
        <a href="//beta.example.co.uk/menu/" title="LINK TITLE">LINK</a>
    </nav>
</div>

This is the desired appearance of the box (noting the faint white border at the top and halfway down the sides):

I have also provided representations of the box broken down into individual elements (handle and background)

I believe it can be achieved using clever overlaps and nested divs, though ideally seeking an alternative solution... Any suggestions?

Answer №1

Simplest way to achieve it

To create this effect, simply use a basic box shadow:

.plaque {
    box-shadow: inset 0 1px 1px 0 rgba(255, 255, 255, 0.32);

    /*...*/
}

Illustrative Sample

Take a look at this sample involving one class and a div on jsbin.

Code for Copy-Pasting

This code is intended for modern browsers only; older versions of Internet Explorer and other unsupported browsers may not display it correctly.

.plaque:after {
  top: -9px;
  content: " ";
  height: 11px;
  width: 30px;
  position: absolute;
  pointer-events: none;
  left: 50%;
  margin-left: -15px;
  display: block;
  background-repeat: no-repeat;
}


.plaque {
  width: 250px;
  height: 100px;
  display: block;
  border: 0;
  outline: 0;
  padding: 12px 16px;
  line-height: 1.4;
  box-shadow: inset 0 1px 1px 0 rgba(255, 255, 255, 0.32);
  border-radius: 5px;
  border: 1px solid transparent;
  font-family: sans-serif;
  color: white;
  font-size: 1.2em;
  text-overflow: ellipsis;
  position: relative;
  top: 6px;
}

/* Customize with your preferred background */
.plaque { background-color: green; }

.plaque:after { background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAALCAYAAACZIGYHAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAcJJREFUeNqMUktPU0EU/mZuL6Up1RCjC4oRau4t4FJ84EKID/ZAjI9/6Mo/4MadG5dqJGjBatpyuY+2UNreeXDOBE0MNHGSSWZyzvnOd77zicdbd+EVJKyxGPSHmC4XIYSAMQYCoJhn81wJKSnHWhR8D1oZl69yhamiD8GBSefpywc2XKzjy7fP+PDuk5iUJxnksvvkxX1buxkgThOEt5exvr1qJ+XKy5CfvXpow9oSsn6GdqeF40EPK+GKY/ZfTNa3Vm1AI6TdFAeNfQgp0CKgrJehVg1AGl5gJLTWfxGfv15zI3BBnB5CehJGG5Cw8EjY6tw8KjNXsfv9K96//SguMOERgoU6+ic9NH8eQClNGzDQBMLb4FU1fzdxFB+hev0WNnbu2X802TxnkGQJoriNymwZHrFgAbhdidbOK+YTxR0ojLEc3sHmm0dOI8Gq10n9OI1xGLVcMvuGGYyHOYqlKcfK9wvOF3/i12ZvoFK+gsavPUgGSLsJkm4En4xDTqMi45iUZqZdd34zJY7L8was2enoGMHCEmS3l6LxYx9qrJ2I7FTNelBxPlKuYDgYu9nzUe6cenoygqF/J2o7AmcCDACumSjtgWp8aAAAAABJRU5ErkJggg==); }

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

Mastering the Art of Utilizing Waypoints

Having trouble with waypoints and can't seem to make it work Here is the HTML code I am using: <section class="progress center" id="progress"> <h3>Skills</h3> <div class="bars"> <div class="progressbar"> < ...

Struggling to achieve the expected outcome using PHP and AJAX

Currently, I am faced with the task of verifying whether a user-entered name is valid or not. Despite being a simple question, I am encountering difficulties with this. I have devised the following HTML and AJAX script to handle this: <script> func ...

PHP - Combining time-based events or rows into unified HTML blocks

I am faced with a challenge involving a table of 'events' each with a start and end time (both in DATETIME format). My task is to group these events for a single day so they can be displayed as a cohesive HTML block. For instance... Event #1: L ...

Is there a way to invoke a function within a mat-error element?

I need to display an error message in my input field! The function will return true if both passwords match, otherwise it will return false. How can I invoke a boolean function inside mat-error! My Function: checkPasswords(): Boolean { // 'passwords& ...

PHP response is blank when password_hash or password_verify functions are used

My application utilizes JavaScript to retrieve a string and send it via POST to a PHP file on the server for processing. The PHP receiver is responsible for parsing the string, performing tasks, and sending back status updates to JavaScript. However, after ...

Can you pass arguments to a jQuery .on event handler function?

I am looking to implement a feature where users can update a page using an AJAX call. The idea is for users to input some parameters into specific fields, and then upon clicking a button, data will be retrieved from a database and the page will be updated ...

What is the best way to incorporate both images and text in PHP code?

I'm currently working on creating a large image call-to-action (CTA) for my new WordPress website. I've set up a new field group with the type "group" in ACF, and added some functions in PHPStorm. However, none of my images, text, or links are ap ...

display:table causing issues in Internet Explorer

I am trying to achieve a layout where table cells are aligned horizontally similar to the ones demonstrated on this page. Despite following the provided instructions and even copying the css and markup exactly, I am facing an issue with IE 8 rendering my ...

Ways to transfer a variable from a Node.js script to a JavaScript file on the client side

Seeking guidance on how to transfer the "myBlogs" variable from my Node.js file ("server.js") to a frontend JavaScript file ("blogs.js"). I intend to utilize this variable in the JS file to iterate through the array it contains, generating a template for e ...

How can I prevent this image from expanding within the section?

I am currently utilizing Bootstrap 4.6 and WordPress along with the ACF Plugin, and I find myself in need of assistance. I am facing an issue where the height of a row in a section needs to adjust according to the content within a column, but the image wit ...

Using jQuery and CSS to change to "loading" status

My current setup includes the following: <div class="click red"></div> <div class="click green"></div> <div class="click blue"></div> When the "click" is clicked, I want to add the class "load" to the div. I have succe ...

table that can be scrolled horizontally

I am facing an issue similar to the one discussed in this thread about responsive design for html wide table. In essence, my problem involves a table that is wider than the container div, which has ten columns in width (using bootstrap). The challenge aris ...

Having trouble viewing the image slider on an HTML webpage

I've been attempting to incorporate an image slider into my personal website on GitHub, but I've encountered some difficulties as the images are not displaying. Interestingly, I can load individual images without using the slider and they show up ...

I want to learn how to change the background image in React based on different components

Hey there! I've been learning and came across the Tomorrowland website. I really love the background scrolling effect on the homepage, where it changes depending on the component. I'm not sure how to code it myself and could really use some assis ...

Users are unable to access the most recent version of the CSS file

Running a website through Hostinger has presented a unique challenge - when I make changes to the CSS file, it updates for some users but not all. It seems that the changes are being cached for certain individuals. I attempted to rectify this issue by add ...

Transitioning images in JQuery by using a rollover effect

Is there a way to use Jquery for a hover effect that transitions images with a slide up animation? I've looked everywhere online, but I can't seem to find a code that works. All the examples I've found use fadeIn or fadeOut. Thank you for yo ...

I am encountering challenges and confusion with CSS

I am encountering an issue with my code that is causing some difficulties. The goal is to create a basic div with left, right, and center panes. The left pane loads perfectly, but the right pane, which has the same css styling, displays its children with a ...

Calculate the total number of true values in every row

I have successfully set up a MySQL database using PHPMyAdmin to store user-selected data from a webpage. Essentially, when a user clicks buttons on the page, the corresponding column in the database changes from 0 to 1. However, I want to limit each user t ...

Is there a way to enable automatic scrolling in a Django chat application?

Hello! I am looking to implement an automatic scroll-down feature on my webpage. Every time I refresh the page, I find myself at the top of the conversation, specifically at the "start-conversation" section. Below is the code snippet that I am currently ...

ReactJS: Want to update card design by utilizing the onClick event handler

Currently, I am aware that there will be a need to refactor this code later on to separate things into their own components. However, due to time constraints, I have to wire this up as is at the moment. To achieve this, I utilized array.map() to create car ...