Using CSS to create a triangular background within a <div> element

I am looking to create a CSS triangle shape for a background, but I am unsure of how to achieve this or if it is even possible.

Ultimately, I want the menu to resemble the image linked below:

While I have come across methods to create the desired shape, I am struggling to fit text inside it...

I'm simply wondering if it's feasible to accomplish this using just HTML and CSS without relying on images, and whether a triangle shape is the right choice.

Beneath this menu, there should be another <div> with a yellow background that is connected to the menu to form one cohesive shape.

Thank you in advance for any responses and advice provided.

PS: fiddle

I am attempting to position "homepage" on the left side, but I am feeling lost...

body{
    background-color: 
}

.shape {
    width:960px;
    margin:0 auto;
}
.top {
}
.bottom {
width: 960px;
height: 50px;
padding-top: 25px;
font-family: 'Source Sans Pro', sans-serif;
color: #f1c40f;
text-align: right;
background: #f1c40f; /* Old browsers */
background: -moz-linear-gradient(4.5deg, #f1c40f 50%, #1c2228 50%); /* FF3.6+ */
background: -webkit-gradient(linear, left bottom, right top, color-stop(50%,#f1c40f), color-stop(50%,#1c2228)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(4.5deg, #f1c40f 50%,#1c2228 50%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(4.5deg, #f1c40f 50%,#1c2228 50%); /* Opera 11.10+ */
background: -ms-linear-gradient(4.5deg, #f1c40f 50%,#1c2228 50%); /* IE10+ */
background: linear-gradient(4.5deg, #f1c40f 50%,#1c2228 50%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f1c40f', endColorstr='#1c2228',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */
}
.bottom a.special {
    text-align: left;
padding:100px;
    color: red;
}
.bottom a, a:link, a:visited, a:hover {
color:#f1c40f;
background-color:transparent;
text-decoration:bold;
}
.bottom a, a:active {
color:#f1c40d;
background-color:transparent;
text-decoration:none;
}
<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css" />
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,400,600,700,200italic,400italic,600italic,700italic&subset=latin-ext' rel='stylesheet' type='text/css'>
</head>
<body>
<div class="bottom">
<a class="special">Homepage</a>
<a href="">About</a>
<a href="">Works</a>
<a href="">Contact</a>
</div>
</body>
</html>

Answer №1

Consider utilizing the Cross browser technique for creating a triangle shape by visiting this link.

This method is completely cross-browser compatible and avoids any pixelation effects.

You can view a live demonstration of this technique by clicking on this demo link.

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

Insert the URL into either a div or an iframe

It seems like a common issue. I've come across multiple solutions for this problem. using jquery load using iframe I attempted both methods but encountered difficulties in loading content. Specifically, I tried to load google.com and it didn't ...

Connect to a point on the leaflet map using an external <a> tag reference

I have a leaflet map and I am trying to create a link that, when clicked, will activate a specific marker on the map. Essentially, I want the linked marker to simulate being clicked when the link is clicked. Here is an example of the link: <a href="#" ...

Different choices for pick component in Bootstrap

Struggling to create an inline label with a select element using Bootstrap, I came across this helpful example on jsfiddle: http://jsfiddle.net/kokilajs/1q53pr6j/ <form id="searchForm" method="get" class="form-horizontal" role="form"> <div class= ...

Tips for ensuring your background image is fully displayed and covers the entire size

My dilemma lies within the header div. My intention is to have it fully covered with a background image without any cropping. However, the current setup seems to be stretching and cutting off parts of the image. Here is my CSS code: .header { bor ...

How to Add a Responsive Inset Transparent Overlay to Images without Using JavaScript?

My goal is to create a unique overlay effect on images of different sizes within a Pinterest-style fluid grid layout. The outer border width and inset 'border gap' will remain consistent, while the images themselves need to dynamically adjust. C ...

Is there a way to ensure my function runs as soon as the page starts loading?

My goal is to have a function execute as soon as a person opens my page, without requiring any interaction. The function should trigger on page load, rather than waiting for a click event. Additionally, I want the function to repeat every 90 seconds. I&apo ...

Use radio buttons to enable switching between different data options within a dropdown menu

I am working on a dropdown box that is populated dynamically using JSON data. The content in the dropdown can be categorized into 4 types, so I have included radio buttons to switch between these categories. I have created HTML code to toggle between manu ...

Is there a way to retrieve the disabled drop-down field value after submitting the form?

I'm struggling with a dropdown field that becomes disabled once an item is selected. After submitting the form, the dropdown field loses its value and I'm left with an empty field. Any suggestions on how to keep a value in the dropdown after subm ...

Masonry style attempted for posts but did not produce desired outcome

I've been experimenting with different methods to achieve a masonry style layout for my posts. So far, using float:left seems to work almost perfectly, but occasionally there are gaps between the posts. I'm on the lookout for a solid solution to ...

Changing the color of a pseudo element in Material-UI

I'm having trouble changing the border color of the ::after pseudo element on a standard text field from MUI. I've been unable to figure it out. <TextField id="standard-basic" label="Email" variant="standard"/> ...

What could be the reason behind the significant void in the grid I designed?

I'm currently learning how to utilize the grid container and have successfully created a grid with 2 images on top, 2 on the bottom, and one that stretches vertically on the left side. While I have arranged the grid as desired, I am facing an issue wi ...

What is the best way to incorporate a YouTube video into my HTML webpage?

Looking to add some YouTube links to my webpage - I'm a complete newbie and clueless about formats and embedding. Can someone guide me on what to use and how to insert it into my HTML code? Appreciate any help! ...

anchor text substitution for hyperlink

I currently have a code snippet that replaces a span class with a hyperlink. The hyperlink contains an abbreviation, and the alternate text for the link also includes the same abbreviation. Now, I am looking to replace the second abbreviation in the alte ...

Steps for creating a fixed menu bar that remains stationary while scrolling

I am facing three challenges: When I hover over my menu links, I want them to become 'bold', but it causes the items on the right to move slightly. How can I prevent this movement? In regard to the dropdown menu on "Two", how can I ensure t ...

The appearance of the webkit-scrollbar is not reflecting the intended style

I have successfully created a wrapper for a styled scrollbar in React JS - import styled from '@emotion/styled'; export const ScrollbarWrapper = styled.div(() => ({ maxHeight: '65vh', overflowY: 'auto', '*::-web ...

Using jQuery to modify CSS attributes is proving to be more challenging than I anticipated

I am attempting to modify a CSS attribute using jQuery. I have used the following code: wrapperInner.css('overflow', 'visible'); However, the value remains unchanged. When I use an alert alert(wrapperInner.css('overflow')), ...

Multiple jQuery AJAX requests triggered in a click event handler

I am in the process of developing a PHP web application and utilizing the datatables jQuery plugin along with jQuery AJAX calls to create a dynamic table for editing, deleting, and adding elements. Although it appears to be working correctly, I've not ...

Locate the parent element that has the smallest amount of space taken up by its child elements

My goal is to determine which container, among several <divs>, each containing multiple child <divs> of varying sizes, has the smallest amount of space covered by the child elements. <div class="container" id="first"> ...

In Bootstrap 5, the anchor tag is causing a shift in the background color of surrounding tags upon being clicked

Why does clicking on an anchor tag temporarily change the background of other tags that weren't clicked? What am I doing wrong? https://i.stack.imgur.com/ZKlUT.png Check out the code below: <nav class="navbar navbar-expand-lg navbar-light bg- ...

Adding alternative content when embedding an SWF file in HTML5 - What's the best way to do it?

I am looking to incorporate an SWF file into HTML5. Currently, I have successfully used this code: <embed src="main.swf" width="550" height="400" /> However, I am wondering how I can display alternative content (such as an animated GIF image, or a ...