Click on the right side of the header image

My webpage has a header that spans the full width of the page. The header is styled using CSS with a background image, which includes text in the center and a box labeled "Contact us" on the right side. I want to make this button clickable so that when a user clicks on it, they are directed to a specific link. Ideally, only the right part of the header image should be clickable. Is it possible to achieve this with jquery?

I am open to any hacks or suggestions.

Answer №1

  • If you're looking to create a navigation menu, consider using CSS grid for better flexibility and responsiveness. Avoid using image maps as they can limit adaptability across different devices.

Below is a basic code snippet using CSS grid layout for creating a navigation bar. You can easily customize this by adding text links and positioning them within the defined areas.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Test</title>

<!--CSS-->
<style>

.wrapper {
  display: grid;
  grid-template-columns:
  1fr
  1fr
  1fr
  ;
  grid-template-rows:
  100px
  ;
  grid-template-areas:
  "header-1-left header-1-mid header-1-right"
  ;
  }

  .header-1-left {grid-area: header-1-left; background-color: grey;}
  .header-1-mid {grid-area: header-1-mid; background-color: pink;}
  .header-1-right {grid-area: header-1-right; background-color: lightblue;}

</style>

<div class="wrapper">
  <div class="header-1-left"></div>
  <div class="header-1-mid"></div>
  <div class="header-1-right"></div>
</div>


</head>
<body>

</body>
</html>

Answer №2

To achieve this layout, make sure to use position: relative for the header and position: absolute for the element. Here is a sample code snippet to help you with it.

<div class="header">
    <a href="#" class="link"></a>
</div>

.header {
    position: relative;
}
.header .link {
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    width: 100px;
    z-index: 2;
}

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

Tips for avoiding word fragmentation in <pre> code blocks

pre { white-space: pre-wrap; /* CSS 3 */ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ word-wrap: break-word; /* Internet Explorer 5.5+ */ overflo ...

Navigating through JSON Serialization in Django and Unpacking JSON Data in Jquery

So here's the code snippet that I'm currently working with: def success_comment_post(request): if "c" in request.GET: c_id = request.GET["c"] comment = Comment.objects.get(pk=c_id) model = serializers.serialize("json" ...

Utilizing tag keys for inserting text and adjusting text sizes within a Web application

Creating an online editing interface for coursework where keyboard events are used. The goal is to have the tab key insert text, while also reducing the size of the text on that line. However, upon using getElementById, an error message pops up stating: ...

JQuery - Issue with setTimeout Function on Mouseleave Event

I am currently facing an issue with the script below. The goal is to display a div instantly when hovering over a specific area, and then make it disappear after a certain amount of time when leaving that area. Everything works perfectly, except if the mou ...

Utilize Bootstrap to showcase YouTube videos on your local environment

Here's the code I'm using to showcase a YouTube video: <div class="mbr-gallery-item mbr-gallery-item--p1 video-slide" data-video-url="https://www.youtube.com/watch?v=Bhy-laGxglg&amp;t=1s" data-tags="Awesome"><div href="#lb-gallery1- ...

Select2.js Dropdown List with Case Sensitivity

Currently making use of select2.js version 4.0.3 Situation: Imagine the dropdown list contains the following options: JavaScript javascript Javascript javaScript So, when a user types in java, all options are displayed (case is n ...

Click on the <a> tag to submit the form

I currently have: <ul> <form name="myform" action="Users" id="myform" method="post"> <li><a id="target" name="target" value='A' href="#">A</a></li> <li><a id="target" name="target" value=&ap ...

Switch the image displayed on hover over an image using the #map attribute

Recently, I successfully integrated a database connection into this website and made it dynamic. The overall design of the site was already in place, so my main focus was on adding the functionality of the database connection. However, after implementing ...

The Bootstrap Tooltip seems to be glued in place

Utilizing jQuery, I am dynamically generating a div that includes add and close buttons. Bootstrap tooltips are applied to these buttons for additional functionality. However, a problem arises where the tooltip for the first add button remains visible even ...

The JavaScript function fails to give back the parameter values

After creating a function in the script tag within the head section that takes two parameters, a and b, to return the product of a multiplied by b, I encountered an issue. When calling the function with the values 3 and 4, nothing was displayed. To troubl ...

Utilizing Ajax for Multiplication

Is there a way to dynamically calculate and display the total amount by multiplying the unit price with the quantity entered in the text box as it changes? <div> <label id="" name="price" class="unitprice"><?php echo "Price: <label ...

Using the jquery-ui-daterangepicker to fetch date values within an MVC controller

I have successfully implemented the jquery-ui-daterangepicker. How can I extract the start and end dates when submitting to my controller? Controller: [HttpPost] public ActionResult EmailReport(DateTime start, DateTime end) { int totalEma ...

Issue with JavaScript HTML Section Changer not functioning properly

I need to implement a button that switches between two pages when pressed. Although the code seems simple, I am struggling to make it work. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"& ...

Adjusting the size of images using CSS

Assuming an image has dimensions of 200px by 200px and is assigned a CSS class with the same measurements, will the browser retain the image size or still attempt to resize it through CSS? Lately, I have been investigating ways to decrease page loading ti ...

Angular - Render distinct options in dropdown depending on criteria

In the HTML code, I have a condition to display the value of data as a dropdown. Now, I want to introduce another condition where when a different dropdown menu with company names is changed (e.g. changing it to 'Amazon'), only the corresponding ...

Having trouble with jQuery dialog popups not appearing as expected? Instead of popping up as intended, do they simply show up on the page

I am having some trouble with a few small divs that are supposed to pop up when a certain event occurs. However, instead of popping up, they are appearing within the content of the page. Does anyone have any insights into why this might be happening? Addi ...

What causes the absence of CSS classes in production while utilizing Tailwind and next.js?

Tailwind version: v9.3.5 PostCSS Configuration: // postcss.config.js module.exports = { plugins: { tailwindcss: {}, autoprefixer: {}, ...(process.env.NODE_ENV === 'production' ? { '@fullhuman/p ...

Tips on how to store the values of dynamically generated textboxes into a variable

Trying to insert dynamic values from multiple rows of textboxes into a variable, then send it through ajax json to the server side. This is the code for generating multiple dynamic values. $('#btnASize').click(function() { var sizerangeMin = " ...

Javascript Custom Scrollbar Issue

var start_mouse_y = 0; var scroll_offset = 0; function SET_SCROLL_EVENT(e){ document.getElementById("online_list_scroll").draggable = true; start_mouse_y = e.clientY; } function ADJUST_SCROLL_EVENT(e){ dont_pass = (412 - set_scroll_heig ...

The function 'attachEvent' is not supported by the object in Internet Explorer 11

When clicking the send button "Saada" on a form in IE11, an error message appears: Object doesn't support property or method 'attachEvent' This issue seems to be specific to IE11, and the workaround I found so far is to manually switch the ...