Reputation: 13
I've been going crazy these past couple of days trying to figure out a way to fix this.
My issue: I want to have a column part(let's say 10%) at the right of an basic one page site(no scroll bar)
Here's an example: https://jsfiddle.net/498v5reh/
#sidecolor {
float: right;
margin: 0;
overflow: hidden;
background: url(https://i.pinimg.com/736x/b9/78/50/b97850a4460e7a80600a3e0eb6b1bc4d.jpg);
background-repeat: no-repeat;
background-size: cover;
padding: 100% 10%;
}
But when I add the background-image to the column, since the image is larger it expands through the column creating a scroll bar.
Is it possible to have the image cropped depending on the viewer's screen size so there's no scroll bar at all?
Thanks
Upvotes: 1
Views: 239
Reputation: 1
#sidecolor {
background-clip: border-box;
background-color: rgba(0, 0, 0, 0);
background-image: url("https://i.pinimg.com/736x/b9/78/50 /b97850a4460e7a80600a3e0eb6b1bc4d.jpg");
background-origin: padding-box;
background-position: 0 0;
background-repeat: no-repeat;
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
}
Upvotes: 0
Reputation: 4946
So you want it fixed.
Add the following CSS to your #sidecolor. And clean up.
#sidecolor {
position: fixed;
right: 0;
}
body {
background-color: rgb(247, 233, 233);
color: black;
font-family: Source Sans Pro, monospace;
margin: 0;
width: 100vw;
height: 100vh;
}
#maintext {
margin: 0;
float: left;
font-size: 1.8rem;
font-weight: 300;
padding: 20% 0 0 20%;
position: absolute;
}
#sidecolor {
position: fixed;
right: 0;
margin: 0;
overflow: hidden;
background: url(https://i.pinimg.com/736x/b9/78/50/b97850a4460e7a80600a3e0eb6b1bc4d.jpg);
background-repeat: no-repeat;
background-size: cover;
padding: 100% 10%;
}
<div id="site">
<div id="sidecolor">
</div>
<div id="maintext">
</div>
</div>
Upvotes: 1
Reputation: 933
You are using the wrong approach. If you want a fixed column on the right use the position absolute:
#sidecolor {
position: absolute;
right: 0;
top: 0;
width: 10%;
height: 100%;
background-color (...);
padding: 10% 10%;
box-sizing: border-box;
}
Another problem is the padding. Don't use the 100%, and I have used the box-sizing: border-box so that the padding does not change the height.
Link: https://jsfiddle.net/498v5reh/15/
Upvotes: 1