Decrease the interactive area for an image

I have successfully designed a left navigation bar using buttons. Currently, I am facing two main issues that I need assistance with. Firstly, I am trying to limit the hyperlink area to just the background image. Secondly, the elements that are overlaying the background image are covering the hyperlink, making the button unclickable. For reference, you can view the page here:

Let's focus on the hyperlink area:

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

Now, let's examine the background image area:

https://i.sstatic.net/6H4qQ.png

.img-responsive {
    display: block;
    padding: 0;
    margin: 0;
}
.background:hover .head {
    color: #d76e08;
}
.overlay {
    position: absolute;
    z-index: 1;
    top: 0;
    left: 0;
    color: white;
}
.icon {
    padding-top: 15px;
    padding-left: 40px;
}
.head {
    margin-top: -75px;
    padding-left: 120px;
}
.content {
    margin-top: -5px;
    padding-left: 120px;
    padding-right: 35px;
}



<div class="row">
    <div class="col-sm-12">
        <div class="background">
            <a href="../Collin/misc/issues/index.html">
                <img alt="background" class="img-responsive" src="buttons/images/button.png" />
            </a>
            <div class="overlay">
                <div class="icon">
                    <img alt="test" class="img-responsive" src="buttons/images/info-icon.png" />
                </div>
                <p class="head">Ask Facilities</p>
                <p class="content">Here will be text about the button. .</p>
            </div>
        </div>
    </div>
</div>

Answer №1

I'm looking to minimize the clickable area to just the background image.

Your coding seems overly complicated for the content you want to display.

You might consider something like this:

<ul>
<li>
<a>
<h2></h2>
<p></p>
</a>
</li>

<li>
<a>
<h2></h2>
<p></p>
</a>
</li>
</ul>

Then, use CSS to insert the image and gradient.

Answer №2

To create a stylish button, utilize a single link tag and incorporate CSS gradients for the background:

* {
  box-sizing: border-box;
}

body {
  font-family: sans-serif;
}

.button {
  background-image: linear-gradient(to bottom, #3D85C6, #07355F 50%, #07355F);
  background-size: 100% 200%;
  border-radius: 4px;
  color: #fff;
  display: block;
  padding: 10px;
  text-decoration: none;
  transition: all 150ms ease-in-out;
}

.button:hover,
.button:focus,
.button:active {
  background-position: 0 50%;
}

.button-icon {
  float: left;
  margin-right: 15px;
}

.button-content {
  overflow: hidden;
}

.button-title {
  font-size: 18px;
  font-weight: bold;
}

.button-description {
  font-size: 16px;
}
<a class="button" href="../Collin/misc/issues/index.html">
  <div class="button-icon">
    <img src="http://satyr.io/72/white?brand=github" alt=""/>
  </div>
  <div class="button-content">
    <p class="button-title">Ask Facilities</p>
    <p class="button-description">Here will be text about the button…</p>
  </div>
</a>

For a live example, visit http://jsbin.com/rikisemawe/edit?html,css,output

Answer №3

The markup for the elements in OP was not nested, resulting in the unusual position coordinates and large padding. To improve this, some tags like <button> and <h4> were used instead of <p>, and <img> was replaced with background-image.

SNIPPET

.button {
  position: relative;
  min-width: 350px;
  max-width: 100%;
  min-height: 95px;
  height: auto;
  padding: 5px 10px;
  border: 0 none transparent;
  border-radius: 6px;
  background: url(http://www.auburn.edu/administration/facilities/home-page/buttons/images/button.png)no-repeat;
  background-size: cover;
}
.background:hover .head {
  color: #d76e08;
}
.text {
  padding: 0 5px;
  position: absolute;
  left: 85px;
  top: 5px;
  text-align: left;
  color: #def;
  text-decoration: none;
}
.button:hover,
.text:hover {
  text-decoration: none;
  color: #def;
}
.button:hover .head {
  color: gold;
}
.icon {
  width: 75px;
  height: 75px;
  position: absolute;
  top: calc(50% - 37.5px);
  background: url(http://www.auburn.edu/administration/facilities/home-page/buttons/images/service-icon.png)no-repeat;
}
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


<div class="row">
  <div class="col-sm-12">


    <button class="button">

      <div class="icon"></div>
      <a class='text'>
        <h4 class="head">Ask Facilities</h4>
        <p class="content">Here will be text about the button.</p>
      </a>

    </button>

  </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

Achieving Vertical Alignment in a Bootstrap 4 Image Overlay Card

I am facing a challenge in trying to vertically center a FontAwesome icon within an Image Overlay Card. Despite attempting various methods like using d-flex and justify-content-center, none of them seem to be effective. What could I be overlooking? < ...

What methods can be used to control the URL and back button in a web application designed similar to an inbox in Gmail?

Similar Question: Exploring AJAX Techniques in Github's Source Browser In my application, there are essentially 2 main pages: The main page displays a list of applications (similar to an inbox) The single application page is packed with various ...

Issues arise when trying to use the Jquery append() method in conjunction with Angular

We are currently utilizing jquery version 1.9.1 and angular version 1.2.13 for our project. Our wysiwyg editor is functioning well, as we are able to save HTML into the database and load it back using the jquery append function successfully. However, we ar ...

Leverage Bootstrap 4 for achieving flexible layouts and centering content with two elements using flex and justify-content

By using the d-flex, justify-content-center, and flex-grow-1 classes, I was able to achieve my desired layout with just 3 divs. <div class="row bg-primary d-flex justify-content-center"> <div class="col-auto"> LEFT </div> < ...

Closing a bootbox alert by clicking on a href link

Utilizing bootbox alert within my Angular2 application to present information to users on the UI. The alert message includes href links, and I want the page to navigate to the clicked link while also closing the bootbox modal. However, I am facing an issue ...

What is the process for adding color to the rows of a table?

Hello, I have a table with various fields that include: I am looking to assign colors to entire rows in the table based on certain criteria. For example, if the ASR value falls between 75 and 100, it should be assigned one color; for values between 50 and ...

The webpage appears fine on the local server, but displays incorrectly on IIS (Internet Explorer 11)

My project looks great when I run it locally on my computer and open the page in Internet Explorer 11: https://i.stack.imgur.com/yZvo2.png However, when I deploy the page to an IIS server and navigate to the page, it appears differently in Internet Explo ...

What is the best approach to determine the value of a textbox in an array for each row of

I am trying to display the total sum of values for each row in a data array. There are 5 rows of data, and I need to calculate the results for each one. Can someone assist me in solving this? function calculateTotalValue(){ var total = (document.get ...

Retrieve data from an external website containing an HTML table without a table ID using Java Script and transform it into JSON

I have developed a script that can convert HTML table data into a JSON Object. To accomplish this task, I utilized the jquery plugin created by lightswitch05. With this code, I am able to extract data from an HTML table on the same web page using: var t ...

Conceal and reveal elements using a specific identifier with

Web Development Guide <ul id="menüü"> <li id="meist"> <p><a href="meist.html">Meist</a></p> </li> </ul> <div id="submenu"> <ul id="submeist"> ...

Mastering jQuery UI: A beginner's guide to utilizing the date picker widget

This is my first venture into the world of HTML and JavaScript, so I am asking for your patience. I am trying to incorporate the Datepicker widget from jQuery UI, following the instructions on the Getting Started page. There seems to be an issue with lin ...

Improved efficiency in CSS for left transition animations

Here is the current code I am using: .s2 { top: 150px; left: 20px; position: absolute; transition: left 300ms linear; } I am currently updating the left position dynamically using JavaScript based on scroll events. However, I have noticed that th ...

Is it possible to leverage the flex features of react-native in a manner similar to the row/column system of

Is it a good idea to utilize flex in react native by creating custom components that retrieve flex values? I previously used the bootstrap grid system and now I am exploring react native. Is there a way to implement this example using react-native bootstr ...

Using javascript to color in cells of a grid of "pixels"

I have a project similar to an Etch-a-Sketch in progress. The main challenge I am currently facing is how to gradually darken each cell of the grid with every pass of the mouse cursor, based on the opacity of the cell being hovered over. When the grid cell ...

After being reloaded multiple times, the time and date mysteriously vanish

Issue with Javascript/jQuery/jQuery Mobile Code After reloading or refreshing the page multiple times, the values for currentDate and currentTime seem to disappear sporadically. Strangely, they start working fine again after a few more reloads. Can anyone ...

Issue with fancyBox not functioning properly when integrated with a caption script

Hey there! I've been working with both jQuery's fancyBox for displaying image/video galleries and the Capty script for showing image titles on images. However, I've run into a snag - when the title is displayed on the image, fancyBox st ...

Increase the font size of a div using CSS to make it appear larger

Utilizing a WYSIWYG-editor, I am creating content that I want to display with double font-size, without directly altering the HTML code. Here is an example of the HTML structure: <div id="contents"> <p style="text-align:center"> <spa ...

Set the input's type attribute to 'checkbox' to address an issue with Internet Explorer

This issue is specific to Internet Explorer, as other browsers like Firefox, Chrome, Safari, and Opera are functioning correctly. Instead of displaying checkboxes, it shows a value box... Here is the code snippet: <html> <head> <title> ...

What could be causing the issue of this JQuery dropdown plugin not functioning properly on multiple dropdowns?

I have implemented a JQuery plugin for dropdown menus that can be found at the following link: https://code.google.com/p/select-box/ Currently, I am facing an issue where the script only seems to work for the first dropdown menu out of 4. I am unsure abo ...

Tips for creating a stylish scrollbar in a React Material-Table interface

Currently, I am utilizing the react material-table and looking to implement a more visually appealing scroll-bar instead of the default Pagination option. Although I have experimented with the react-custom-scroll package, it has not produced the desired ...