Ensure that the div remains fixed to a specific percentage of the screen's size

Currently, I am working on enhancing my personal website to make it more user-friendly and responsive. You can check out the live version of the site at .

My main goal is to ensure that the right half of the webpage adjusts dynamically based on the screen size, while keeping the left bar consistently sized. To achieve this responsiveness, I have been experimenting with adjusting the container width property.

To test these changes effectively, I recommend using tools like Firebug or inspect element feature in your browser. By modifying the .container width from a fixed 940px to a percentage value like 80%, I observed improvements on wider screens but encountered issues on smaller devices.

.container {
    position: relative;
    width: 940px; /* Consider changing to % for responsiveness */
    margin: 0 auto;
    -webkit-transition: all 1s ease;
    -moz-transition: all 1s ease;
    -o-transition: all 1s ease;
    transition: all 1s ease;
    float: left;
    padding-left: 45px;
}

Additionally, I aim to make the portfolio section scale gracefully as the viewport size decreases. Currently, when the screen size shrinks, the images in the portfolio area pile up below the left bar abruptly. Ideally, the number of displayed images should decrease gradually as the screen gets smaller.

While troubleshooting further, I realized that certain CSS properties, notably those affecting the categories and social media sections, may need adjustment for optimal responsiveness.

The filters part specifically pertains to the category display:

#filters {
    margin: ; /* Add a proper value */
    padding: 0;
    list-style: none;
    border-bottom: solid 1px #dad8d6;
    width: 920px;
    padding-top: 5px;
 }

Your feedback and suggestions are greatly appreciated!

Answer №1

Instead of relying on fixed width values, it is recommended to use percentages for a more responsive design. Bootstrap should be used only after mastering CSS to speed up development process.

To ensure responsiveness, include the following meta tag in your <head> section:

<meta name="viewport" content="width=device-width, initial-scale=1">

In your global css, add the following code snippet to allow percentage-based elements to resize with padding intuitively:

html {
    -webkit-box-sizing: border-box;
            box-sizing: border-box;
}

*,
*:before,
*:after { 
    -webkit-box-sizing: inherit;
            box-sizing: inherit;
}

The key is to experiment with floats, positioning, and percentages until achieving the desired layout. For instance, setting the #sidebar position to fixed and adjusting other values led to a functional layout:

#sidebar {
    width: 270px;
    background-color: #fbfbfb;
    box-shadow: 0px 0px 1px #959595;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 999;
}

.container {
    position: relative;
    padding-left: 286px;
}

#filters {
    padding: 0;
    list-style: none;
    border-bottom: solid 1px #dad8d6;
    padding-top: 5px;
}

Answer №2

Creating a responsive design can be achieved by using meta tags that adapt to the viewport size. Setting width:100% helps resolve any pixel/fixed value conflicts. Adjustable margins may be necessary, or consider utilizing Bootstrap for an easier solution.

Answer №3

Here are some tips to help you get started.

To update your CSS, make the following changes:

#filters {
  width: 100%;
}

.container {
  width: auto;
  position: absolute;
  left: 270px;
}

.sidebar {
  position: fixed;
}

Remember to adjust all container widths to auto in media queries.

Answer №4

Avoid using fixed width or height if you want your design to be responsive. Using percentages is a better approach. It's important to note that 20% + 80% does not always equal 100%. If you set the widths of two inline-block elements to 20% and 80%, it can cause issues. A workaround is to have one element at 20% and the other at 78%. Responsive design is crucial in web development and Bootstrap offers great solutions for this. Make sure to check it out and good luck with your projects!

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

Unable to delete Google+ button

I am facing an issue with my WordPress site where the social buttons added by the 'Yet Another Social Plugin' are showing up on the mobile version of my website customized with WP-Mobile. I have been able to remove all the buttons except for the ...

Invisible boundary line within the column

My task involves creating a table using div elements. The layout of the table includes two columns structured as follows: <div> <div class = "columnborder"><span>Some text for column 1</span></div> <div><span>Some ...

What causes variations in layouts when using the same CSS grid code across different pages?

I've encountered an issue where the CSS on two pages, with slight color changes, is behaving differently in terms of grid layout. Despite multiple attempts to troubleshoot by adjusting items, grid-template-layout, and other parameters, the issue persi ...

To grab a specific CSS attribute from a stylesheet using JavaScript

I am looking for a way to extract the value from a CSS file using a JavaScript function. Take a look at my code snippet below: HTML file -> <link rel="stylesheet" type="text/css" href="test_css.css" /> <script type="text/javascript ...

Unable to get click function to work with multiple div elements

Using four div elements, I have implemented a feature where clicking on the first div causes all other div elements to change opacity. This is working correctly. However, I would like the opacity of the first div to remain unchanged when moving to another ...

Is it necessary to set up Tailwind CSS for each new project we start?

Is it necessary to install Tailwind CSS and its files for each new project in every new directory? I'm uncertain if this is the correct process, or if there is an alternative method available. Furthermore, when making changes to files on a live serve ...

CSS transition not working properly when toggling

I am working on creating a toggle feature for a div that can expand and collapse upon clicking. While I have successfully implemented the expand transition using max-height to accommodate varying content sizes, I am facing difficulties with transitioning t ...

Transforming a sequence of characters into a multidimensional array

I have a nested for loop that generates an empty string value representing a multidimensional array. After the loops finish, the output looks like this: "[[0,0,0,0],[0,0,0,0]]" Now, I want to insert this into a multidimensional array within my code. How ...

Is there a more efficient method for horizontally and vertically aligning in this particular scenario using HTML and CSS?

Embarking on my HTML/CSS journey, I am taking on the challenge of creating my very first website. Currently tackling the final CSS project for Codecademy. I've been tinkering with this task for what feels like an eternity and just can't seem to ...

Avoiding HTML Encoded Characters when sending button or form submissions

When a user clicks a button that uses the GET method, I need to send multiple values at once. To achieve this, I am using an argument in the following way: $argument='var2=value2&var3=value3'; echo "<button value='value1&$argument ...

What is the best way to display the complete text or wrap a menu item in an Angular Material menu?

Is it possible to display the full text of a menu item instead of automatically converting it to ellipses or breaking the word? I've tried various CSS methods without success. Any suggestions? https://i.stack.imgur.com/3l7gE.png #html code <mat-m ...

What's the reasoning behind incorporating a superscript esf in the Zap Chance typeface?

I'm working with a sample HTML file that includes the Zap Chance font. <!DOCTYPE html> <html> <head> <style> @font-face { font-family: myFirstFont; src: ...

Trouble with alignment of text in two rows using Div/text - a simple fix needed

I'm currently facing some challenges with a simple task, due to being new to web design and system administration. My boss requested two phone numbers instead of one in the top box, and I need them aligned while keeping the "free estimate" button in p ...

I am looking to implement an animation that automatically scrolls to the bottom of a scrollable DIV when the page is loaded

My DIV is configured with overflow-y set to scroll. .scrolling-div { width: 85%; height: 200px; overflow-y: scroll; } If I have an abundance of content within this div, my goal is for it to automatically scroll to the bottom upon loading the page. I am ...

Listening for a click event on a newly added element using JQuery

I am relatively new to using JQuery and I have encountered an issue with adding a click event listener for a dynamically created button. When the user clicks on the first button, my function successfully adds a second button to a div. However, I am facing ...

A guide to updating a button in Angular:

Currently, I have implemented a directive that displays 3 tabs at the bottom. However, I am curious to know if it is possible to swap out "exterior" for "interior" based on whether I am on the exterior or interior page. For example, when on the exterior ...

Increasing a hyperlink to the surrounding container

I am currently working on a design that involves a button with multiple options. Here is the CSS code for the button: .menu-main-window { position: absolute; top: 5px; bottom: 5px; left: 0px; right: 0px; font-size: 0; } ...

What is the best way to restore the original dimensions of images after they have been altered?

I have content displayed on a webpage with images, each image having a specific width or none specified. When a user clicks a button, the content is exported to a PDF file. To ensure the images fit correctly on the PDF page, I adjust their width and height ...

Seeking guidance on utilizing jQuery to trigger changes in CSS properties upon

Just starting out with jQuery and hoping to find an easy script (or maybe a more straightforward approach) that allows for changing the CSS property of one element when another element is hovered over. For instance, hovering over this image could cause th ...

Can you save data entered by a user into a text file using JavaScript or a similar technology in HTML, without the need to send it to a server?

Is there a way to create a site where user data is inputted into an input box or form, and then that information is stored in a .txt file on the user's C drive without uploading it to a server first? I've been experimenting with various forms an ...