Creating styles with CSS to position text below an image

123.456.789.000/index.php

<html>
<head>
    <title>Unique Triathlon Club</title>
    <meta  charset=iso-8859-1" />
    <link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<ul id="nav">
    <li><a href="http://unique-triathlon.com">Home</a></li>
    <li><a href="/forum">Forum</a></li>
    <li><a href="/join">Join</a></li>
    <li><a href="/members">Members</a></li>
    <li><a href="/events">Events</a></li>
    <li><a href="/training">Training</a></li>
    <li><a href="https://www.facebook.com/groups/unique-triathlon/">Facebook</a></li>
    <ab><a href="/about">Unique Triathlon Club</a></ab>
</ul>
<ul id=main>
<p>Main Section</p>
</ul>
</body>
</html>

123.456.789.000/style.css

body {
    background:#000 url(bg.jpg) center top no-repeat;
    background-size: cover;
    color: #c1c1c1;
    font-family: Arial, Verdana, Helvetica, sans-serif;
    margin:0;
}

#nav {
width: 100%;
float: left;
margin: 0 0 3em 0;
padding: 0;
list-style: none;
background-color: #f2f2f2;
border-bottom: 1px solid #ccc; 
border-top: 1px solid #ccc;
}

#main{
    display:inline-block;
    float:left;
}

How can I adjust the layout to have content in the main section appear below the background image while keeping the navigation bar at the top? Visit http://123.456.789.000 for the current code.

Answer №1

  1. Consider changing the "main" container to a div instead of a ul. You can always nest a ul inside the main div if necessary.

  2. Include a margin-top property in your #main css to create space between the main content and the navigation bar.

In index.php:

<div id="main">
<p>Main</p>
</div>

In style.css:

#main {
    margin-top: 240px; /* Adjust this value as needed */
}

You may remove the display: inline-block from your main css, and potentially eliminate the float:left based on your design goals.

It might be necessary to remove the background-size: cover from your body's css to prevent the background image from extending into your main div.

Answer №2

It appears that you may be looking to achieve a specific design outcome, but without seeing the full context it's hard to say for certain. One suggestion could be to adjust the padding-top of your body element to match the height of your background image.

For example: body { padding-top: 50px; } //assuming your bg.jpg is 50px in height

Additionally, consider whether the float property applied to your #main element is necessary for your layout.

Answer №3

give this a shot

body {
background-color: #000000;
    background-image: url("bg.jpg");
background-position: center top;
    background-repeat: no-repeat;
color: #C1C1C1;
    font-family: Arial,Verdana,Helvetica,sans-serif;
    margin: 0;
}

#main {
    margin-top: 370px;
}

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

Listening to a sequence of mp3 tracks consecutively

I'm currently working on a project that involves playing a series of mp3 files consecutively. However, I've encountered an issue with my code snippet below: Here's the code snippet: function playAudio(){ var au = document.getElementById( ...

When running the Grunt build process, the styles are not combined within the build:css(.tmp) directory

When setting up my front-end with Yeoman Angular generator and using Grunt, I noticed that only the first CSS file and the Sass files generated in main.css were included in my build. Here is a snippet from my index.html: <!-- build:css(.tmp) styles/mai ...

Card image floating to the right using Bootstrap

I have a set of three horizontal cards, not in a card deck as it's not responsive, and I want to align images in the bottom right corner of each. Bootstrap 4 comes with a class for card-img-left which works perfectly. I've attempted using float-r ...

Troubleshooting: Django update causing issues with CSS background image display

Recently, I made an upgrade to my Django 1.10 (Python 3.5) app to Django 1.11 (Python 3.6). Most of the functionalities are still intact, however, I am facing a peculiar issue where my CSS background images are no longer rendering (even though they work fi ...

Having trouble with loading a 3D gltf model on A-frame.io?

I'm experiencing some difficulties when attempting to load a gltf model onto an a-frame. Unfortunately, the model does not appear to be loading properly. Here is the code snippet in question: <html> <head> <title>Tree model</t ...

I am encountering issues with integrating the dynamically obtained data into the tailwind library. Any solutions or suggestions on how to resolve this problem would be greatly

I attempted to use the initial data as a class and wrote code to cross out the label for incoming data if it exists in the class. Unfortunately, this approach did not work as expected and did not result in any errors either. import { useState } from " ...

The :host selector is not functioning properly for a custom element with shadow DOM

I am currently in the process of developing a custom component with shadow dom attached to it. The custom component is successfully created and added to the dom with shadow dom attached, but for some reason, the :host style is not being applied. HTML < ...

iOS exhibits a flashy display of Material Select lighting up

In my attempt to develop a website using Material Design, I encountered an issue with the Material Select component. Whether I utilize MDB (Material Design for Bootstrap) or the Materialize CSS framework, both function well on Windows/OSX/Android devices. ...

Specify the input type to occupy the full width and be contained within its parent div

I'm currently dealing with a form that includes input fields for email and password, along with some additional buttons. Here is the HTML code: <div id="login-form"> <form> <input type="email" placeholder="Email" id="email" name= ...

Is there a way to conceal overridden div borders? When two divs are in conflict, eliminate borders only from the overridden region

I am facing an issue with two overlapping div elements. I need to remove the border from the area where they overlap only. Take a look at the code snippet below: <div style="width:100px; height:20px; background-color:#5475b1;border: 2px solid;" ...

The script ceases to function once the page is loaded from a JSON file

I'm facing an issue on my shopping website where the items and products are loaded from a JSON file. The problem is that once the page has loaded, the script fails to work properly. If the items take a little longer to load on the page, the script doe ...

Newbie struggling with div and css issues

After making changes to my code based on the suggestions below, the layout of the images and text appears to be all over the place. Some elements are behind the div background while others are in front. Additionally, some text is positioned to the left whi ...

No input value provided

I can't figure out what's going wrong. In other js files, this code works fine. Here is my HTML code: <table class='table'> <tr> <th>Event</th><td><input class='for ...

JQuery Mobile fails to apply consistent styling to user input check items within a list

I have successfully implemented the functionality to add user input items to a checklist. However, I am facing an issue where the newly added items are not adhering to Jquery Mobile's styling. Here is a screenshot showcasing the problem: Below is th ...

Tips for maintaining a fixed div within another div using absolute positioning

When the mouse hovers over an element, a hidden div with absolute positioning is displayed. At the bottom of this div, there should be another fixed div. Take a look at the image to see what I am trying to achieve. This is the CSS code I have written for ...

Retrieve information from an HTML form

Currently, I have a piece of Javascript that fetches the HTML for a form from the server using an XMLHttpRequest and then displays the form on the page. I am looking for a solution to extract the data that would be sent via POST if the form were submitted ...

Easily input new information into your MySQL database with just a click by utilizing a link through PHP and HTML

Is there a method to modify information in a MySQL database when a user clicks on a hyperlink? I'm developing a voting application. It enables users to save questions for immediate use or later use. When the user is viewing their created questions, t ...

ASP repeater exceeding container boundaries

Having trouble with my asp repeater that reads from a database and generates repeatable divs. The issue arises when the h4 spills over the div, particularly when using <%Eval. Any suggestions on how to fix this? Manual input divs don’t seem affected o ...

Moving the search bar on a WordPress mobile theme: A step-by-step guide

As a novice in web design, I've taken on the task of self-hosting a Wordpress site at noisehole.com using the MH Magazine template. One modification I made was to include a search bar above the header by creating a child theme and customizing it. How ...

Space empty on the right side of a card within a container - Bootstrap 4

I've been working on creating a responsive card for different screen sizes, but I've encountered a problem. On mobile screens, there seems to be some unwanted blank space on the right side of the card. Is there a way to center this card on smalle ...