Movement occurring outside the boundaries of the element

Whenever I hover over the hyperlink, it extends beyond the text of the link.

Check out the jsFiddle demonstration: jsFiddle

It seems like it is taking the width of the <div>, causing it to be displayed across the entire <div>.

Below is the HTML code (using foundation):

<div class="container row">
    <a href="#">
        <div id="logo" class="large-3 columns">
            <span>My Bank ,too Big</span>
        </div>
    </a>
</div>

How can I fix this issue without modifying the foundation classes? Could it be related to the <span> element?

I attempted to reduce the width of the <span>, but the behavior remained unchanged.

Answer №1

One issue is that the div is nested within an a tag, causing layout problems. By default, all div tags are block elements and take up the full width, while a tags are inline and only take up as much space as needed. To fix this, simply move the a tag inside the div, as shown below:

.row.container {
  max-width: 1020px;
  margin: 0 auto;
  padding: 0 30px;
}
.row.container {
  position: relative;
}
.row.container:after,
.row.container:before {
  content: " ";
  display: table;
}
.large-3 {
  width: 25%;
}
#logo {
  margin: 46px 0 0;
  padding: 0 0 46px;
}
<div class="container row">
  <div id="logo" class="large-3 columns">
    <a href="#">
      <span>My Bank ,too Big</span>
    </a>
  </div>
</div>

Answer №2

To ensure the entire clickable area is preserved within the #logo rule, simply add the following code:

#logo {
  display: inline-block;
  width: auto;
}

This will maintain the entire <div> element as the clickable region, rather than just the <span>, while also keeping the width of the <div> consistent with the text.

You can test out the code snippet below:

.row.container {
  max-width: 1020px;
  margin: 0 auto;
  padding: 0 30px;
}
.row.container {
  position: relative;
}
.row.container:after,
.row.container:before {
  content: " ";
  display: table;
}
.large-3 {
  width: 25%;
}
#logo {
  margin: 46px 0 0;
  padding: 0 0 46px;
  background: lightgreen;
  display: inline-block;
  width: auto;
}
<div class="container row">
  <a href="#">
    <div id="logo" class="large-3 columns">
      <span>My Bank ,too Big</span>
    </div>
  </a>
</div>

Answer №3

To adjust the width of #logo, you can set it to auto and then change the anchor to inline-block.

Another option is to set #logo to either display: inline-block or inline. The issue arises when a block element like <div> is placed inside an inline element such as <a>.

.row.container {
  max-width: 1020px;
  margin: 0 auto;
  padding: 0 30px;
}
.row.container {
  position: relative;
}
row.container:after,
.row.container:before {
  content: " ";
  display: table;
}
.large-3 {
  width: 25%;
}
header #logo {
  margin: 46px 0 0;
  padding: 0 0 46px;
}
#logo {
  width: auto;
}
.row.container a {
  display: inline-block;
}
<div class="container row">
  <a href="#">
    <div id="logo" class="large-3 columns">
      <span>My Bank ,too Big</span>
    </div>
  </a>
</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

expanding the close window icon beyond the boundaries of the modal container

I seem to be experiencing a CSS mistake that I can't figure out. The close window icon in my modal window is getting cut off at the edge and not displaying properly. Check out this JSFiddle link <div id="sendMsgForm" class="modal"> <div ...

What is the best way to ensure that the text within Span children is properly laid out to match the width of the parent div tag?

This particular instance involves setting the width of the div tag to 200px and organizing all the span children to occupy the entire width of the parent div tag. If the first row is filled, the span tags should then flow into a second row. My attempt at ...

Struggling to figure out the method for obtaining css selectors for scraping in scrapy

Struggling with scraping a website and figuring out how css selectors work in Scrapy. The css in question: https://ibb.co/eJeZpb Here are some standard css selectors: .css-truncate-target .message .js-navigation-open time-ago For scrapy, you would need ...

Choosing Only the Visible Element with CSS

Within my program, there exists a text element that appears in two distinct sections: section A and section B (in the form of a popup). My intention was to create one object using CSS that could be utilized in both areas. By doing so, I would be able to em ...

Is it possible to customize bootstrap classes for a unique bootstrap css design?

In my MVC4 project, I faced a situation where I had a global.css class with some classes that conflicted with Bootstrap after adding it. To resolve this, I created a new file called bootstrap_migration.css. In this file, I prefixed the Bootstrap classes wi ...

The scrollbar remains unresponsive and fixed until the screen size is adjusted

Need some assistance with a website project for a client. The scrollbars on each page are not loading or changing height until the window is resized. I have a jQuery scrollbar in place, but disabling it does not solve the issue as the normal scrollbar beha ...

Experiencing problems with web page layout when using bootstrap on IE8?

Here is a code snippet that functions correctly in IE9 and later versions, but encounters issues in IE8: <div class="col-lg-5 col-md-5 col-sm-6 col-xs-6" id="div1"> <div class="panel panel-default" style="" id="panel1"> ...

Ensuring a consistently positioned footer at the bottom

I understand that this might not seem like a significant issue, but I'm encountering some difficulties. In my main.html file, there are three divs. The first div contains the navigation bar, the second div is an "empty" div that uses JQuery/Javascript ...

Resizing SVG to specify width in pixels and automatically adjust height

I'm having trouble understanding how SVG works. Can someone explain where my mistake is? Here's an example of my inline SVG code: <div style="width:1000px; height:auto; background-color:blue;"> <svg class="_image"><use xlink ...

Adjust the clarity of the elements within my HTML document

I have been working on creating a login page that will appear in front of the main webpage. Through my online research, I discovered a technique to blur the main webpage background until the user logs in. Below is the code snippet: HTML: <div id="logi ...

Arranging three items within a div container

I am facing an issue with the layout provided in the code snippet below. Essentially, there is a div container with tools on the left side, main content in the center, and tools on the right side (a visual drag handle on the left and a delete button on the ...

Using the swiper carousel on WordPress results in an unexpected horizontal scrolling issue

Running an Elementor website, I need to incorporate various image carousels within my post content. Initially, I created a template for each carousel using Elementor. However, I have now decided to switch to utilizing a shortcode that leverages Elementor&a ...

Effective Methods for Implementing CSS Variables within nth-child Selectors

Objective: To pass a variable successfully as a parameter to nth-child. The task is to make the third line turn green in the example provided. Dilemma: Currently, the parameter is being disregarded as a variable. Inquiry: Is achieving this possible? If s ...

"Verifying the dimensions of the input sizes with the i

It's possible that this question has been asked before on this platform. However, I haven't come across a satisfactory answer yet. How can I adjust the size of inputs in the iCheck library? The current size is too large for my website. Css: .ic ...

What is the best way to re-render a component immediately following an update in React?

As I attempt to change the color of a bar to green and then back to black, it seems like the latter color update is taking precedence in my code. const [color, setColor] = useState("black") const bubbleSort = async () => { const sleep = ms => ...

I'm feeling pretty lost when it comes to understanding how line-height and margins work together

When creating a webpage layout, my goal is to maintain balance by ensuring there is an equal amount of spacing between sections and elements. However, when dealing with varying font sizes and line heights, achieving this can be challenging. To provide fur ...

Using jQuery to create dynamic CSS effects directly on the drop-down menu button

Seeking your kind assistance once again... I am attempting to design a navigation bar that displays the dropdown section upon hovering over the buttons AND shows a bottom border on the button that was last hovered over My code functions properly when I ...

Moving Text Over a Static Background Image in HTML and CSS

Currently working on developing a website that involves coding in HTML and CSS. However, I've encountered an issue while programming. Whenever I attempt to adjust the positioning of my text, the background image shifts along with it, making it impossi ...

When viewing the material-ui Chip component at normal zoom, a border outlines the element, but this border disappears when zoomed in or out, regardless of

Edit I have recently discovered a solution to the unusual problem I was facing with the material-ui Chip Component. By adding the line -webkit-appearance: none; to the root div for the Chip, the issue seems to resolve itself. However, this line is being a ...

What is the best method for aligning buttons in a row with all the other buttons?

I have been attempting to display two buttons, id="strength" and id="minion", when a certain button, id="expandButton", is clicked. I want these two buttons to be positioned on either side of the button that triggers their cre ...