Embed shapes inside the margins of an HTML container

I'm aiming to create something unique by placing the circle and triangle on the borders of an HTML block.

https://i.sstatic.net/MVYuc.png

Below is the CSS code for my block:

.block { 
    color: red;
}
.cercle { 
    border-radius: 50%;
}

.triangle {
    width: 0; 
    height: 0; 
    border-top: 60px solid transparent;
    border-bottom: 60px solid transparent;
    border-left: 60px solid red;
}

Answer №1

In order to achieve the desired effect, it is recommended to utilize absolute positioning and incorporate CSS3's transform property instead of relying on traditional borders.

Here is a sample implementation:

.container {
  padding: 50px;
  border: 1px solid black;
  display: inline-block;
}
.item {
  background: red;
  height: 100px;
  width: 200px;
  display: inline-block;
  position: relative;
  border: 2px solid #880015;
}
.circle {
  border-radius: 50%;
  position: absolute;
  width: 25px;
  height: 25px;
  background: red;
  top: -12px;
  right:-2px;
  border: 2px solid #880015;
  border-bottom: 0;
  border-left: 0;
}
.triangle {
  background: red;
  position: absolute;
  width: 20px;
  height: 20px;
  top: 5px;
  right: -12px;
  transform: rotate(45deg);
  border: 2px solid #880015;
  border-bottom: 0;
  border-left: 0;
}
<div class="container">
  <div class="item">
    <div class="circle"></div>
    <div class="triangle"></div>
  </div>
</div>

Answer №2

If you're exploring ways to achieve certain design features, take a look at this informative article. It delves into the concepts you are aiming for, although it relies on solid images rather than CSS alone.

For a more straightforward approach, consider nesting a DIV within another DIV. Place all your content and simple borders in the inner div, while incorporating custom elements like circles and triangles in the outer div.

Answer №3

I created a simple example using a circle shape, but you can easily customize it to add other shapes as well.

html

<div class="container">
  <div class="rectangle">
    <div class="circle-shape"></div>
  </div>
</div>

css

.container {
  margin: 25px;
}

.rectangle {
  width: 300px;
  height: 100px;
  border: 5px solid red;
}

.circle-shape {
  width: 50px;
  height: 50px;
  border-radius: 50px;
  background-color: pink;
  position: absolute;
  margin-left: 275px;
  margin-top: -25px;
}

Check out the demo here

Answer №4

To begin, start by incorporating some HTML code.

Here is an example:

<div class="container">
    <div class="square"></div>
    <div class="circle"></div>
</div>

Additionally, here is the corresponding CSS code:

.container { 
    background: green;
    display: block;
    width: 150px;
    height: 150px;    
}

.square { 
    width: 50px;
    height: 50px;
    position: absolute;
    top: 60px;
    left: 40px;  
    z-index: 9999;
    background: #ff6600;
}

.circle {
    border-radius: 50%;
    width: 50px;
    height: 50px;
    position:absolute;
    top: 70px;
    left: 120px;
    background: #0066cc;
}

Utilize position: absolute to adjust the element's position using top, left. You can also use z-index to control stacking order... observe a demonstration on jsbin

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

Add the text into a div element with a dropdown selection

I'm having trouble with the code below. My goal is to move the selected text to my chosen-locations div. Any suggestions? Thank you! <select name='available_locations' class='select-location'> <option value=&a ...

Steady Navigation Bar in Javascript without Bouncing

While experimenting with a fixed navigation bar, I've encountered an issue where the content below jumps up on the page when the navigation bar "fixes" itself to the top of the screen. You can check out the JSFiddle I've been working on for refer ...

Having trouble with jQuery loading for the first time

I am having trouble getting the jQuery to load properly. My goal is to toggle classes on specific items identified by their ID. When an item is clicked, I want it to have the class "menu-selected" while the other item has the class "unselected." I have i ...

What is causing the unusual behavior of z-index in this specific scenario?

I have a good understanding of z-index and decided to practice with it by writing the following code: *{ padding: 0; margin: 0; box-sizing: border-box; } body{ height: 100vh; di ...

Enhancing the layout of a bootstrap table: Creating space between rows while maintaining borders

table{ width: 100%;max-width: 100%; margin-bottom: 20px;border:solid 1px #000; border-collapse: collapse;} tbody tr{border:2px solid #256ac4;} td{ color: #8d9097; vertical-align: top; font-size: 14px;} th{text-align:left} <table> <thead> ...

Tips on creating animations for elements that are triggered when scrolling and become visible

Is there a way to animate an element when it becomes visible on scroll, rather than at a fixed position on the page? I'm currently using code that triggers the animation based on an absolute scroll position, but I'm looking for a more dynamic sol ...

How can I achieve a smooth opacity transition without using jQuery?

Although I understand that JQuery offers functions for this purpose, I am interested in finding a solution using only pure javascript. Is there a way to change the CSS opacity setting over time? Perhaps utilizing a unix time stamp with millisecond precisi ...

Transform the input value into a string

Struggling with converting an input value into a string. HTML: <input type="text" placeholder="Email Ex: john123" id="emailinput"> <input type="text" placeholder="Domain Ex: @gmail.com" id="domaininput"> JS: let emailVal = document.getElem ...

I'm curious as to why a webpage tends to load more quickly when CSS files are loaded before script files. Can anyone shed some

While watching a video, I came across some concepts that were a bit difficult for me to grasp. The video mentions that scripts are 'serialized' and can block subsequent files from loading. According to this explanation, Script 1 would load first ...

Arranging of the fetch_assoc

As a complete beginner in programming, I am excited to share that I have recently embarked on this journey and had only a few classes so far. Currently, I am working on developing a new website just for fun. It is intended for me and my colleagues at work ...

The font is displaying differently when compared to Figma

I'm currently using the font Gilroy-Bold for my project, but I'm facing inconsistencies between how it appears in Figma and my React application, even though they are both sourced from the same place. Figma: https://i.stack.imgur.com/3QvY4.png ...

Converting multi-dimensional array into a structured table format

Query about arrays: Here is the array structure I am working with: Array ( [0] => Array ( [0] => Project [1] => Time ) [1] => Array ( [0] => Google [1] => 2 ...

React, Axios, and the PokeAPI are like a team of explorers navigating an

Trying to enhance my React abilities, I decided to follow this tutorial on creating a list of names using PokeAPI. However, I hit a roadblock at 11.35 into the tutorial while implementing the provided code snippets in both App.js and PokemonList.js: fu ...

Unable to display menu content text using jQuery

Currently experimenting with jQuery to create a dynamic submenu. The goal is to have a sub menu appear when the main menu is clicked, and then disappear when an item in the sub menu is selected, revealing additional information within a div. Unfortunately, ...

Is feature recognition possible in a jQuery plugin?

Can I integrate a tool similar to Modernizr into my plugin? I want to be able to test for specific CSS3 properties without starting from scratch. ...

The dropdown within the modal is proving elusive for Selenium to locate

I am attempting to choose a value from the dropdown menu labeled 'ddl_settpymtaction' using Selenium, but unfortunately it seems to be unable to locate it within the modal where it is located. CSS: https://i.stack.imgur.com/3YWQu.png Selenium ...

How can you change a particular inline style using the Firefox browser?

I am looking for a solution to override an inline style on a specific webpage within the Firefox browser without access to the source code. Previously, I would manually modify the page source using Firefox development tools. Specifically, I encounter a we ...

generate a flexible div that adjusts its height based on the size of the browser window

Is it possible to create a div layout structured like this: <div_wrapper> <div_header> </div_header> <div_content> </div_content> </div_wrapper> Upon page load, the div_header o ...

Utilizing ng-repeat to loop through a div element that consists of various nested tags

I need to display multiple tabs, with each tab having a table where the values are populated from a database. The number of tabs is dynamic and fetched from another page of the application. All tables have the same structure but different values. How can I ...

Modifying Image Source on Hover Using Jquery

Is it possible to change the source of an image on hover and then back to the original source? For example, the name of the file always remains the same, but the number changes - 1 for the original and 2 for the hover. Thank you for any advice. Code: < ...