Does CSS positioning change depending on the screen size?

I need help fixing the positioning of my logo on the screen. I want it to be 40px from the top and centered horizontally regardless of the screen size. Here is the code that I have:

<html>
<head>

<style type="text/css>

body{
    background-image: url("images/bg.jpg");
    background-color:#844903;
}
.logo{
    position: fixed;
    top: 40px;
    right: 850px;
}
h1{
    position: fixed;
    top: 250px;
    right: 720px;
    color: #a86b00;
}  
.rf_id{
    position: fixed;
    top: 50%;
    right: 50%;
}  
 </style>

<title></title>
</head>

<body>
    <h1>Welcome, Please scan your student card:</h1>

<div class="logo"><a href="index.html"><img src="images/logo.jpg" alt="logo" </a></div>


<button class="rf_id" type="submit" style="border: 0; background: transparent"><a href="index1.5.html"><img src="images/rf_id.jpg" alt="submit"/></a></button>

</body>
</html>

Answer №1

If you want to customize your CSS based on different screen sizes, you can use a technique called 'media query'.

Media queries allow you to apply specific styles to your HTML elements depending on the size of the screen.

Here's an example:

@media (max-width: 600px) {
  .logo{
    position: fixed;
    top: 40px;
    right: 850px;
  }
}

This CSS code ensures that if the screen width is less than 600px, the class .logo will have the specified properties.

Another example:

@media all {
  .logo{
    position: fixed;
    top: 40px;
    right: 850px;
  }
}

In this case, the .logo class will have the specified properties across all screen sizes.

You can combine multiple media queries to achieve the desired styling effects for different devices.

For more information on media queries, check out these resources:
https://css-tricks.com/css-media-queries/
https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries

Answer №2

When working with positioning elements using pixels, it can be challenging due to the varying pixel densities on mobile screens (1x, 2x, 1.5x, etc.). This means that one pixel may not actually equal 1px on a screen with a density of 2x.

I suggest utilizing em units for layout purposes, or if possible, exploring newer CSS3 sizing options such as vh and vw.

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

Is there a way to remove a pseudo element in CSS using Internet Explorer

I've been struggling to make some pseudo elements work in Internet Explorer, but it seems like I can't get it to function as intended. It's as if IE is ignoring the CSS rules that I have set up for these elements, and it's quite frustr ...

Is there a conflict between bootstrap.min.JS and chart.min.js?

I have been working on developing an admin page for customer support and I recently added a visually appealing chart to display some data on the home screen. The chart integration was successful, but when I introduced tab panes to the page and refreshed ...

Tips for positioning the avatar to the right along with other links?

I've encountered various methods to align text or an image to the right, but I'm having trouble aligning a basic avatar with some text. It used to work before I switched to material-ui-next, and now I can't seem to get them aligned properly. ...

What could be causing my page to appear off-center?

Hey there! I'm still learning the ropes, but I could really use a hand with this issue: So, while I was playing around with HTML and CSS, I wanted to create a page with a fixed size that would be perfectly centered on the screen. My approach was to p ...

Using PHP to wrap text based on the language at hand

I'm facing an issue with a small area (div or span) that can only display one to five words at a time. The problem arises when certain lengthy words like "muziekgeschiedenis" exceed the boundaries of this limited space. Is there a way in PHP to wrap s ...

Overlay displayed on top of a single div element

Trying to implement a loading overlay in an Angular project within a specific div rather than covering the entire page. Here's a Fiddle illustrating my current progress: #loader-wrapper { top: 0; left: 0; width: 100%; height: 100%; ...

Creating a dynamic visual effect with image overlap in the Sencha Touch carousel

I've created a carousel that loads multiple images, but I'm experiencing an issue where each image is overlapping with another image from a different card. Here's a visual of the problem: As shown in the screenshot, parts of one image are a ...

Extracting data from DIV class tags, encountering VBA glitches

Trying to compile data into an Excel table from a website led me to discover this useful example, however, I encountered a VBA error. My current code is: Sub WebData() Dim http As New XMLHTTP60 Dim html As New HTMLdocument Dim currentRow As Long ...

What is the best way to align the navigation bar to the left using bootstrap?

I'm having trouble creating a navigation bar for my website using bootstrap 5. I tried to move the bar to the left by adding the class margin left auto (ml-auto), but it didn't work as expected. Can someone help me figure out why? Thank you in ad ...

What could be causing the unexpected white gap within my div element even though I've adjusted its dimensions to be minimal?

<div style=" height:0; width: 0 ; border: 1px solid black ; "> This code snippet displays a div element with a specified height, width, and border color. However, there seems to be an issue with the rendering as some st ...

Getting rid of the upper boundaries and outlines of the Bootstrap table

React code: <div style={{paddingLeft: '8px', paddingRight: '8px'}}> <div className="-subtitle"> <div className="pull-right" style={{marginBottom:'5px' ...

A picture placed side by side with a list

Could someone please help me figure out what I'm doing incorrectly? <div class="row"> <ul class='list-group .col-md-6'> <li>1</li><li>1</li><li>1</li> </ul> <div> ...

The specified selector is invalid or illegal in HTMLUnit

Attempting to mimic a login using htmlunit has presented me with an issue despite following examples. The console messages I have gathered are as follows: runtimeError: message=[An invalid or illegal selector was specified (selector: '*,:x' erro ...

How to toggle between displaying divs using JavaScript and Jquery

How can I use JavaScript to show or hide specific divs on page load and upon clicking different links? I want to display the "houseImages" div by default, while hiding the "landImages", "renovationImages", "UpcomingImages", and "voteForNext" divs. Then, w ...

Elements listed are often ignored by HTML

My website sends a URL and xpath query to the server in order to extract data from the URL based on the xpath query. While it is functioning properly, I am encountering a singular issue. When I specify an xpath query for href,text, it displays a list of a ...

Modifying Div Size with Jquery

I am working on populating the div container with square boxes, but I'm having trouble adjusting the size of my #gridSquare div. Despite trying to change its height and width using jQuery, it doesn't seem to work as expected. $('#gridSquare ...

Issue with CSS background color not extending to full screen in webkit browsers when using 960.gs grid system

When using 960.gs, I have created a login screen with a div for the login form that has a background image. This div is positioned below a header, which centers it in the browser window. In my CSS, I am setting the body color as follows: body { backgr ...

Paper-dropdown-menu component failing to render properly in web browser

Encountering an issue with the rendered HTML for a basic paper-dropdown-menu. Instead of displaying as a styled menu, the list items are just appearing as a plain list on the page. Upon clicking the rendered paper-input component within the dropdown, the ...

What are some methods for creating a responsive table design?

Here is my table that needs to be made responsive: <table style="width:100%" class="table table-hover"> <tr> <th>Booking Date</th> <th>Booking Id</th> ...

Display a div when hovering over another div

I have a menu that looks like this: https://i.sstatic.net/WqN33.png and I want to create a hover effect where another div shows up over each item, similar to this: https://i.sstatic.net/JRaoF.png However, I can't seem to figure out how to implemen ...