Place the span element above the div container

I recently created some social media buttons with share counters, but I'm facing an issue where the counter data appears inside the buttons rather than on top of them. Has anyone encountered this problem before?

  1. Is there a way to display the number of shares on top of the button instead of inside it? If so, how can this be achieved?

  2. Despite using CSS properties like float: left and text-align: left, the text inside each social button remains centered. Does anyone know why this might be happening?

You may find my code snippet on JSFiddle for reference... Link to Fiddle

Below is my HTML markup:

<a class="post-share facebook entShare" target="entsharewindow" href="#">
<div class="social-buttons-text">Facebook Like</div><span>0</span>
</a> 
<a class="post-share facebook entShare" target="entsharewindow" href="#">
<div class="social-buttons-text">Facebook Share</div><span>0</span>
</a> 
<a class="post-share twitter entShare" target="entsharewindow" href="#">
<div class="social-buttons-text">Twitter</div><span>0</span>
</a> 

This is my CSS styles:

a.post-share {
    display: block;
    width: 74px;
    height: 34px;
    float: left;
    margin: 10px 0px 0px 0px;
    background: #3e599a url(sidebar-share.png) no-repeat 0 0;
    text-decoration:none;
    width: 110px;
    text-indent: 50px;
    font: 15px/46px "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
    color: #FFFFFF;
}
a.post-share:hover {
    opacity: 0.8;
    text-decoration: none;
    cursor: pointer;
}

a.post-share span {
    width: 22px;
    height: 18px;
    padding: 3px;
    display: block;
    float:right;
    background-color:#080563;
    color: #FFFFFF;
    font-style:bold;
    vertical-align: middle;
    font: 10px "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
    text-align:center;
    text-indent: 0;
}

a.post-share.facebook {
background-color: #3B5998;
background-image: url('/images/social-icons/facebook-32.png');
margin-right: 10px;
}

.social-buttons-text {
    font-size:4px;
    color:#FFFFFF;
    float:left;
    margin:0px;
    padding:0px;
    text-align:left;
}   

Answer №1

  • One way to align elements in CSS is by setting the position property to relative for the parent element and absolute for the child element, along with defining values for top and left

a.post-share {
  display: block;
  width: 74px;
  height: 34px;
  float: left;
  margin: 40px 0px 0px 0px;
  background: #3e599a url(sidebar-share.png) no-repeat 0 0;
  text-decoration: none;
  width: 110px;
  font: 15px/46px"Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
  color: #FFFFFF;
  position: relative;
}
a.post-share:hover {
  opacity: 0.8;
  text-decoration: none;
  cursor: pointer;
}
a.post-share span {
  width: 22px;
  height: 18px;
  padding: 3px;
  display: block;
  position: absolute;
  top: -24px;
  right: 0;
  background-color: #080563;
  color: #FFFFFF;
  font-weight: bold;
  vertical-align: middle;
  font: 10px"Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
  text-align: center;
  text-indent: 0;
}
a.post-share.facebook {
  background-color: #3B5998;
  background-image: url('/images/social-icons/facebook-32.png');
  margin-right: 10px;
}
a.post-share.facebook {
  background-color: #3B5998;
  background-image: url('/images/social-icons/facebook-32.png');
  margin-right: 10px;
}
a.post-share.googleplus {
  background-color: #D14836;
  background-image: url('/images/social-icons/googleplus-32.png');
  margin-right: 10px;
}
.social-buttons-text {
  font-size: 4px;
  color: #FFFFFF;
  float: left;
  margin: 0px;
  padding: 0px;
  text-align: left;
}
<a class="post-share facebook entShare" target="entsharewindow" href="#">
  <div class="social-buttons-text">Facebook Like</div><span>0</span>
</a>
<a class="post-share facebook entShare" target="entsharewindow" href="#">
  <div class="social-buttons-text">Facebook Share</div><span>0</span>
</a>
<a class="post-share twitter entShare" target="entsharewindow" href="#">
  <div class="social-buttons-text">Twitter</div><span>0</span>
</a>

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

Prevent JavaScript from being entered into the form

I'm currently developing an "HTML editor" for one of my webpages. Right now, I want to ensure that the editor only allows input of HTML and CSS elements without any Javascript (or Jquery). I've been attempting to prevent the use of <script> ...

What is the best method for efficiently wrapping contents within a div container?

On the website cjshayward.com/index_new.html, there is a div wrapped around the content of the body, which is approximately 1000 pixels wide. In Chrome and Firefox, the wrapper works perfectly for the top section of about 100 pixels. Further down the page, ...

Having issues with the JavaScript voting system {{bindings}} returning null when clicked?

It seems like the error is not appearing in the developer tool, so it might be related to how the data is being read. Both {{upVote}} and {{downVote}} start with no value and show null when clicked, indicating that the buttons are somehow linked. I was att ...

What is the best way to line up three divs horizontally and center the contents inside each one?

I'm brand new to CSS and need some help simplifying things. I am trying to create 3 divs that are all the same size, placed next to each other, with centered content in each one. Currently, I have a central div with a rotating image, and on the left a ...

Can you explain the meaning of -ms-value?

I recently came across a solution for an issue specific to IE, and it worked perfectly for me. You can find the solution here: Change IE background color on unopened, focused select box However, I'm still puzzled about the meaning of -ms-value. Any i ...

When using jQuery, the PHP variable value is not retrieved from the DIV data-id attribute, instead it just displays the variable name

I currently have the following code: <div class= "obutton feature2" data-id=".$bookID."><button>Reserve Book</button></div> <div class="modal-box"></div> Although this button triggers the jQuery script, the modal box ...

Responsive design challenge

I'm currently working on a WordPress theme with a fixed header and footer on the homepage, and a vertical slider in between that includes content and images. I've made the website responsive, but I'm facing an issue where the content in the ...

CSS3 List Style Floating Challenge

I have encountered a seemingly simple question, but I am struggling to find a solution. In my HTML code, I have two ul elements. Each li within these lists is styled with float:left in my CSS. The reason behind this styling choice is that I am working on ...

What could be causing the image not to appear on the React app?

I'm currently working on a react website, and I'm facing an issue with the image display on the single product page. Despite trying to tweak both the react and CSS code, I haven't been able to resolve the problem. Below is my react file: im ...

What causes RangeError: Maximum call stack size exceeded when Element UI event handlers are triggered?

I'm currently working on setting up a form and validating it with Element UI. Despite closely following the documentation, I am encountering an issue where clicking or typing into the input boxes triggers a RangeError: Maximum call stack size exceeded ...

Embedding images within written content

Is there a way to insert an image into text from a specific position without using tables? I'm looking for a method other than aligning the image "left or right". ...

What is the process of choosing a language (English/French) within a pop-up?

<body style="text-align:center"> <h2>Popup</h2> <div class="popup" onclick="myFunction()">Interact with me to show/hide the popup! <span class="popuptext" id="myPopup">A Simple Popup!</span> </div> <script& ...

Utilizing AngularJS to display an array of user inputs

Hey there, hope all is well with you! I have been working on an HTML form that looks like this: <div class="table-responsive " > <table class="table table-bordered"> <tr ng-repeat="x in [1, 2, 3, 4, 5]"> <td> <td align="center" ...

Guide to changing the border color in a Material-UI TextField component styled with an outline design

To complete the task, utilize the Material UI outlined input field (TextField component from "@material-ui/core": "^4.12.2",) and apply a custom blue color style to it. Here is the outcome of my work: Current theme override for InputL ...

jQuery conceal input field after it has been displayed

I've created an HTML form with two different sections for search purposes. The first section displays basic fields, and by clicking on "Advanced Search" (in my case, "Расширенный поиск"), additional fields are revealed. Everything work ...

Accordion menu with smooth CSS3 transitions

I created a unique accordion menu to replace the select form control, and I am interested in using CSS3 transitions to give it a smooth expand and contract effect. Feel free to check out my work on jsfiddle: http://jsfiddle.net/hKsCD/4/ In order to achi ...

LabeFor does not automatically create the display-lable class attribute

When setting up a new MVC project, the default Site.css file typically includes the following styles: /* Styles for editor and display helpers ----------------------------------------------------------*/ .display-label, .editor-label { font-weight: ...

Browser comparison: Chrome and Firefox - peculiar ID name causing table width difference without CSS. Suspected AdBlocking interference

There seems to be an issue with a table I have in Chrome. Whenever I change the ID name, it either sets the width to zero or doesn't display at all. You can view it here: http://jsfiddle.net/kdubs/W6GTE/ The specific line causing trouble is: <ta ...

hiding elements yet passing down

Despite disabling the style sheet, a dynamically created form is displaying strangely. This form will show or hide various details based on selected options. For instance, many of the elements are generated with C#.net... formOutput += "<div class=&bs ...

Swapping values between HTML tables and arrays with the power of JavaScript

I have a unique table structure that I need help with: My current table has 2 rows and multiple columns, but I want to change it to have 2 columns and multiple rows like this: To create the table, I am using two arrays named milestone and milestoneDate. ...