In Google Chrome, the :after element on the left is cleared, while other browsers do not

In an effort to create a button using background images in the :before and :after pseudo-selectors for cross-browser compatibility, an issue arose where only Chrome did not display it correctly (Safari results were unknown).

HTML:

<div class="btn-container align-right more-info-btn">
        <a class="btn" href="#">Super Button<i class="arrow-after-right"></i>
    </a>
</div>

CSS:

.btn-container .btn {
    display: inline-block;
    text-decoration: none;
    height: 24px;
    background: transparent url('http://img842.imageshack.us/img842/5052/kdti.png');
    padding: 0 6px;
    font-size: 11px;
    line-height: 21px;
    font-weight: bold;
    color: red;
    font-family: Helvetica, Arial, FreeSans, Verdana, Tahoma, 'Lucida Sans', 'Lucida Sans Unicode', 'Luxi Sans', sans-serif;
}
.btn-container .btn:before {
    content:'';
    display: inline-block;
    background: transparent url('http://img600.imageshack.us/img600/3825/6ppo.png') no-repeat;
    width: 4px;
    height: 100%;
    margin-left: -10px;
    float: left;
}
.btn-container .btn:after {
    content:'';
    display: inline-block;
    background: transparent url('http://img834.imageshack.us/img834/4803/b5zs.png') no-repeat;
    width: 4px;
    height: 100%;
    margin-right: -10px;
    float: right;
}

Google Chrome Button Rendering:

Button Display in Other Browsers:

jsFiddle:

http://jsfiddle.net/K7y4U/4/

Attempts have been made to adjust float/clear settings with no success.

Answer №1

To fix the issue, add a specific width to the .btn_container element. This will resolve the problem you are experiencing. You can view an example here: http://jsfiddle.net/K7y4U/6/

In my solution, I added the following CSS rule:

.btn-container .btn { width: 90px; }

Answer №2

This JSFiddle link

When it comes to styling elements, Floats and Inline Blocks don't always mix well.

.btn-container .btn {
    vertical-align:top;
    line-height:24px;
    display: inline-block;
    text-decoration: none;
    background: transparent url('http://img842.imageshack.us/img842/5052/kdti.png');
    padding: 0 0 0 6px;
    font-size: 11px;
    height:24px;
    font-weight: bold;
    color: red;
    font-family: Helvetica, Arial, FreeSans, Verdana, Tahoma, 'Lucida Sans', 'Lucida Sans Unicode', 'Luxi Sans', sans-serif;
    min-width: 90px
}
.btn-container .btn:before {
    content:'';
    display: inline-block;
    background: transparent url('http://img600.imageshack.us/img600/3825/6ppo.png') no-repeat;
    width: 4px;
    height: 100%;
    margin-left: -10px;
}
.btn-container .btn:after {
    content:'';
    display: inline-block;
    background: transparent url('http://img834.imageshack.us/img834/4803/b5zs.png') no-repeat;
    width: 4px;
    height: 100%;
    margin-right: -10px;
}
.btn-container .arrow-before-right:before, .btn-container .arrow-after-right:after, .arrow-link-container.arrow-before-right:before, .arrow-link-container.arrow-after-right:after {
    border-color: transparent transparent transparent blue;
}
.btn-container .arrow-before-down:before, .btn-container .arrow-before-left:before, .btn-container .arrow-before-right:before, .btn-container .arrow-before-up:before, .btn-container .arrow-after-down:after, .btn-container .arrow-after-left:after, .btn-container .arrow-after-right:after, .btn-container .arrow-after-up:after, .arrow-link-container.arrow-before-down:before, .arrow-link-container.arrow-before-left:before, .arrow-link-container.arrow-before-right:before, .arrow-link-container.arrow-before-up:before, .arrow-link-container.arrow-after-down:after, .arrow-link-container.arrow-after-left:after, .arrow-link-container.arrow-after-right:after, .arrow-link-container.arrow-after-up:after {
    border-width: .4em .45em;
    border-style: solid;
    content:'';
    display: inline-block;
    margin-left: .4em;
    vertical-align:top;
    margin-top:7px;
}

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 identifying when a video's autoplay feature does not function properly on all web browsers

My search for the most optimal method to automatically play a video in the background led me to discover some interesting findings based on the latest data available. VVC/x266 - Versatile Video Coding: Offers significant reduction in data requirements wi ...

Is there a way to specifically import only variables and mixins from Sass stylesheets?

Using the Zurb Foundation 4 (S)CSS framework has presented a challenge with massively duplicated styles. Each file that I import 'foundation' into brings along all of Foundation's styles, resulting in redundant declarations for body, .row, . ...

Is Your Mobile Site Displaying Differently?

Although my resume website looks great on Desktop, I recently noticed that the HTML paragraph tags do not scale correctly when viewed on various mobile web browsers (refer to the images attached below). Screenshot 1: Website displayed in Facebook Messenge ...

Is it possible to customize the arrow on a drop-down menu?

Here is an example of the page I am facing issues with: If you look at the right side of the bottom bar, you will notice a selection option for different themes. I have been attempting to replace the down arrow with an image. Below is the code I have used ...

How to align the last item in the bottom row using Flexbox styling

Is it possible to center the last element when resizing the window to a smaller resolution, even though the parent's justify-content parameter is set to space-between? I understand that using center or space-around would achieve the desired result, bu ...

Utilizing Webpack to emulate the @apply functionality of Tailwind CSS and shift away from using @extend in SASS

I am currently developing an internal CSS 'framework' / methodology that falls somewhere in between ITCSS and Tailwind. We heavily rely on utility classes, but sometimes the length of the actual class name becomes too much and we feel the need t ...

When using NextJS, the dynamically generated HTML elements do not get affected by CSS repaint

Recently, I encountered an issue while working on a Next.js project involving the addition of an external script that uses vanilla JavaScript to dynamically create nodes. Despite importing global CSS at the top of my _app.js file, I noticed that the styles ...

What causes the element to load with a transparent appearance? And why is my JavaScript code overriding the hover effect on it?

My goal is to have an element fade out when clicked and then fade back in when its space is clicked again. I also want the opacity of the element to be 0.9 instead of 1 when visible. I've encountered two issues with my code. First, the hover selector ...

Changing the class of an element using CSS when hovering over another

Is it possible to dynamically change the style of another element when hovering over a specific element? For example, I want a menu item to change its appearance when hovering over a submenu item. Here is the CSS code I have: ul.menu .menulink { padding ...

How should one correctly align various classes in a cascading manner within CSS?

Here is an interesting challenge - I want each of these buttons to have their background image change when hovered over. However, I'm struggling with the class setup in my code. I've been trying to understand how to distinguish between divs and c ...

What is the method for increasing the left margin of the back button on the default header in React Native?

My attempt to increase the space on the back button from the left side of the header in my React Native code has been unsuccessful. headerStyle: { paddingLeft: 60 } https://i.stack.imgur.com/0RFb0.png I also experimented with adding margin ...

What is the proper way to eliminate the top margin from a div that has the display table-cell property?

There are two div elements with display: table-cell property: <div> This is a table cell </div> <div> <h1>Some content</h1> <h1>Some content</h1> <h1>Some content</h1> <h1>Som ...

Tips for aligning a form in the center of a webpage

I have a code snippet using material-ui that I want to center on the page, but it's not working. Can someone please help me fix this issue? Thank you in advance. import React from 'react'; import { makeStyles } from '@material-ui/core ...

Tips for defining a relative path in the base URL with AngularJS

Encountering an issue with AngularJS routes related to file paths. The folder structure is as follows: js -> Angular -> css -> Bootstrap -> index.html Routes work fine when hosted on a server like IIS. However, copying and pasting the direct ...

Tips for switching the background image in React while a page is loading?

Is there a way to automatically change the background of a page when it loads, instead of requiring a button click? import img1 from '../images/img1.jpg'; import img2 from '../images/img2.jpg'; import img3 from '../images/img3.jpg& ...

Unexpected behavior observed when trying to smoothly scroll to internal links within a div, indicating a potential problem related to CSS dimensions and

Within a series of nested div containers, I have one with the CSS property overflow:hidden. My goal is to smoothly scroll to internal links within this specific div using jQuery. The snippet of code below has worked successfully in previous projects: ...

chrome side column must be set to 100% height

Having trouble with setting height to 100%. I have a list of items that need to be distributed to match the height of the side image. It works fine when I use a fixed height, but not with a percentage. The issue arises because the website is responsive a ...

JavaScript for Dynamic Scaling Animations

I am currently working on animating an SVG button and I am trying to incorporate the transform property with a fadeout using opacity attributes in Javascript. This is how I have attempted to write the code: (Starting with opacity 0 and scale 0) (I am awa ...

Stop images from appearing transparent when placed inside a transparent div

My issue is clearly visible in this image: The div element is transparent and affecting the images inside it. Below is my HTML code: <div id="cselect" style="position: absolute; top: 99px; left: 37px; display: block;"> <div class="cnvptr"> ...

Disabling the 'fixed navigation bar' feature for mobile devices

Here's a code snippet that I'm working with. It has the ability to make the navigation stick to the top of the page when scrolled to. HTML <script> $(document).ready(function() { var nav = $("#nav"); var position = nav.position(); ...