tilted container with outline

One challenge I'm facing is with a code that involves 6 slanted divs. I would like to add a black border to only the center Title 2 div. However, when I apply the border, it only shows on the top and bottom, not on the left and right sides.

.title {
  background: #f2f2f2;
}

.img {
  min-height: 300px;
  background: center/cover no-repeat;
}

.col:first-child {
  clip-path: polygon(0 0, calc(100% - 15px) 0, calc(100% - 10vw) 100%, 0 100%);
  margin-right: -5vw;
}

.col:nth-child(2) {
  clip-path: polygon(10vw 0, calc(100% - 15px) 0, calc(100% - 10vw) 100%, 15px 100%);
  margin: 0 -5vw;
}

.col:last-child {
  clip-path: polygon(10vw 0, 100% 0, 100% 100%, 15px 100%);
  margin-left: -5vw;
}

.col:nth-child(2)>.title,
.col:last-child>.title {
  padding-left: calc(10vw - 15px)!important;
}
.black-border{
 border: 2px solid black;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">

<div class="container-fluid">
  <div class="row text-center">
    <div class="col">
      <div class="title p-3">Title 1</div>
      <div class="img mt-3" style="background-image:url(https://picsum.photos/id/1012/800/800)"></div>
    </div>
    <div class="col">
      <div class="title p-3 black-border">Title 2</div>
      <div class="img mt-3" style="background-image:url(https://picsum.photos/id/1015/800/800)"></div>
    </div>
    <div class="col">
      <div class="title p-3">Title 3</div>
      <div class="img mt-3" style="background-image:url(https://picsum.photos/id/1016/800/800)"></div>
    </div>
  </div>
</div>

Answer №1

Try using the drop-shadow filter to create a border around your elements:

.title {
  background: #f2f2f2;
}
.filter {
  --b:2px;
  filter:
   drop-shadow(var(--b) 0px 0px black) 
   drop-shadow(0px var(--b) 0px black) 
   drop-shadow(calc(-1*var(--b)) 0px 0px black) 
   drop-shadow(0px calc(-1*var(--b)) 0px black)
}
.img {
  min-height: 300px;
  background: center/cover no-repeat;
}

.col:first-child {
  clip-path: polygon(0 0, calc(100% - 15px) 0, calc(100% - 10vw) 100%, 0 100%);
  margin-right: -5vw;
}

.col:nth-child(2) {
  clip-path: polygon(10vw 0, calc(100% - 15px) 0, calc(100% - 10vw) 100%, 15px 100%);
  margin: 0 -5vw;
}

.col:last-child {
  clip-path: polygon(10vw 0, 100% 0, 100% 100%, 15px 100%);
  margin-left: -5vw;
}

.col:nth-child(2)>.title,
.col:last-child>.title {
  padding-left: calc(10vw - 15px)!important;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">

<div class="container-fluid mt-2">
  <div class="row text-center filter">
    <div class="col">
      <div class="title p-3">Title 1</div>
      <div class="img mt-3" style="background-image:url(https://picsum.photos/id/1012/800/800)"></div>
    </div>
    <div class="col">
      <div class="title p-3 black-border">Title 2</div>
      <div class="img mt-3" style="background-image:url(https://picsum.photos/id/1015/800/800)"></div>
    </div>
    <div class="col">
      <div class="title p-3">Title 3</div>
      <div class="img mt-3" style="background-image:url(https://picsum.photos/id/1016/800/800)"></div>
    </div>
  </div>
</div>

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

I am looking to transmit information from flask to React and dynamically generate HTML content based on it

index.py @app.route('/visuals', methods=["GET", "POST"]) def visuals(): global visclass return render_template('visframe.html', images=visclass.get_visuals()) visframe.html <div id='gallery'></div> { ...

Using a foreach loop to showcase data in a table

My goal is to utilize the GitHub API to showcase all the issues present in my repository in a neat table format on my website. Despite my best efforts, I am facing difficulties in generating the table using a foreach loop. Below is the PHP code I am curr ...

Alternative solution to avoid conflicts with variable names in JavaScript, besides using an iframe

I am currently using the Classy library for object-oriented programming in JavaScript. In my code, I have implemented a class that handles canvas operations on a specific DIV element. However, due to some difficulties in certain parts of the code, I had t ...

How can I display multiple images in a single row using PHP echo?

I am struggling with my PHP code that displays images from a database. The issue I'm facing is that the images are all appearing in a single column, but I want them to be displayed in one row so that users can scroll horizontally to view them. How can ...

When printing a table in HTML/CSS, only the header will appear on the empty page

I'm struggling to figure out why there are two pages, one blank and one with just the table header in this document. The content looks fine otherwise, but I can't seem to remove these extra pages. Here is the full HTML code: <!DOCTYPE html& ...

Placing the child element behind the parent element's parent does not seem to be affected by the `z-index`

Please help! I've been struggling to get the <span> to appear behind the #sideBar using z-index: -3, but it's not working as expected.</p> body { margin: 0px; font-family: "Signika Negative", sans-serif; background-color: #25 ...

transferring a selected option from a dropdown menu to a different webpage

I need to implement a dropdown box that allows users to select a value and then use Php to send it to another page. Below is the current code for the dropdown box: Here is the code snippet for the dropdown box: Version 2: <form style="margin-top:20px ...

Implement a sequence of animations within a div using jQuery

My goal is to create an animation effect for each div element within a row when the user scrolls down to that specific point on the page. The layout consists of three <div> elements in the same row. The structure of the HTML code is as shown below: ...

Creating a dynamic quiz with random images using text boxes in HTML and PHP

I am working on creating a 'guess the picture' style quiz where a random image is displayed as the question, and users must input their answer in a textbox. The question will be selected randomly from 3-5 options each time the page is refreshed o ...

Is it possible to use a shell script to replace the external CSS file link in an HTML file with the actual content of the CSS file

Seeking a solution for replacing external CSS and JS file links in an HTML document with the actual content of these files. The current structure of the HTML file is as follows: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C ...

How can I convert a number to the format of hh:mm using Angular?

Within my form, there is an input field that should only accept numbers. Is it possible to format the input number into a hh:mm format once the user enters it? I prefer not to use input type = time. Do you have any suggestions for achieving this? ...

Display a notification to the user prior to reloading the page

I have created a code for logging attendance at work using a barcode reader. The user simply needs to scan their card with a barcode to register their attendance. let $scannerInput = $(".scanner-input"); $(document).ready(function(){ $scannerInput.focu ...

Combining multiple rows into a single row and inserting a new column

Hi there, I'm currently diving into the world of programming and tackling a project involving PHP and MySQL. However, I've encountered a bit of a roadblock. My current setup involves a table named marks, where each time a mark is added to a stud ...

Adding new elements to a div container

My goal is to populate a div element with items based on elements from an array. I need to duplicate an existing element on the page and append the new version to the div. Let me provide the code for better understanding: JavaScript: function apply(list ...

Problems with scrolling in the navigation bar, main content area, and footer

The challenge Encountering a scrolling anomaly with the Navigation Bar, Body, and Footer while utilizing Bootstrap 4. Everything appears to function smoothly on the desktop view. The glitch arises when I reduce the viewport size. The body fails to stay in ...

Unable to accommodate additional space, InputGroup is not utilizing the

Using react-bootstrap in my project, I have a component with the following code. I want the input and button to display together and fill up the entire space allocated by the Col. Although the input and button are displaying side by side, they are not ta ...

Using the information retrieved from Google Place Autocomplete and saving it for future reference

I am interested in utilizing the Google API "Place Autocomplete" widget to enhance user experience on my website. The specific widget I have in mind can be found here. My goal is to streamline the process of obtaining property addresses from Real Estate A ...

Motion of the atoms

I recently came across an interesting effect on the IconArchive website, but I am unsure how to implement it. If anyone could help me understand the concept with a small example, that would be greatly appreciated. You can see the effect in action by visi ...

Ajax - Retrieving data from a different webpage

My index.php contains the following HTML: <div id="showDetails"> </div> <div id="showList"> </div> And this Ajax function is also in index.php: function ...

When the value is removed, it does not revert back to the initial filtered choices

After clearing the input, I want to display all the original li's again. The issue is that even though .value = '' clears the input, the filter remains active. I could really use some help with this as it's starting to get on my nerves ...