The CSS background gradient appears distorted on larger screens

https://i.sstatic.net/SN1j8.jpg

This layout design is my own creation. It's structured like this:

<div class="outer">
 <div class="container">
    <div class="content"></div>
    <aside></aside>
 </div>
</div>

Here is the CSS for this layout:

.container{width:1000px; margin:0 auto;}
.content{width:70%; float:left;}
aside{width:30%; float:left;}

Now, I'm looking to add a gradient background to the sidebar. While I can create a gradient image repeat-y for the sidebar, it causes the container's margin-right space to also have the same gradient effect.

To tackle this issue, I applied the background gradient to the .outer div. This works well on normal desktop screens, but higher resolution displays show some displacement in the gradient.

https://i.sstatic.net/tzIuE.jpg

The displacement is due to percentage values used in generating the gradient. Here's the default gradient line without prefix that I used:

background: linear-gradient(to right,  #ffffff 0%,#ffffff 67%,#e5e3e6 66%,#f5f5f5 72%,#f5f5f5 100%);

Any suggestions for fixing this issue?

** The page has a long content area with a short sidebar. However, the background should extend from top to bottom.

If you would like to see a live example, visit

Answer №1

Consider using this CSS code to style the container_wrap class

#main .container_wrap
{
    background:-webkit-linear-gradient(left, #ffffff 0%,#ffffff 50%,#e5e3e6 66%,#f5f5f5 72%,#f5f5f5 100%);
}

Answer №2

Instead of applying the background gradient to the entire container and setting specific percentages for where it should start in order to fit over the aside element, I suggest applying it directly to the aside itself and adjusting the styling accordingly.

In addition to resolution issues, you also seem to have duplicate percentage values stored.

aside{
   width:30%;
   float:left;
   //background gradient definition here
}

http://jsfiddle.net/abc123xyz/

Answer №3

When you use your browser, it will display the correct information. One quick option is to utilize media queries for larger screens.

@media screen and (min-width: 1500px) #main .container_wrap {
    background: linear-gradient(to right, #ffffff 0%,#ffffff 62%,#e5e3e6 66%,#f5f5f5 72%,#f5f5f5 100%);
}

Alternatively, you can simply specify a width of 62% for the white gradient. This should work fine as well.

Answer №4

It seems like the goal is to create a page with specific design elements:

  1. A background gradient from top to bottom, transitioning from #fff for the content section
  2. A dark region for the sidebar
  3. Consistent display on large and small screens

Here's what has been accomplished:

  1. The body now has a gradient background, transitioning from white on the left to a dark color on the right
  2. Varying gradients with dark colors that end in the same shade as the body (ensure consistency across screen sizes)
  3. The container spans the full height of the screen alongside the sidebar

Feel free to view the Fiddle

body{background: linear-gradient(to right,  #ffffff 0%,#ffffff 67%,#e5e3e6 66%,#cfd7da 72%,#cfd7da 100%);margin:0;}
.container{width:400px; margin:0 auto;background:#fff;height:100vh;border:1px solid #999;}
.content{width:70%; float:left;height:100vh;}
aside{width:30%; float:left;background: linear-gradient(to right,  #acb9bf ,#cfd7da 72%,#cfd7da 100%);height:100vh;}

Answer №5

Hey there, give this a shot and see if it works out for you!

    background: linear-gradient(to right, #ffffff 0%,#ffffff 0%,#e5e3e6 66%,#f5f5f5 72%,#f5f5f5 100%);

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

Guide to highlighting input field text using Angular

I've set up an angular page that includes an input field within its template. My goal is to highlight the text in the input field when a specific function is triggered. When I refer to "highlighting the text," I mean (check out the image below) https ...

How do you locate elements using text in Selenium with special characters like &#65279?

As a newcomer to test automation, I'm looking for a way to click on a link with only partial text available. I am aware of the find_element_by_partial_link_text method, but there seems to be random words in the code that include &#65279;. This pre ...

Arranging images in layers using jQuery or CSS

My current challenge involves two overlapping images. I am looking for a solution where clicking on the back image will bring it forward. I prefer a simple method that is also mobile-friendly since I am using Bootstrap for responsiveness. What suggestions ...

Bootstrap 4 - Interactive horizontal timeline for optimal viewing on all devices

I'm working on creating a responsive horizontal timeline using Bootstrap 4 for my timeline and project. The code I've developed so far is working well in terms of being responsive. timeline.html <div className="container timeline-container"& ...

Using jQuery to make an element follow you as you scroll down a page inside a div

I've made some progress on my code: HTML <div id="header"></div> <div id="content"> <div class="sidebar-wrapper"></div> </div> <div class="session-wrapper"></div> <div id="footer"></div> ...

"Trouble with 3D hexagonal grid in CSS - unable to achieve desired display

In order to create a dynamic Hexagonal Grid using CSS, the objective is to automatically reorganize hexes in a circular or rectangular manner when a new div with a specific class (e.g. 'hexes') is added to the view. Currently, there is a grid wi ...

Please send the element that is specifically activated by the onClick function

This is the HTML code I am working with: <li class="custom-bottom-list"> <a onClick="upvote(this)"><i class="fa fa-thumbs-o-up"></i><span>upvote</span></a> </li> Here is my JavaScript function for Upvot ...

What is the best way to extract a JSON object from a website search using getJSON or similar techniques?

Can anyone provide guidance on utilizing .getJSON() to access JSON-encoded information from a website that is being searched? I've implemented a Google Custom Search API for my site with the aim of retrieving the JSON file from the search results. Fo ...

Exploring json data with angularjs

I am facing a challenge with handling a complex JSON object by looping through it and displaying the data in a form. To tackle this, I have created a small service similar to the one shown below: service.myApprovalResults = function(){ var url = " ...

Adjust the position and size of an image by hovering over it with your

I'm currently working on implementing a button menu for my website, but I'm facing an issue with the hover effect on images. You can check out what I've done so far at http://jsfiddle.net/tNLUx/ What I want to achieve is when hovering over ...

Using JavaScript to modify a section of an anchor link attribute

I am looking to dynamically update part of the URL when a specific radio button is selected. There are three purchase links, each representing a different amount. After choosing an animal, I need to select one of the three amounts to spend. How can I modi ...

Ways to generate multiple choices for options

Is there a method to provide multiple options within an option? I am utilizing CSelect to create options. One of the options needs to include additional options. <CSelect custom name="select_pattern_filter" id="select_pattern_filter" ...

Tips for maintaining a stationary element with fluctuating height positioned at the bottom in React

I am trying to create a fixed element with dynamic height, meaning its size changes when the browser window is resized. You can see an example of what I'm talking about here: https://stackblitz.com/edit/react-yuqarh?file=demo.tsx This element acts li ...

Shorten/Alternate coding:

Sometimes, creating the content section of a website can be time-consuming. I recently spent half a day crafting the index page of my website at . However, when attempting to add an additional image to the list of six already present, it turned into a leng ...

Although the xpath simulates a click on the button, it does not actually perform any action

I've been diligently working on an automation test suite for a web application that can be quite temperamental. Following a recent UI update, I decided to run some tests to ensure the GUI, buttons, and xpaths were functioning as expected. The night b ...

What could be causing the discrepancy in results between the first and second methods?

Implementing Weather Icons: const getWeatherIcon = (iconParameter) => { const icon = `https://openweathermap.org/img/wn/${iconParameter}@2x.png` return <img src={icon} alt={iconParameter} /> } <div className="weathericon"> ...

Tips for establishing a fixed point at which divs cease to shrink as the browser size decreases

There are numerous dynamically designed websites where divs or images shrink as the browser size decreases. A great example of this is http://en.wikipedia.org/wiki/Main_Page The div containing the text shrinks proportionally to the browser size until it ...

align the button to the left using bootsrap configuration

Is there a way to align a button to the left using bootswatch/Litera, which is a bootstrap 4 beta theme? I attempted to use the float-left class on the button and place it inside a div, but the outcome remained the same. https://i.sstatic.net/qs4zU.png ...

Modifying the disabled attribute of an input tag upon button click in Angular 2

I am currently working on a function in Angular 2 where I want to toggle the disabled attribute of an input tag upon button click. Right now, I can disable it once but I am looking to make it switch back and forth dynamically. Below is the HTML template c ...

The div element is failing to adjust its height correctly to match its parent container

I'm struggling to make the red border that wraps around the text extend all the way to the bottom of its parent div. Setting the height to 100% isn't achieving the desired effect, as it needs to match the height of the image. Tip: Try resizing y ...