Alignment troubles persist with text formatting

The alignment of the link at the bottom of the page seems to be causing an issue.

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="cssforwebsite.css"/>
    <link href="https://fonts.googleapis.com/css?family=Covered+By+Your+Grace|Raleway:100,500,600,800" rel="stylesheet">
</head>
<body>
<div id="top">
    <h1>TRAVEL GUIDE</h1>
</div>
<div id="body">
    <p>Exploring various tourist attractions around the world is the focus of this webpage. From tropical paradises to icy terrains, it covers a wide range of destinations.</p>
    <h2>France</h2>
    <p>France, located in Western Europe, offers a mix of historic cities, picturesque villages, and beautiful coastlines. Paris, its capital, is famous for fashion, art museums like the Louvre, and landmarks such as the Eiffel Tower. The country is also known for its wines and gourmet cuisine. Ancient cave paintings in Lascaux, Roman theaters in Lyon, and the grand Palace of Versailles reflect France's rich cultural heritage.<p>
    <ul>
        <li>The Eifel Tower</li>
        <img src="https://cache-graphicslib.viator.com/graphicslib/thumbs674x446/9205/SITours/skip-the-line-eiffel-tower-tour-and-summit-access-in-paris-296015.jpg" width="200px" height="160px"/>
    </ul>
    <a href="https://www.google.co.uk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwjirL3Jy_7RAhUEBcAKHVs9C6AQFggaMAA&url=http%3A%2F%2Fwww.worldtravelguide.net%2F&usg=AFQjCNGnX8FXlQKh9hEebd1Syt2Wh33q_Q&sig2=B-usIraK2zeErXSMJVlRmw&bvm=bv.146094739,bs.1,d.d2s" id="help" style="text-align:center;" target="_blank">Discover more travel options on this website!</a>
</div>
</body>
</html>

Below is the CSS code used for styling the webpage:

body{
    background-image: url("https://i.sstatic.net/jGlzr.png");

}
#top{
    width:74%;
    margin: 0 auto;
    background-image:url("http://www.thetreesandthestars.co.uk/wp-content/uploads/2014/10/Up-the-beach.jpg");
    height:400px;
    background-position: center center;
}
*{
    font-family: "Raleway";
    color: #444444;
    font-size: 18px;

}
h1{
    color: black;
    text-align: center;
    position:relative;
    line-height: 450px;
}
#body{
    background:white;
    width: 1000px;
    width: 74%;
    margin: 0 auto; 
}
p,h2{
    text-align: center;
}
#help{
    text-align:center;

}

/*This makes the link black if the mouse is not hovering over it and the user hasn't visited the link before*/
a:link {
    color: black;
}

/*This makes the link cyan if the user has visited this website before*/
a:visited {
    color: cyan;
}

/*this makes the link blue when the mouse is hovering over it*/
a:hover {
    color: blue;
}

/*the link appears red when someone is holding their mouse down and hovering on top of it*/
a:active {
    color: red;
}

I am facing an issue with the image alignment. It always aligns on the left side when added. Can anyone provide assistance with this problem?

Answer №1

One reason for this is that the a element defaults to being an inline element, so it only takes up as much space as necessary on the page. To center it, you can either change it to a block element using display: block;, or place it within a parent block element and apply text-align to the parent.

<a style="text-align:center;display:block;" href="#">centered</a>
<p style="text-align:center;"><a href="#">centered</a></p>

body {
  background-image: url("https://i.sstatic.net/jGlzr.png");
}

#top {
  width: 74%;
  margin: 0 auto;
  background-image: url("http://www.thetreesandthestars.co.uk/wp-content/uploads/2014/10/Up-the-beach.jpg");
  height: 400px;
  background-position: center center;
}

* {
  font-family: "Raleway";
  color: #444444;
  font-size: 18px;
}

h1 {
  color: black;
  text-align: center;
  position: relative;
  line-height: 450px;
}

#body {
  background: white;
  width: 1000px;
  width: 74%;
  margin: 0 auto;
}

p,
h2 {
  text-align: center;
}

#help {
  text-align: center;
}


/*This makes the link black if the mouse is not hovering over it and the user hasn't visited the link before*/

a:link {
  color: black;
}


/*This makes the link cyan if the user has visited this website before*/

a:visited {
  color: cyan;
}


/*this makes the link blue when the mouse is hovering over it*/

a:hover {
  color: blue;
}


/*the link appears red when someone is holding their mouse down and hovering on top of it*/

a:active {
  color: red;
}
<!DOCTYPE html>
<html>

<head>
  <link rel="stylesheet" type="text/css" href="cssforwebsite.css" />
  <link href="https://fonts.googleapis.com/css?family=Covered+By+Your+Grace|Raleway:100,500,600,800" rel="stylesheet">
</head>

<body>
  <div id="top">
    <h1>TRAVEL GUIDE</h1>
  </div>
  <div id="body">
    <p>In this webpage I will write about many different tourist attractions. These will include countries from continents all around the world. From countries with a warm, tropical climate, to countries with sub-zero temperatures, this page contains it
      all.</p>
    <h2>France</h2>
    <p>France, in Western Europe, encompasses medieval cities, alpine villages and Mediterranean beaches. Paris, its capital, is famed for its fashion houses, classical art museums including the Louvre and monuments like the Eiffel Tower. The country is
      also renowned for its wines and sophisticated cuisine. Lascaux’s ancient cave drawings, Lyon’s Roman theater and the vast Palace of Versailles attest to its rich history.
      <p>
        <ul>
          <li>The Eifel Tower</li>
          <img src="https://cache-graphicslib.viator.com/graphicslib/thumbs674x446/9205/SITours/skip-the-line-eiffel-tower-tour-and-summit-access-in-paris-296015.jpg" width="200px" height="160px" />
        </ul>
        <a href="https://www.google.co.uk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwjirL3Jy_7RAhUEBcAKHVs9C6AQFggaMAA&url=http%3A%2F%2Fwww.worldtravelguide.net%2F&usg=AFQjCNGnX8FXlQKh9hEebd1Syt2Wh33q_Q&sig2=B-usIraK2zeErXSMJVlRmw&bvm=bv.146094739,bs.1,d.d2s"
          id="help" style="text-align:center; display: block;" target="_blank">Travel website for more help finding a holiday</a>
  </div>
</body>

</html>

Answer №2

Experiment with this approach, placing your anchor element within a paragraph container

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

`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 ...

Postpone the inclusion of html files within ng-include in AngularJS

I need to optimize the startup performance of my app by delaying the loading of a series of HTML files that are being included into my main controller. These files are not needed for at least 4 seconds while one specific HTML file processes. How can I de ...

prismjs plugin for highlighting code displays code in a horizontal format

If you're looking for a way to showcase source code on your website with highlighted syntax, prismjs.com may be just what you need. It offers a similar style to monokai... However, I've encountered an issue where the plugin displays my code in a ...

Styling Overlapping Divs with CSS3

I am attempting to replicate this particular effect using HTML within the UIWebView control on iOS. The desired outcome is to simulate a progress bar on the listing. My current approach involved utilizing this method, however, as you can observe, adding pa ...

Show that a CPU-intensive JavaScript function is executing (animated GIF spinners do not spin)

Displaying animated indicator or spinner gifs, then hiding them, is an effective way to communicate to the user that their action is being processed. This helps to assure the user that something is happening while they wait for the action to complete, espe ...

Exploring Font-Awesome 5: Using CSS Pseudo-elements to Mirror or Rotate Icons

I am utilizing CSS pseudo elements to display icons (jsfiddle) body { font-family: Arial; font-size: 13px; } a { text-decoration: none; color: #515151; } a:before { font-family: "Font Awesome 5 Free"; content: "\f07a"; di ...

How can we prevent floating li elements from overlapping the parent div element?

What could be causing the yellow stripe (#header) to disappear when I apply "float left;" to "#header ul li"? Despite setting a fixed size for "#header ul li", I anticipated that the list items would line up next to each other horizontally, not exceeding t ...

Visualizing Data with HTML and CSS Chart Designs

I'm seeking assistance with creating an organization tree in a specific layout. I am having trouble replicating the tree structure shown in the image. I need help generating a similar tree structure where multiple levels are displayed, including ext ...

The Simple HTML Dom parser is failing to parse contents on these specific websites

I tried using a basic HTML DOM parser but it's encountering issues when parsing certain websites. include_once 'simple_html_dom.php'; $html=file_get_html('http://www.lapenderiedechloe.com/'); This results in an error message like ...

Dimming the background of my page as the Loader makes its grand entrance

Currently, I am in the process of developing a filtering system for my content. The setup involves displaying a loader in the center of the screen whenever a filter option is clicked, followed by sorting and displaying the results using JQuery. I have a v ...

Creating a div that is subtly askew

When it comes to positioning a div 15 pixels off-center horizontally from the page, traditional methods like setting margins to auto or using position:absolute may not work in this situation. The challenge lies in ensuring that the div scales correctly a ...

Modify the color of a div element in React when it is clicked on

My goal is to change the color of each div individually when clicked. However, I am facing an issue where all divs change color at once when only one is clicked. I need help in modifying my code to achieve the desired behavior. Below is the current implem ...

What is the best way to configure a row layout in a Vuetify dialog component?

Encountering a layout issue. Here is the problem: https://codepen.io/positivethinking639/pen/YzzwYZq. When the dialog pops up, it appears strange because the width of the row(<v-row justify="center">) is larger than the width of the dialog, resulti ...

menu fails to expand when clicked in mobile view

Could someone please help me troubleshoot why the menu icon is not expanding in mobile view? I'm not sure what I did wrong. Here is the link for reference: Snippet of HTML: <nav class="navbar navbar-default navbar-fixed-top" role="navigation"> ...

The "pointer" cursor style is simply not functioning in any way

Here is the angular template code I am working with: <!-- Modal --> <ng-template #levelsmodal let-c="close" let-d="dismiss"> <div class="modal-header"> Select the levels you want to show in the table and chart ...

Updating style in Javascript can sometimes be a bit tricky

What's preventing this from working? localStorage.fontSize contains the correct value, but the initial document.body.style.fontSize = localStorage.fontSize + "pt"; doesn't update the style. <script type="text/javascript> if(!localStorage. ...

What is the process for creating a Sass mixin that declares a selector at the base level, rather than nested within another

Apologies for the unconventional terminology in the query, but I am struggling to find better words to describe it. Hopefully, this example will clarify my intention: scss-syntax .my-smug-selector { @include my-smug-mixin(30px); } desired css-output ...

Collaborative Vue component: Clients need to manually import the CSS

I recently created a Vue component using TypeScript that resulted in a separate CSS file being generated after the build process. However, I noticed that when the client imports this component, the CSS file is not imported automatically and needs to be exp ...

Make a portion of the title come alive on hover

Looking to add animation to a title that consists of two parts: "HARD" and "WARE", with the second part having a more transparent color. When hovering over the "HARD" word, the colors reverse correctly. However, when hovering over the "WARE" word, only on ...

What is the best way to remove table row data fetched from an API within a table?

Can someone assist me with deleting the table tr from the user table, where data is retrieved from an API? I have attempted the code below: $("principleTable").find("tr").hide(); $("#delAgentModal").modal("hide"); ...