Why does the div class play nice with CSS while the span class is causing issues?

Can anyone explain why the CSS is not implemented when using a span class for marking up a letter, but it works fine with a div class? I thought both should work, considering one is a block-level element and the other is inline. Here's the line that was changed:

<div class="receiver-column"> 20 January 2016 </div>

changed to

<span class="receiver-column">20 January 2016 </span>

This is the HTML code snippet provided:

body {
  max-width: 800px;
  margin: 0 auto;
}

.receiver-column {
  text-align: right;
}

h1 {
  font-size: 1.5em;
}

h2 {
  font-size: 1.3em;
}

p,
ul,
ol,
dl,
address {
  font-size: 1.1em;
}

p,
li,
dd,
dt,
address {
  line-height: 1.5;
}
<p class="receiver-column"><strong>Dr. Eleanor Gaye </strong> Awesome Science faculty <br> University of Awesome <br> Bobtown, CA 99999, <br> USA <br>
  <strong>Tel</strong>: 123-456-7890 <br>
  <strong>Email</strong>: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e48a8bbb968194889da4819c8589948881ca873feb">[email protected]</a> </p>

<div class="receiver-column"> 20 January 2016 </div>

Answer №1

When it comes to the span element, it is important to remember that it is inline and will only be as wide as its content, which is usually the text inside of it. So, if you decide to apply text-align: right to a span element, the alignment will only affect the width of the span itself, meaning it won't have much of an impact.

For proper text alignment, it's best to use block elements like div, p, h1, h2, h3, or similar options.

Answer №2

The default display property for Span is inline, whereas Div's is block.

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

How to build a login page with a static header and footer using Angular2

For my latest project, I am currently in the process of developing an application using Angular2 and eclipse Neon. Utilizing angular-cli for this app, I am now focused on creating the login page. Within the app.component.html file, you will find the follow ...

Design: Seeking a layout feature where one cell in a row can be larger than the other cells

To better illustrate my goal, refer to this image: Desired Output <\b> Currently, I'm achieving this: current output Imagine 7 rows of data with two columns each. The issue arises in row 1, column 2 where the control needs to span 5 row ...

The input placeholder text in Safari 5.1.7 is unable to be centered

Check out my code snippet below: HTML: <input type="text" name="Surname" placeholder="Surname" id="surname"> CSS: ::i-block-chroms, input[placeholder]::-webkit-input-placeholder { text-align:center; } ::-webkit-input-placeholder { t ...

html: div broken

The HTML document reads as follows: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"& ...

Painting with color blends

I need help designing a color selector in the shape of a triangle. I've come across resources like the color wheel (), but I'm unsure how to alter it to resemble a triangle instead of a square. ...

The background color of the body is being utilized by Div in Internet Explorer version 7

Within my HTML document, I have created a container div that holds several nested divs for a slideshow effect. This "container" div is positioned over the background image of the body element. The CSS styling for the body element is as follows: body { ba ...

Combine a variable and a string to create a new variable

@color-purple: "#ffffff" @colors: purple, light-purple, green, light-green, red, light-red, grey, light-grey, lightest-grey; .ColorsMixin(@i:0) when(@i =< length(@colors)){ //loop over icons array @color: extract(@colors, @i); //extract the ic ...

What is preventing me from being able to import a React component from a file?

I've double-checked my code and everything seems correct, but when I view it on the port, only the app.js file is displayed. import React from 'react'; import ImgSlider from './ImgSlider'; import './App.css'; function ...

Tips on building an immersive interactive panoramic website

I have a vision for a website that will simulate being in a room, where users can explore the space with limited panoramic views - allowing them to look up/down 30 degrees and left/right 45 degrees. In addition, I would like to integrate interactive object ...

Boxes not occupying entire vertical space

My structure is unique, like a 9-box with div elements: <div class="NBWrapper"> <div class="NBTopRow"> <div class="NBLeft" /> <div class="NBRight" /> <div class="NBMiddle" /> </div> & ...

Obtain user input and showcase it on the screen using a combination of Ajax and PHP

Whenever a user inputs a value in the textbox, it should dynamically display on the screen. I have successfully implemented this feature once, but I am encountering difficulties with implementing it for a second input. Your help is greatly appreciated. fu ...

Utilize Bootstrap button dropdown to automatically assign a selected value to a list item

I have a form with a select box that transforms into a bootstrap button after the page loads. However, I am unable to set the selected value for the converted bootstrap button drop-down li. <button type="button" class="btn dropdown-toggle btn-default" ...

`We are experiencing alignment issues with the Bootstrap drop-down menu`

I'm struggling to understand why my menu isn't aligning properly on the sub dropdowns. They are appearing at the lower edge of their parent cell, making navigation quite difficult. You have to drop down diagonally just right to access the next me ...

Dynamically adjusting CSS Max-Height according to scroll position

Is there a CSS only technique to achieve the following scenario: An element is positioned absolutely at x,y coordinates on the screen. The document includes a vertical scrollbar depending on its content. Can the height of the element be adjusted based on ...

``Sorry, the link redirection feature is currently experiencing technical

First and foremost, take a look at this example View here Based on the example provided, I would like to create a similar page using the Telrik Text Editor, with a list of links and their corresponding paragraphs. Here is the HTML I am using in the Telr ...

Combining CSS and HTML with IE10

With the release of Windows8 and IE10 as developer previews, I am curious about what features IE10 does not support that IE9/8 did, as well as what new features it now supports. Thank you for your assistance! ...

Filter out the selection choice that begins with 'aa' in the drop-down menu

Here is a select field with various options: <select id="sel"> <option value="1">aadkdo</option> <option value="2">sdsdf</option> <option value="3">aasdfsddkdo</option> <option value="4"> ...

How can we convert unpredictable-length JSON user input into well-structured HTML code?

Welcome to the world of web development! I am currently embarking on a project where I aim to transform JSON data into HTML structures. Specifically, I am working on creating a dynamic menu for a restaurant that can be easily updated using a JSON file. The ...

Adjust the size of iCheck jQuery radio buttons

I have implemented the iCheck Plugin for radio buttons in Angular Directive, but I am facing an issue with resizing the radio button to a smaller size. Does anyone have any suggestions or solutions for this? ...

What is the best way to position items of varying heights in alignment?

Can someone help me with this issue? I have a grid with 12 columns, each containing 2 identical icons and 2 texts of different heights. I need to align the icons in the center and make sure the texts are at the same height, but I'm having trouble achi ...