When I added a border in CSS and inserted a link within that border, the link ended up extending beyond the border itself

I decided to create a border class for my link and placed the link inside that border. However, when I view it on a responsive device, the link extends beyond the borders while the text within the border remains intact. How can I fix this issue?

Here is my CSS:

.border { 
    border: 1px solid #cc0000;
    border-radius: 8px;
    width: 100%;
    padding: 5px;
}

Answer №1

It seems like you have utilized an element with a display: block property for your .border class:

.border {
  border: 1px solid #cc0000;
  border-radius: 8px;
  width: 100%;
  padding: 5px;
}
<div class="border">
  <a href="https://google.com">Google</a>
</div>

The default display value of <div> is block, resulting in full width.

To resolve this, consider utilizing an element with display: inline:

.border {
  border: 1px solid #cc0000;
  border-radius: 8px;
  width: 100%;
  padding: 5px;
}
<span class="border">
  <a href="https://google.com">Google</a>
</span>

Alternatively, you can directly add display: inline to the styles of your .border class:

.border {
  border: 1px solid #cc0000;
  border-radius: 8px;
  width: 100%;
  padding: 5px;
  display: inline; /* <---- */
}
<div class="border">
  <a href="https://google.com">Google</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

Use a foreach loop to iterate over an array of dates and display them in individual tables

I am currently working on structuring my foreach loop to iterate through all the dates in my time stamp arrays. The goal is to display the results in 5 separate tables, each pertaining to one of the dates. Below is the function I've implemented to re ...

Solid white border encasing the full page

While I know there have been similar questions asked before, I believe mine is unique because I haven't found a solution anywhere. Recently, I started a new project in React. I decided to remove App.css and index.css, and created a single component wh ...

How come @keyframes animations do not seem to cooperate with Vue.js?

I'm attempting to create a flashing link upon site load, but I'm encountering issues with the animation not working in Vue. Interestingly, when testing the same code without Vue in a separate file, it functions perfectly fine. Below is the spec ...

What is the best way to align a drop-down menu within my DIV container?

Here is the code snippet I am working with: <div id="one"> <a href="#" id="test1" > <button title="test1">test1</button> </a> <a href="#" id="test1" > <button title="test1">test1</button> &l ...

How can I make CSS text-overflow ellipsis trigger a pop-up to display lengthy text when clicked?

I'm encountering an issue with a lengthy sentence in a table cell which I've truncated using text-overflow to display ellipsis. Is there a way to enable users to click on the dots (...) and view the full text in a popup window? table { wi ...

Leap over in a similar fashion to the provided demonstration

In my attempt to create a unique project, I have created this CodePen example. The goal is to have one ball on the circle that remains in a fixed position, while another rotating main ball must avoid touching it at all costs. Points are awarded for success ...

What is the process for incorporating PHP into a three-dimensional virtual world?

I recently completed a client's website using a combination of PHP and basic HTML/CSS. The site's main feature is the ability for users to upload images and view them in a digital art gallery. Essentially, I positioned the images against a backgr ...

In my development environment, the page does not have scroll functionality, but in the production environment, it is scrollable

Whenever I open a table or any other element with overflowing content, I encounter an issue with the scrolling bar. Even though the CSS includes overflow-y: scroll;, the scroll bar on the right remains in gray and does not allow me to scroll down when the ...

Div expanding beyond intended size when media reaches maximum 468 pixels

When zoomimg is set to width: 145px; height: 145px; it ends up pushing the text that should be inside its parent element out of the parent. If you want to see the Zoomimg ProjectKort divs, check out the code below: .projectkort{ margin: 10px 0px 10px 0 ...

Thumbnails failing to line up in a continuous row

Having an issue creating a row with 3 thumbnails as they are not aligning in a single row, instead each thumbnail is going into a different row. echo "<table>"; echo "<tr>"; echo "</tr>"; while($r ...

Is it detrimental to my search engine ranking if I utilize CSS display:none?

Imagine having valuable content that is initially hidden with CSS, and then using javascript to reveal it only when the user clicks on certain links. Even users without javascript enabled can access this content by following the links to a new page where i ...

To ensure a rectangular image is displayed as a square, adjust its side length to match the width of the parent div dynamically

How can I make the images inside my centered flexbox parent div, #con, be a square with side length equal to the width of the parent div? The image-containing div (.block) is positioned between two text divs (#info and #links). I want the images to be squa ...

Designing numerous vertical lists in HTML

I need help with displaying multiple lists vertically using HTML For example: +--------+---------------------------------------------+--+ | Global | Region Country Currency Account Type Entity | | +--------+---------------------------------------------+ ...

The display of data attributes is not being rendered correctly

Check out the fiddle I'm currently working on: http://jsfiddle.net/7Z8wY/9/ The HTML section looks like this: <div class="container"> <div class="right"> <div id="cityList" class="inner-table"></div> </div> ...

Struggling with applying mixins

Is it possible to select only the top border using this mixin? Currently, I only need a top border but would like to have the option to use others in the future. Using separate mixins for each side of the border seems inefficient. .bordered(@top-width: 1 ...

Mobile view causes malfunction in Bootstrap Toggle Burger Menu functionality

<nav class="navbar navbar-expand-lg navbar-dark px-2 " style="background-color:#E53935;"> <a class="navbar-brand" href="#">FoodFusion</a> <button class=&quo ...

What are the steps to retrieve information from a raw HTML document?

Can data be extracted from a poorly written HTML file without IDs or classes? For example, if there is an unstructured saved HTML file of a profile webpage and I want to extract specific information like 'hobbies', can PHP be used for this task? ...

Passing PHP Variables Between Pages

I'm currently working on building a game using html5(phaser js) and I need to create a leaderboard. Here's the code snippet I have: restart_game: function() { // Start the 'main' state, which restarts the game //this.game.time.events ...

css Apply styles to form controls only if they are not empty

Utilizing an angularjs form, I have customized the following example to fit my code: .my-5 { margin:100px; } .form-group { position: relative; margin-bottom: 1.5rem; } .form-control-placeholder { position: a ...

Using CSS3 to Enhance the Look of Multiple Background Images

While I've come across similar inquiries, I haven't found a satisfactory explanation yet. My aim is to grasp the best CSS practices for implementing multiple repeating backgrounds. Essentially, I want a background image to repeat across the entir ...