Is there a way to center the text vertically within an anchor tag?

How do I align text vertically within an anchor tag?

Here's a visual representation of the issue:

The text "Publisher Search," "Add a New Publisher," and "Edit a Publisher" should be aligned vertically in the "bar."

This is the coding structure:

<div id="content">

    <div id="pub1">
        <form id="pub-form1">
            All Members: <input type="radio" name="preference" />
            Current Members: <input type="radio" name="preference" checked/>
            Members with User Priveleges: <input type="radio" name="preference" />
        </form>
    </div>

    <div id="pub2">
        <a href="#" id="drop">Publisher Search</a>
        <form id="pub-form2">
            Firstname: <input type="text" name="fName" />
            Lastname: <input type="text" name="lName" />
        </form>
    </div>

    <div id="pub3">
        <a href="#" id="drop">Add a New Publisher</a>
        <form id="pub-form3">   
            Firstname: <input type="text" name="fName" />
            Lastname: <input type="text"  name="lName" />
        </form>

   </div>

   <div id="pub4">
        <a href="#" id="drop">Edit a Publisher</a>
        <form id="pub-form4">
            Firstname: <input type="text" name="fName" />
            Lastname: <input type="text" name="lName" />
        </form>
   </div>

   <div id="results">
   </div>


</div>

The CSS styling:

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  height: 100%;
  background: url(../Images/bg.jpg)
}

body {
  height: 100%;
  overflow-y: hidden;
  padding: 0;
  margin: 0;
}

#content {
  width: 900px;
  height: 100%;
  margin : 0 auto;
  background: #FFF;
}

div a#drop {
  display: block;
  background-color: #283744;
  width: 70%;
  position: relative;
  color:#fff;
  height: 40px;
  padding-left: 20px;
  font-size: 11pt;
  font-family: 'PT Sans', Arial, sans-serif;
  font-weight: bold;
  text-decoration: none;
  text-shadow: 1px 1px 0px #283744;
}

div a#drop:after {
      content:"";
      background: url(../Images/1373497280_arrow_state_grey_expanded.png) no-repeat;
      width: 30px;
      height: 30px;
      display: inline-block;
      position: absolute;
      right: 15px;
      top: 10px;
} 

Your feedback is valued.

Answer №1

To make your div a#drop class have a line height of 40px, simply add line-height:40px;

Check out the FIDDLE for more details

div a#drop {
  display: block;
  background-color: #283744;
  width: 70%;
  position: relative;
  color:#fff;
  height: 40px;
  line-height:40px; /* This is where you set the line height */
  padding-left: 20px;
  font-size: 11pt;
  font-family: 'PT Sans', Arial, sans-serif;
  font-weight: bold;
  text-decoration: none;
  text-shadow: 1px 1px 0px #283744;
}

Answer №2

If you want to center something vertically, you can achieve this by using the CSS properties display: table-cell; along with vertical-align: middle;

Here is an example:

http://example.com/stylesheet


span {
  display: table-cell;
  height: 50px;
  border: solid;
  vertical-align: middle;
}

Answer №3

Why are the anchor tags the initial elements within the div and displayed first as block elements? Is there a specific purpose for having position:relative on them?

Consider using padding-top and padding-bottom instead of assigning them a height value.

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

Guidance on creating a custom color selection tool for a specific task

Looking for assistance in converting a code snippet that uses <button> elements to select colors into a color picker. I am unsure how to retrieve the selected color and use it within a JavaScript function. Can someone provide guidance on this? Here i ...

Is it possible to utilize retina images with CSS3's :before selector?

Can I adjust the size of an image inserted using :before? For example, if I want to use a high resolution image in the content below - how can I specify the dimensions? .buy_tickets_btn:before{ content: url(../images/buttons/pink_ticket_btn_bg.pn ...

Is there a way to address this scrollbar issue without relying on HTML?

Currently, I am working on a website where the only customization allowed is related to CSS. While I've been able to make progress, I've encountered an issue with the scrollbar placement. The scrollbar is extending beyond the boundaries of the di ...

I am looking to expand my CSS/HTML menu with an additional sub-sub menu. What is the correct way to achieve this?

This is my current CSS code that I am working on. I am trying to create a multi-level menu in Blogger with submenus, sub-submenus, and sub-sub-submenus without disrupting the existing formatting. .top-nav { background-color: #f9f9f9; background: t ...

Attempting to choose everything with the exception of a singular element using the not() function in Jquery

Within the mosaic (div #mosaique) are various div elements. My goal is to make it so that when I click on a specific div, like #langages or #libraries, the other divs become opaque while the selected div undergoes a size change (which works correctly in t ...

Expanding Image with HTML and CSS: A Guide

In the process of creating my website, I encountered an issue with the logo placement. I wanted the logo to be in the top left corner, similar to the one shown in this image. Initially, everything was working fine until I made some adjustments to move the ...

Table Header Stays Put Without Shrinking or Expanding with Window Adjustment

I have a sticky table header that stays at the top when scrolling down on my web page. To achieve this effect, I followed the solution provided on css-tricks.com/persistent-headers/. However, I encountered an issue where the sticky table header does not ...

The toLowerCase method seems to be malfunctioning along with several other functions

JS var score = 0 var yes = "yes" var pokemonName = []; var bg = []; var index = 0; document.getElementById('repete').style.visibility = 'hidden'; (function asyncLoop() { background = bg[num = Math.floor(Math.random() ...

Move a div by dragging and dropping it without creating duplicates

I'm in need of some assistance. It seems like a simple task, but I'm having trouble finding a solution. I've managed to create draggable elements that work smoothly without any issues. The drag and drop functionality is working perfectly. ...

Troubleshooting Symfony2 and Assetic: Why are my CSS-linked images not loading?

I've encountered an issue with my CSS sprite sheet that my CSS file seems unable to locate the image. Despite following the provided solution here, I'm still facing the same problem. The directory structure of my bundle is as follows: src/ v ...

Guide on how to navigate through sub-sections within a larger section

I am in the process of developing a rails app where I would like to include a side div for displaying news updates in a vertical feed style. I have made some progress with the layout, but now I am facing issues with finding a suitable news-ticker plugin th ...

Is it possible to make side elements expand to occupy the remaining screen space beyond the container?

This is what it's supposed to look like: The goal here is to have the red element on the left expand to fill the remaining space beside its content, as well as the grey on the right. I am utilizing bootstrap which means the center elements occupy 117 ...

Guide to attaching a mouse click event listener to a child element within a Polymer custom component

I'm currently facing an issue where I am attempting to attach a click listener to one of the buttons within a custom element during the "created" life cycle callback (even attempted using the "ready" callback with the same outcome). Unfortunately, I ...

Angular JS does not display the bold tag for specific words

I'm currently working on an Angular JS application and receiving text from the server that needs to be displayed on my website. The text received from the server is: "My name is <b> John </b>" with b tags. Unfortunately, when I display ...

Troubleshooting AJAX hover functionality issue

Here is the content that loads through AJAX: <div class="grid"> <div class="thumb"> <img alt="AlbumIcon" src="some-image.jpg"> <div style="bottom:-75px;" class="meta"> <p class="title">Title< ...

Tips on determining if a string is a properly formatted HTML:

My question is about checking whether selected strings in a web form are valid HTML syntax. How can I achieve this on a button click? function chkhtml() { var code = $("<table><td>"); code.each(function () { if( ...

Using PHP to display arrays on the screen

Currently, I am working on manipulating an array in my code. I have already accessed the array and begun the process of displaying its contents using the following code snippet: <html> <?php $file=fopen("curr_enroll_fall.csv", "r"); $records[]=fg ...

What's the best way in Angular 6 to set focus on an element that's being made content editable?

I am currently utilizing the contentEditable attribute in Angular 6 to allow for editing the content of elements within an ngFor loop. Is there a way to focus on a tag element when its contentEditable attribute is set to true? <div class="tag" *ngFor= ...

Designing a nested box layout with bootstrap HTML/CSS styling

Can anyone provide guidance on how to create a HTML/CSS layout similar to the image below? I am specifically struggling with designing the silver "Add corkscrew" box, a white box beneath it, and then another silver box nested within. Any suggestions on ho ...

Issues with unresponsive links (HTML5/CSS)

As a beginner, I've encountered an issue where my previously working links are no longer functioning. Can anyone help identify what could be going wrong? Below is the HTML code: <!doctype html> <html> <head> <meta charset="UTF-8 ...