To view the border design I have in mind, please click on the provided link

The edges of the border are cut on the left side. This is the specific border design I am aiming for:

Here is my current code, what alterations should I implement?

 <section class="started">
      <div class="container">
        <div class="row">
          <div class="col-3">
            <div class="box1 text-center">
              <h3>All started in 1956</h3>
              <h3>A fresh breeze of modern furniture in town!</h3>
            </div>
          </div>
        </div>
      </div>
    </section>
.box1 {
  height: 300px;
  background: #fff;
  position: relative;
}

.box1:before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  border-top: 12px solid #000000;
  border-left: 12px solid #000000;
  border-right: 12px solid #000000;
  border-bottom: 12px solid #000000;
  width: 0;
} 

Answer №1

Utilizing the `::before` Pseudo-Selector in CSS

I have employed the clever technique of utilizing the `::before` Pseudo Element in CSS, which allows us to generate a new element that can be styled according to our preferences.

  1. Create a border for your parent element (in my case, `.container`)

  2. Determine the thickness of the border

For instance, if you have border: 0.5em solid black;, the value of 0.5em is what you would use (it may be in pixels).

  1. Add a ::before or ::after PseudoElement

  2. Set the width of the ::before element to match the border thickness

  3. Apply position: relative to the parent element so we can utilize absolute positioning for the PseudoElement

  4. Use display: grid; on the parent element `.container` for easy centering using place-items: center;

The key trick lies here:

When implementing these lines:

background-color: white;
position: absolute;
left: -0.5em;
width: 0.5em;

Complete Code Snippet

body {
    display: grid;
    place-items: center;
    min-height: 100vh;
}

.container {
    height: 80vh;
    width: 80vw;
    border: 0.5em solid black;
    position: relative;
    display: grid;
    place-items: center;
}

.container::before {
    content: "";
    background-color: white;
    position: absolute;
    left: -0.5em;
    height: 40vh;
    width: 0.5em;
}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <div class="container">
    </div>
</body>

</html>

Answer №2

If you want to create a box with a missing segment, one way to achieve this is by using the following CSS code. However, please note that the linear-gradient may need adjustments for better browser compatibility.

.box {
  position:relative;
  border-top: 1px solid #000000;
  border-left: 1px solid #000000;
  border-right: 1px solid #000000;
  width: 100px;
  height:100px;
}
#border-segment {
  position:absolute;
  bottom:0px;
  height:1px;
  width:100%;
  
  background: -moz-linear-gradient(left, #000000 0%, #000000 33%, #FFFFFF 33%, #FFFFFF 66%, #000000 66%, #000000 100%);
}
<div class="box"><div id = "border-segment"></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

Switch the div class when clicked, and revert it when the body is clicked

Allow me to elaborate on the issue: I currently have <div class="contact"> <div id="form"></div> <div id="icon"></div> </div> My goal is to change the class of .contact to .contactexpand (or simply ...

Maintaining responsiveness, CSS grid will automatically adjust the height of each element to be equal

I am facing an issue with my grid layout. Each element in the grid has an image and other divs below it. The problem arises when the screen size changes, causing the elements to scale automatically due to responsive width. I want all the images to have the ...

What is the best way to hide only the rows in a table when it is clicked using JavaScript?

Is there a way to hide rows in these tables by clicking on the table head? I'm currently using bootstrap 5 so JQuery is not an option. <table class="table table-info table-bordered"> <thead id="tablea"> ...

Tips for preventing background scrolling of a Fixed element in React

Currently, I am working on a project using NextJS with Tailwind CSS. I am in the process of creating a drawer, popup, and modal with the CSS property position: fixed. However, I have encountered an issue where when I scroll on the fixed elements, the bac ...

Using inline-block in CSS for layout purposes

I recently created a website using a template from w3school. I have a question regarding the anchor elements in my navigation bar: Why do the anchor elements (home, band, tour, contact) jump when clicked? Does anyone know how to fix this issue? I've ...

Extract content from whole webpage including HTML, CSS, and JavaScript

Currently I am working on developing a webpage version control backup/log system. The goal is to automatically save a static copy of the webpage, including all its CSS and JavaScript files, whenever there are any changes made. I have already figured out h ...

Table on the absolute position within an overflow scroll container

I'm encountering an issue with a custom select list within a table. The absolute position of the select list is not working properly within the table, causing it to fill the height of the table. My desired outcome is for the select list to overlay the ...

The tabs are visible in the drawer, but the transition is not occurring

I am a beginner when it comes to using material ui. After clicking on advanced sports search, a drawer pops up. I have been trying to incorporate tabs in the drawer, but every time I click on tab two, the drawer closes. In reality, it should switch between ...

Is there a way to make my Bootstrap carousel display three cards at a time in a continuous cycle?

I currently have a Bootstrap carousel implemented on my website, but I am encountering an issue where only one card is displayed at a time within the carousel. I am looking to modify the carousel so that it displays 3 cards simultaneously. Additionally, I ...

Extracting information from a checkbox list displayed within an HTML table

I have a table with multiple rows and two columns in each row. The first column contains text, and the second column consists of checkboxes. While I was able to retrieve the values from the first column, I am struggling to fetch the values of the selected ...

The background image on my website isn't showing up once it's been deployed via GitHub

I've tried various solutions to fix the issue at hand, but unfortunately, none of them seem to be effective. I double-checked the image path directory and confirmed that it is accurate. Even after uploading both png and jpg files, the problem persists ...

Is there a way to replicate the data from one canvas onto another canvas using getContext('webgl')?

I am currently working on a project that involves displaying medical images on one canvas and annotating those images by drawing shapes or lines on another canvas. My issue arises when I try to copy the drawn annotations from canvas#2 to canvas#1. Here is ...

What's the process for browsers to render the 'span' element?

<p> <span>cancel</span><span>confirm</span> </p> <hr> <p> <span>cancel</span> <span>confirm</span> </p> Both should display the same result. However, in the ...

Adjust the size of an image to fit next to a separate division within a larger division

Need help with creating a webpage layout featuring two text boxes side by side, with the main content adjusting its width accordingly. The issue arises when adding images, as they do not scale proportionally and end up at the bottom of the smaller box, cr ...

arranging the table within the div

I have utilized the following code snippet to exhibit data in an HTML table while enhancing the loading time for large datasets. Code Snippet: <body onload="load();"> <div id="Grid" style="overflow:scroll; width:600px;height:300px; ons ...

Unusual actions exhibited by GestureEvent.rotation in iOS webkit browsing

Utilizing JavaScript Gesture events, I've been able to detect multitouch pan/scale/rotation actions on an element within an HTML document. If you visit this URL with an iPad: , you'll be able to touch the element with two fingers and rotate it. ...

Attempting to initiate a CSS animation by clicking a button using JavaScript

I'm having trouble getting a CSS animation to trigger with a button press using Javascript. I've gone through various questions and answers, but nothing seems to work. My code looks like it should do the trick -- what am I missing? When I click t ...

Embed an external website within a div element

Is there a way to embed an entire external website onto another site, without scroll bars or borders? I attempted this method but the entire page did not load, and there were still scroll bars and borders present. <!DOCTYPE HTML> <html> <b ...

VBA: A guide to interacting with elements inside an iframe

I've been struggling to click on an element within an HTML iframe for weeks now. I've tried clicking on a div ID and a span title, but nothing seems to work. I believe it's due to incorrect syntax. Can someone please advise me on the correc ...

The issue of jQuery CSS positioning failure in Chrome/Opera

My code is functioning correctly in IE and Firefox, but not in Opera or Chrome. Essentially, it generates a DIV that is placed right after the input field. In IE and Firefox, the new div overlaps the input, but in Opera and Chrome, it appears next to the l ...