Unable to insert additional lines into diamond shape generated solely with CSS

Is there anyone out there who can assist me in creating this logo using CSS?

View the image of the logo here

I initially attempted to make a square with width and height, followed by experimenting with pseudo elements. However, I hit a roadblock because pseudo elements can only be used twice - once before and once after - which limited my options.

Although this second approach demonstrates an alternative method, it is not ideal as it lacks reusability and the lines become misaligned when zoomed in. You can see the code in action on this JSFiddle link.

* {
  box-sizing: border-box;
}

.container {
  margin: auto;
  background-color: green;
  max-width: 1400px;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.rectangle {
  height: 40px;
  width: 40px;
  border: 3px solid yellow;
  transform: rotate(45deg);
  position: relative;
}

.first-line {
  position: absolute;
  content: "";
  width: 20px;
  height: 20px;
  left: 100%;
  top: 100%;
  transform: translateY(-100%);
  border-top: 3px solid yellow;
}

.second-line {
  position: absolute;
  content: "";
  width: 20px;
  height: 20px;
  top: 0%;
  left: 0%;
  transform: translateX(-100%);
  border-bottom: 3px solid yellow;
}
<!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" />
  <link rel="stylesheet" href="css/style.css" />
  <title>Web Design | Mike Taylor</title>
</head>

<body>
  <!-- Main header -->
  <section class="main-header">
    <div class="container">
      <div class="rectangle">
        <div class="first-line"></div>
        <div class="second-line"></div>
      </div>
    </div>
  </section>
  <!-- End Main header -->
</body>

</html>

Answer №1

/* Creating a 1170px container */

* {
  box-sizing: border-box;
}

.container {
  margin: auto;
  background-color: green;
  max-width: 1400px;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.rectangle {
  height: 40px;
  width: 40px;
  border: 3px solid yellow;
  transform: rotate(45deg);
  position: relative;
}

.first-line {
  position: absolute;
  content: "";
  width: 20px;
  height: 20px;
  left: 100%;
  top: 100%;
  transform: translateY(-100%);
  border-top: 3px solid yellow;
}
.second-line {
  position: absolute;
  content: "";
  width: 20px;
  height: 20px;
  top: 0%;
  left: 0%;
  transform: translateX(-100%);
  border-bottom: 3px solid yellow;
}
.third-line {
  position: absolute;
  content: "";
  width: 20px;
  height: 20px;
  top: 0%;
  left: 0%;
  transform: translateY(177%) translateX(81%) rotate(90deg);
  border-bottom: 3px solid yellow;
}
.forth-line {
  position: absolute;
  content: "";
  width: 20px;
  height: 20px;
  top: 0%;
  left: 0%;
  transform: translateY(-115%) translateX(81%) rotate(90deg);
  border-bottom: 3px solid yellow;
}
<!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" />
    <link rel="stylesheet" href="css/style.css" />
    <title>Web Design | Mike Taylor</title>
  </head>
  <body>
    <!-- Main header -->
    <section class="main-header">
      <div class="container">
        <div class="rectangle">
          <div class="first-line"></div>
          <div class="second-line"></div>
          <div class="third-line"></div>
          <div class="forth-line"></div>
        </div>
      </div>
    </section>
    <!-- End Main header -->
  </body>
</html>

Click here for the full page screenshot: Link to Screenshot

Answer №2

Take a look at the answer below, it should provide you with some assistance

* {
  box-sizing: border-box;
}

.container {
  margin: auto;
  background-color: green;
  max-width: 1400px;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
.rectangle {
    height: auto;
    width: auto;
    border: 4px solid yellow;
    transform: rotate(45deg);
    position: relative;
    text-align: center;
    min-width: 100px;
    min-height: 100px;
}
.rectangle h1 {
   margin: 0;
    line-height: initial;
    color: #fff;
    font-weight: normal;
    font-size: 50px;
    font-family: arial;
    position: relative;
    transform: rotate(-45deg);
    padding: 40px;
}
.rectangle:after {
    content: "";
    position: absolute;
    width: 60px;
    height: 4px;
    background: yellow;
    right: -60px;
    top: 50%;
    margin-top: -2px;
}

.rectangle:before {
    content: "";
    position: absolute;
    width: 60px;
    height: 4px;
    background: yellow;
    left: -60px;
    top: 50%;
    margin-top: -2px;
}
.rectangle .line:before{
    content: "";
    position: absolute;
    height: 60px;
    width: 4px;
    background: yellow;
    top: -60px;
    left: 50%;
    margin-left: -2px;
}
.rectangle .line:after{
    content: "";
    position: absolute;
    height: 60px;
    width: 4px;
    background: yellow;
    bottom: -60px;
    left: 50%;
    margin-left: -2px;
}
  <section class="main-header">
    <div class="container">
      <div class="rectangle">
        <div class="line">
        <h1>M</h1>
      </div>
    </div>
  </section> 

Answer №3

Check out this simple div concept with minimal code:

.design {
  --b:8px; /* adjust this for different thickness */
  /* customize the dimensions */
  width: 60px;
  height: 60px;
  /**/
  font-size: 45px;
  font-family: 'Arial';
  margin: 80px auto;
  position: relative;
  display: grid;
  place-items: center;
}
.design:before {
  content: "";
  position: absolute;
  inset: -200%;
  transform: rotate(135deg);
  background: 
    linear-gradient(#fff 0 0) center/100% var(--b), 
    linear-gradient(#fff 0 0) center/var(--b) 100%, 
    linear-gradient(#fff 0 0) center/50% 50%;
  background-repeat: no-repeat;
  -webkit-mask: 
    linear-gradient(#fff 0 0) center/calc(50% - 2*var(--b)) calc(50% - 2*var(--b)),
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  -webkit-mask-repeat: no-repeat;
}
body {
  background: #e3e3e3;
}
<div class="design">X</div>

Here's another sleek design approach:

.design {
  --b:6px; /* adjust this for different thickness */
  /* customize the dimensions */
  width: 55px;
  height: 55px;
  /**/
  font-size: 40px;
  font-family: 'Helvetica Neue';
  margin: 80px auto;
  position: relative;
  display: grid;
  place-items: center;
}
.design:before {
  content: "";
  position: absolute;
  inset: -150%;
  padding:70%;
  transform: rotate(45deg);
  background: 
    linear-gradient(90deg,#fff 25%,#0000 0 75%,#fff 0) 50%/100% var(--b), 
    linear-gradient( 0deg,#fff 25%,#0000 0 75%,#fff 0) 50%/var(--b) 100%,
    conic-gradient(from  90deg at top   var(--b) left   var(--b),#0000 90deg,#fff 0) content-box,
    conic-gradient(from -90deg at bottom var(--b) right var(--b),#0000 90deg,#fff 0) content-box;
  background-repeat: no-repeat;
}
body {
  background: #f9f9f9;

<div class="design">X</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

Customize your Bootstrap 4 accordion cards with added margin and a sleek design without the usual bottom

After incorporating Bootstrap's accordion component, I made a custom adjustment by including spacing between the cards to achieve this layout (the - and + symbols were my addition and not important here): https://i.stack.imgur.com/5nRrP.png However, ...

Enhancing functionality through interactive buttons: optimizing the performance of this dynamic data code

I am seeking a more efficient way to retrieve names from a database using PHP and MySQL. Currently, I have multiple if isset statements in my code, one for each button that retrieves a specific name. Is there a better approach to achieve the same result ...

How can I apply various textures in three.js?

Hello there! I'm diving into the world of threejs and currently working on a block game similar to Minecraft. Instead of relying solely on objects, I've decided to build my program using planes (specifically the PlaneGeometry class). As I wrap ...

Angular-dc bar graph failing to display properly

I'm having some trouble creating a bar chart using crossfilter, dc.js, and angular-dc. The rowchart is working properly, but the barchart is not displaying the bars. When I inspect the element in Chrome, I can see the values, and when I force focus, t ...

Include the necessary attribute

I am facing a situation in my HTML code where I need to insert the attribute required="required", but I am having trouble locating the specific location. My goal is to add this attribute using jQuery, and I have attempted to achieve this with the following ...

Creating a JSON-based verification system for a login page

First time seeking help on a programming platform, still a beginner in the field. I'm attempting to create a basic bank login page using a JSON file that stores all usernames and passwords. I have written an if statement to check the JSON file for m ...

Show two <p>'s next to each other

I am trying to arrange 2 paragraphs side by side. <p class = "firstClass">This is the first paragraph.</p> <p class = "secondClass">This is the second paragraph.</p> Result: This is the first paragraph. This is the second paragra ...

Detecting the specific button that was selected with PHP

I am in the process of developing a website for a production company where, upon clicking on a director's name from the menu, all other menu items disappear and only the selected director's biography and work are displayed. My current challenge ...

Responsive Alignment of Slanted Edges using CSS

I have been working on creating a responsive diagonal layout with slanted shapes (refer to the image attached). However, I'm facing a challenge with aligning the edges smoothly at different screen sizes, especially when the rows grow and the screen re ...

An advanced coding tool that is able to transfer CSS code from the style attribute to the class definition

Is there an editor or IDE that can convert styles from CSS classes to inline styles? .my_class { color: black; } <span class="my_class" style="font-size: 200%;">test</span> to .my_class { color:black; font-size: 200%; } <span ...

Preventing Redropping: A jQuery Drag and Drop Feature to Ensure Dropped Elements Stay Put

After implementing Drag & Drop functionality using jQuery, I have encountered a specific issue. The problem: When the dropped element (drag 1) is removed from the droppable container, it reverts back to the draggable container. Subsequently, attempting to ...

Is there a way to fetch a random record from a MongoDb collection and exhibit all the fields of that haphazardly chosen document in HTML?

In my current project, I am fetching a random document from a MongoDB Collection and attempting to showcase all the fields of that document in HTML. Although I can successfully retrieve a random document, the issue arises when trying to display its fields ...

Tips for creating a sidebar table of contents with CSS

I'm looking to design a webpage with a side bar table of contents (TOC) similar to the one found here: The current placement of the TOC on the HTML page is as follows: <h2>Table of Contents</h2> <div id="text-table-of-contents&quo ...

The information overflow occurs outside the tooltip specifically in Chrome, while functioning perfectly in IE11

As a newcomer to the CSS world, I am experimenting with adding a block-level element (div) inside an anchor tag's :hover pseudo-class popup. The div element contains a table that needs to have dynamic sizing for both the table itself and its cells (wi ...

Utilizing local storage functionality within AngularJS

I've been encountering challenges while trying to integrate local storage using ngStorage in my ongoing AngularJS project. Despite fixing what seems to be the root cause of data type problems and errors during debugging, issues persist. Here is the P ...

How to Validate Comma-Separated Email IDs Using Regex in Angular 5 Template?

I am currently working on a project utilizing Angular 5. Within this project, there is an input field designated for E-Mail IDs. The main goal I aimed to achieve was: To enable the user to input a maximum of 3 E-Mail IDs, with each E-Mail ID being subject ...

In Python using Selenium, the text property of a WebElement may cut off duplicate whitespaces

Today, I came across an interesting observation regarding the text property of WebElement. Here is a PDF link that sparked my curiosity: https://i.stack.imgur.com/1cbPj.png Upon closer inspection, I noticed that the file name contains triple whitespace. W ...

Is the sliding navigation glitching due to the video background?

Currently, I am in the process of developing a website with a captivating full-page video background. The nav menu gracefully slides out from the left side using jQuery UI when users scroll down to view the site's content. To view the work-in-progres ...

Concerns regarding rendering HTML and drawing in Node.js

Having an issue where node.js is serving an html file with an SVG drawing. The index.html features a chart similar to the line chart found at http://bl.ocks.org/mbostock/3883245 Whenever I try to serve the index.html through the express server, I end up ...

Converting RGB color values to HSL color values using a unique, randomized Javascript approach

On this site, I have added a random color overlay to the media-boxes. Check it out here Thanks to the helpful folks at stackoverflow, I was able to create this script: var getRandomInRange = function(min, max) { return Math.floor(Math.random() * (ma ...