Full-screen background with image adhering perfectly - left-aligned button that stays in place

Excuse me if my question seems basic, as I am just starting out in front-end development and may not know all the necessary terms to fully understand existing questions.

I currently have a simple html file that consists of a title and three buttons, with the CSS containing only an image.

HTML File:

<!DOCTYPE html>
<html lang="en">
<head>
    <link href="css/style.css" rel="stylesheet" media="all"> 
</head>
<body>

<div id="banner">

<h1> A random title </h1>

<div id="navi" class="navi">
        <a class="navi-button" href="#Home">Rules</a> &nbsp;
        <a class="navi-button" href="quizz1.html">Quizz</a> &nbsp;
        <a class="navi-button" href="#Contact"> Contact</a> &nbsp;
</div>

</div>

</body>
</html>

CSS:

html {
    background: url(../pics/somePicture.jpg) no-repeat center center fixed;
    background-size: cover;
}

The Issue:

As I resize, minimize, or maximize my browser window, the title and buttons remain fixed at the left border while the image resizes. However, I want the buttons to stay on the left when the browser window is full screen. Additionally, I want the image to be displayed in full screen, with only the part visible within the browser window after resizing.

For reference, you can see on this website, that by resizing the window, the buttons remain at the bottom and the background image does not adapt.

I am open to jQuery solutions if necessary.

Thank you for your assistance,

Answer №1

If you prefer the image to remain fixed when resizing, simply use the following CSS:

background-image: url("../pics/somePicture.jpg");

The image will maintain its original size and will not adjust to fit the window.

For links, follow the advice provided by #Rohit Kumar and test it out here: jsfiddle.net/qp4xfvjj , but consider adding:

<body style="overflow: hidden">

Answer №2

To prevent the <a> from breaking across lines, you can apply the CSS property white-space: nowrap;. If you need to hide the <a> when the window width is less than 1cm, you can use a @media query like this -

@media all and (max-width: 100px) { /* specify width in pixels */
    a {
        display: none;
    }
}

Take a look at this JSFiddle for reference.

To ensure that your background-image is fully displayed without cropping at all resolutions, consider using background-size: contain instead of background-size: cover

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

Prevent the mouseup event in jQuery when the mouse has previously been moved

I have a div with a row of span buttons displayed horizontally. Since there are too many buttons to fit on the screen, I want to enable the user to click and drag the entire row of buttons. However, my challenge is to ensure that the button's mouseup ...

What is the process of initializing divs in DataTables?

My application has a DataTable installed, but I encountered an error message stating "DataTables warning: Non-table node initialisation (DIV). For more details about this error, please visit http://datatables.net/tn/2". I'm aware that DataTables is d ...

Adding and adjusting the size of different DIV elements within a shared area

Looking to create a dynamic bar with the ability to add multiple child DIVs (similar to this: https://i.stack.imgur.com/tdWsq.jpg). Utilizing jQuery, jQuery UI, Bootstrap, and various plugins. The structure for the div (or span) system could be structured ...

Positioning of the footer using CSS: A query

What is the best way to position a footer if we know its height? For instance, if the height of the footer is 100px: footer { position:absolute; bottom: 100px; background: red; } If this approach is not recommended, could someone assist m ...

Unable to utilize the full column space provided by bootstrap

I need assistance in making three buttons span the entire width of a column. The grid consists of 3 sections for the buttons and 9 sections for other components. Here's a visual reference. Essentially, the buttons should take up the space highlighte ...

Filtering Jquery datatable results by text

In order to filter records from a jQuery data table, I have utilized the following code. The format for my data table is as follows: var aDataSet = [['1', 'GOld', 'G-110,G-112,G-123', 'G1-001,G1-005,G1-008'], ...

I am having trouble grasping the concept of CSS and the first-child selector

I am having an issue with the first-child selector in CSS. I have two divs with the same class, each containing an image and a paragraph element. When I use the .div-class:first-child {margin:10} rule, the margin is only applied to the paragraph in the fir ...

Display text with ellipsis on one of the two spans within a container

I'm struggling with implementing ellipsis in my HTML code. Here's what I have: <div id="wrapper"> <span id="firstText">This text should be displayed with an ellipsis</span> <span id="lastText">this text should not ...

"Upon loading the page, I encounter JavaScript errors related to Angular's ngOnInit function. However, despite these errors,

I have a page in angular where I am loading data in the ngOnInit function. The data loads correctly and is displayed on the page, everything seems to be working fine. However, I am encountering numerous javascript errors in the console stating cannot read ...

What might be causing the invisibility of a particular div element?

Here is the layout in the div element: <div class=" wrap clear"> <div class="block pink float"></div> <div class="block blue float"></div> <div class="block orange float"& ...

Updating a div's class upon clicking in React

This is my code: render() { return ( <div className='btndiv'> <button className='btn'>Hide</button> </div> ); } I'm trying to change the class of the div from .btndiv to .btndiv ...

Tips for utilizing ng class within a loop

Having some trouble with my template that loops through a JSON file using json server. The issue I'm facing is related to correctly applying ng class when clicking on icons. Currently, when I click on an icon, it adds a SCSS class but applies it to al ...

SASS: incorporating loops within CSS properties

Is there a way to generate multiple values for a single property in CSS? background-image: radial-gradient(circle, $primary 10%, transparent 10%), radial-gradient(circle, $primary 10%, transparent 10%), radial-gradient(circle, $primary 10%, tr ...

Tips for connecting 2 Bootstrap 5 carousels

I currently have 2 Bootstrap 5 carousels (carousel-a & carousel-b) on the same page and I want them to be synchronized with each other. I believe this can be achieved using JavaScript, but I am not very familiar with it. Below is the structure of carousel- ...

Is there a way to retrieve the HTML content from a jQuery object?

I have a series of buttons and corresponding dialog box messages that I would like to display when each button is clicked. Here is the HTML code: <a class="btn dialogbtn dialogbtn-save" href="#">Save</a> <a class="btn dialogbtn dialogbtn-d ...

Magento theme installation on the website encountered unexpected obstacles

Hi everyone, I'm currently in the process of constructing a website with Magento. However, I've encountered some issues after trying to install a theme. It seems like certain files, including CSS, are not loading properly. To provide better conte ...

React app (storybook) experiencing loading issues with @font-face

I am struggling to load custom fonts from a local directory. Can someone provide assistance? Below is the code I am currently using: @font-face { font-family: 'My Custom Font'; src: url('./fonts/MyCustomFont.eot'); src: url(&apo ...

I am facing an issue where the weather information is not being displayed even after sending a request to

I'm working on building an app that will provide users with weather data once they input a city. Utilizing the openweathermap.org API for this purpose, I've noticed in my console under networks that an API call is made when the city is entered, b ...

Troubleshooting a Custom Menu Control in HTML

Would you mind taking a look at the menu I have set up in this fiddle: http://jsfiddle.net/Gk_999/mtfhptwo/3 (function ($) { $.fn.menumaker = function (options) { var cssmenu = $(this), settings = $.extend({ title: "Menu", ...

When a table row is selected, set the OnClick attribute of an input to the value of the TD cell in that row based on

I'm really struggling with this. So, here's the issue - I have a table where rows get assigned a class (selected) when clicked on. Now, there's an input inside a form that needs to redirect to another page when clicked, and it also needs t ...