Difficulty with Line Breaks in Spans

I've noticed that my multi-line address in the footer is not breaking correctly at certain screen widths.

Each line of the address is enclosed within a <span> tag with a specific class and then styled either as block or inline-block in the CSS file.

However, I have encountered an issue where a couple of lines are not displaying as intended, and I'm struggling to determine the cause of this problem.

Irrespective of the styling applied to a particular line, it always appears on a separate line instead of aligning with adjacent lines. Additionally, at 768px, two lines break as expected, but there is an unwanted gap between them.

HTML

<span class="address">FEAST THAILAND</span> 
<span class="address1">10 NAEBKHEHART ROAD HUA HIN</span>
<span class=“address2”>(Inside The Memory Hua Hin) </span>
<span class="address3">PRACHUAP KHIRI KHAN, 77110 THAILAND</span>
<span class=“address4”>+66 (0) 32 510 207</span>
<span class="address5">OPERATED BY FOOD DISCOVERY (THAILAND) CO., LTD.</span>
<span class="address6"><a href="http://feastthailand.com/privacy-policy/"><strong>PRIVACY POLICY</strong></a>&#160;&#160;&#160;&#160;<a href="http://feastthailand.com/terms-conditions/"><strong>TERMS & CONDITIONS</strong></a></span>&#160;&#160;&#160;&#160;<span class="address7"><a href="http://feastthailand.com/waiver-release-liability/"><strong>WAIVER & RELEASE OF LIABILITY</strong></a></span>
<span class="address8"><strong>©2017</strong> ALL RIGHTS RESERVED</span>
<span class="address9">TAT License No. 14/02344</span>

CSS

.address,
.address1,
.address2,
.address4,
.address6,
.address7 {
    font-size: 11px;
    font-weight: normal;
    font-family: Lato, sans-serif;
    letter-spacing: 1.5px;
    text-align: center;
    display: inline-block;
    color: #000000;
}
.address3,
.address5,
.address8,
.address9 {
    font-size: 11px;
    font-weight: normal;
    font-family: Lato, sans-serif;
    letter-spacing: 1.5px;
    text-align: center;
    display: block;
    color: #000000;
}

The standard CSS code provided lacks media queries, but I am facing issues with the formatting of .address4, which should be alongside .address3 but isn't. Any suggestions on why?

Also, when viewed at 768px, .address7 moves below .address6 as required, however, there is a strange gap between these two lines. Can anyone shed light on this issue?

I have experimented with various methods including adding classes to
tags and adjusting the styling based on screen width using media queries like shown below:

CSS

@media only screen and (max-width: 414px){
  .address2 {
   font-size: 10px;
    font-family: Lato, sans-serif;
    letter-spacing: 1.5px;
    text-align: center;
    color: #000000;
    display: block;
}
.address2:after {
    content:"\a";
    white-space: pre;
}
}

Although I used .address2:after to move the line following .address2 to a new line at 414px, it didn't produce the desired result. Any recommendations for a better approach to handle line breaks as needed?

Cheers!

Answer №1

One drawback of using display:block is that the elements always appear on their own line, regardless of the surrounding elements being displayed as display:inline or not.
To address your concerns: an inline-block span positioned next to a block span will not be aligned on the same line. Additionally, two block spans separated by &#160;&#160; will each be on their own line, with a blank line in between where the &#160;&#160; are located.

To simplify the situation, I would recommend streamlining it as follows:

div.addressblock {
  text-align: center;
}

div.addressblock span {
  font: normal 11px 'Lato', sans-serif;
  letter-spacing: 1.5px;
  display: inline-block;
  color: #000000;
}

div.addressblock a {
  font-weight:bold;
  padding:0 .5em}
<div class="addressblock">
  <span>FEAST THAILAND</span>
  <span>10 NAEBKHEHART ROAD HUA HIN</span>
  <span>(Inside The Memory Hua Hin) </span>
  <span>PRACHUAP KHIRI KHAN, 77110 THAILAND</span><br>
  <span>+66 (0) 32 510 207</span>
  <span>OPERATED BY FOOD DISCOVERY (THAILAND) CO., LTD.</span><br>
  <span><a href="http://feastthailand.com/privacy-policy/">PRIVACY POLICY</a>
        <a href="http://feastthailand.com/terms-conditions/">TERMS &amp; CONDITIONS</a>
        <a href="http://feastthailand.com/waiver-release-liability/">WAIVER &amp; RELEASE OF LIABILITY</a></span>
  <span><b>©2017</b> ALL RIGHTS RESERVED</span><br>
  <span>TAT License No. 14/02344</span>
</div>

This approach includes intentional line breaks and converts all spans into inline-blocks to prevent unexpected breaks within them, allowing for smooth page flow.

If specific styling adjustments are needed at different screen sizes, additional CSS can easily be incorporated.

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

Styling Angular Datatables with CSS

i have data on the front end https://i.stack.imgur.com/2xq7a.jpg i need all check marks to be displayed in green color. Below is the code snippet: $scope.dtColumnsCal= [ DTColumnBuilder.newColumn('name').withTitle('Name') ...

Establish a new <section> to serve as a distinct webpage

I have a question about creating multiple <section> elements on a page. I am looking to build an HTML document with several <section> tags, as outlined below. <html> <head> </head> <body> <sectio ...

Arrange floating elements in a three-column layout

Can anyone help me with a CSS solution to make boxes with different heights stack underneath each other neatly, similar to Tetris? Here's my code: CSS #page .equipeBox{ float:left; width:280px; padding:10px; margin:10px; backgro ...

What is the best way to transfer an element and all its children to another div without losing any jQuery functionality?

At first, sharing an example of the JavaScript and HTML from my page is challenging because I couldn't make it work on JSfiddle. The issue I'm facing involves jQuery on a page where I've created two tabs. Essentially, it's the same con ...

Leverage htaccess functionality to modify website configurations without altering the URL

I currently have the following htaccess configuration: <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ dl.php?id=/$1 [QSA,L] </IfModule> It works perfectly fine. However, I am facing a problem with my site URLs and images ...

What are the steps to create a customized app bar with React and Material-UI similar to this design?

Can anyone help me create an app bar that resembles this design: Click here to view I have managed to implement the search box in the top half of the app bar, but I am struggling with adding the bottom half. Here is the code I have written so far: ...

Python code encountered an issue while trying to find the element with the locator //input[@name="session[username_or_email]". The element could not

I have recently started learning about selenium and web scraping in general, and today I attempted to follow a tutorial on selenium that included the following command: from selenium import webdriver driver = webdriver.Firefox() driver.get("https://t ...

JS Emphasis on Scrolling Div

I'm facing an issue with a button that opens a scrollable div. When I try to use the arrow keys on the keyboard, they do not scroll the div as expected. Interestingly, if I click anywhere on the div, then I am able to scroll using the arrow keys. I ...

Is there a disparity in how the mandatory field validator functions in Edge compared to Chrome?

There doesn't seem to be any red color How can I ensure consistency? Both elements should either have color or none at all. <form action=""> <input id="email" type="email" required="required" /> <input type="submit" id="btnS ...

Is there a way to show a 'Refresh' icon in HTML without the need to download an image through HTTP?

In my HTML/JavaScript app project, I am looking to incorporate a 'refresh' symbol without having to load an image through HTTP requests. Are there reliable methods that can achieve this across all major browsers? I came across the Unicode value: ...

The IE condition is failing to work properly with .js and .css files

I've been trying to use this code to load the ie.css file specifically for IE browsers, but for some reason it's not working. I'm feeling a bit confused here - can anyone help me figure this out? <html> <head> <titl ...

Is it acceptable to replicate another individual's WordPress theme and website design in order to create my own WordPress website that looks identical to theirs?

It may sound shady, but a friend of mine boasts about the security of his WordPress website, claiming it's impossible to copy someone else's layout or theme. However, my limited experience in web development tells me otherwise. I believe it is po ...

Discover the process of extracting HTML content that's stored within a JavaScript variable

Having a HTML snippet stored in a variable, like this: var parse= 'Hello<i class="emoji emoji_smile" title=":smile:"></i><i class="emoji emoji_angry" title=":angry:"></i>World' I am looking to extract the value of the "t ...

The last value label in Google Charts bar chart getting cut off

I've searched extensively for a solution to this issue regarding the haxis labels, but I have not been able to find one that addresses it... In the image provided below, you'll observe that the last percentage label on the horizontal axis is mis ...

Tips for designing a HTML form using classes

I need help styling this form using CSS because I have similar areas like a search submit button that require different classes. Any assistance would be greatly appreciated. <perch:form id="contact" method="post" app="perch_forms"> <perch:cont ...

Retrieve all data points if both latitude and longitude are present in the XML dataset

XML data to retrieve details <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <results> <result> <Country_Code>IN</Country_Code> <Country_Name>India</Country_Name> <Region_Nam ...

Animating CSS when closing a modal box

I followed the instructions from a tutorial on W3Schools here to create this code. The "open model" button triggers the modal to open with a smooth CSS animation, which looks great. However, when I click the close button, the modal abruptly closes without ...

Receiving inaccurate video duration when the input bar is modified

Initially, I am uncertain whether the issue stems from Javascript or CSS. The code in question involves displaying the corresponding video time when a user hovers over an input bar. The calculation utilized is as follows: ((user mouseX position / input wi ...

I'm only seeing output on two of my input boxes - what's going on?

Currently in the process of learning JQUERY/HTML, I decided to create a shopping cart. My goal is to display the subtotal, tax, shipping costs, and total cost in input boxes. While I successfully displayed the sub total and shipping cost, I encountered an ...

Conceal a Component within an Embedded Frame

Hey there! I've been attempting to hide a header within an iframe, but it seems like my code isn't doing the trick. Could someone take a look and help me diagnose why the header is still visible? Thanks in advance! <iframe id="booking_iframe" ...