CSS Adaptive Colour Slide on Nav [closed] - css

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I am trying to create some CSS that slides the background colour of the nav element based on the current area of the page that the user is on. A good example is the Dropbox home page for mobile(https://dropbox.com) I can see that they they have just created 3 separate navs with the colours but cannot figure out how they have achieved the colour swipe effect.
I have done some light CSS work in training in the past and tried to figure it out/look through the site but came up with nothing. I have also found a guide on doing something similar with horizontal scroll but nothing on vertical scroll.

If you take a look at their DOM, you can find a section that is repeated with different classes:
<section class="RebrandNavigation RebrandNavigation-theme__sapphire-french-vanilla">
<section class="RebrandNavigation RebrandNavigation-theme__french-vanilla">
<section class="RebrandNavigation RebrandNavigation-theme__default">
These sections have exact same div and nav inside them:
<div class="RebrandNavigation-container"><nav class="RebrandNavigation-container-content">
But there is a little difference! div and nav wrapped with section have different background colors based on section class; Because you need different background color when passing through different section:
.RebrandNavigation-theme__sapphire-french-vanilla .RebrandNavigation-container, .RebrandNavigation-theme__sapphire-french-vanilla .RebrandNavigation-container-content {
background: #0d2f81;
}
.RebrandNavigation-theme__french-vanilla .RebrandNavigation-container, .RebrandNavigation-theme__french-vanilla .RebrandNavigation-container-content {
background: #ffe7aa;
}
.RebrandNavigation-theme__default .RebrandNavigation-container, .RebrandNavigation-theme__default .RebrandNavigation-container-content {
background: #fff;
}
And then clip the wrapper of nav to specify a specific region of it to display using clip css property.
Now, let's combine these all together:
* {
margin: 0;
box-sizing: border-box;
}
html, body {
height: 100%;
font: 14px/1.4 sans-serif;
}
.RebrandNavigation {
position: relative;
height: 100vh;
padding-top: 80px;
}
.RebrandNavigation-container {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
clip: rect(auto, auto, auto, auto);
pointer-events: none;
}
.RebrandNavigation-container-content {
position: fixed;
width: 100%;
top: 0;
font-size: 60px;
}
.RebrandNavigation-theme__sapphire-french-vanilla {
background: #fbb;
color: #000;
}
.RebrandNavigation-theme__french-vanilla {
background: #0bf;
color: #fff;
}
.RebrandNavigation-theme__default {
background: #bfb;
color: #000;
}
<section class="RebrandNavigation RebrandNavigation-theme__sapphire-french-vanilla">
<div class="RebrandNavigation-container">
<nav class="RebrandNavigation-container-content RebrandNavigation-theme__sapphire-french-vanilla">Dropbox Navbar</nav>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. At ultrices mi tempus imperdiet nulla malesuada pellentesque elit. Nulla posuere sollicitudin aliquam ultrices. Elit duis tristique sollicitudin nibh sit amet commodo nulla. Felis donec et odio pellentesque diam. Aenean et tortor at risus viverra adipiscing at in tellus. Sit amet facilisis magna etiam tempor. Pellentesque id nibh tortor id. Purus semper eget duis at tellus. Tincidunt augue interdum velit euismod. Donec enim diam vulputate ut. Vel orci porta non pulvinar neque laoreet suspendisse interdum consectetur. Est lorem ipsum dolor sit amet consectetur. At ultrices mi tempus imperdiet.</p>
</section>
<section class="RebrandNavigation RebrandNavigation-theme__french-vanilla">
<div class="RebrandNavigation-container">
<nav class="RebrandNavigation-container-content RebrandNavigation-theme__french-vanilla">Dropbox Navbar</nav>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. At ultrices mi tempus imperdiet nulla malesuada pellentesque elit. Nulla posuere sollicitudin aliquam ultrices. Elit duis tristique sollicitudin nibh sit amet commodo nulla. Felis donec et odio pellentesque diam. Aenean et tortor at risus viverra adipiscing at in tellus. Sit amet facilisis magna etiam tempor. Pellentesque id nibh tortor id. Purus semper eget duis at tellus. Tincidunt augue interdum velit euismod. Donec enim diam vulputate ut. Vel orci porta non pulvinar neque laoreet suspendisse interdum consectetur. Est lorem ipsum dolor sit amet consectetur. At ultrices mi tempus imperdiet.</p>
</section>
<section class="RebrandNavigation RebrandNavigation-theme__default">
<div class="RebrandNavigation-container">
<nav class="RebrandNavigation-container-content RebrandNavigation-theme__default">Dropbox Navbar</nav>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. At ultrices mi tempus imperdiet nulla malesuada pellentesque elit. Nulla posuere sollicitudin aliquam ultrices. Elit duis tristique sollicitudin nibh sit amet commodo nulla. Felis donec et odio pellentesque diam. Aenean et tortor at risus viverra adipiscing at in tellus. Sit amet facilisis magna etiam tempor. Pellentesque id nibh tortor id. Purus semper eget duis at tellus. Tincidunt augue interdum velit euismod. Donec enim diam vulputate ut. Vel orci porta non pulvinar neque laoreet suspendisse interdum consectetur. Est lorem ipsum dolor sit amet consectetur. At ultrices mi tempus imperdiet.</p>
</section>

Related

How do I control the overflow of an element when the parent width is defined by max-content?

I want to be able to control the width of a parent element to a child element that may exceed the width of the container - of which width is defined by min content and controlled by an element by max content.
article {
width: min-content;
background: cyan;
}
.max-content {
width: max-content;
}
.overflowing-width {
width: 100vw;
height: 20px;
background: darkred;
}
<article>
<h2 class="max-content">This should define the width of the container.</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ac justo tortor. Quisque interdum tempus ipsum, at facilisis libero lobortis vel. Nunc id justo quis risus porta elementum. Duis facilisis a magna sit amet tincidunt. In fermentum et erat quis imperdiet. Vivamus et orci quam. Suspendisse sollicitudin urna id neque bibendum, at luctus orci scelerisque. Integer hendrerit consectetur enim, sed accumsan risus blandit vel. Mauris efficitur orci non luctus pellentesque.</p>
</article>
<article>
<h2 class="max-content">This should define the width of the container.</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ac justo tortor. Quisque interdum tempus ipsum, at facilisis libero lobortis vel. Nunc id justo quis risus porta elementum. Duis facilisis a magna sit amet tincidunt. In fermentum et erat quis imperdiet. Vivamus et orci quam. Suspendisse sollicitudin urna id neque bibendum, at luctus orci scelerisque. Integer hendrerit consectetur enim, sed accumsan risus blandit vel. Mauris efficitur orci non luctus pellentesque.</p>
<div class="overflow-control">
<div class="overflowing-width"></div>
</div>
</article>
The second article's overflow-control element should not exceed the width of the <h2>.
I have tried to use relative positioning through the article element:
article {
position: relative;
}
.overflow-control {
max-width: 100%;
overflow: auto;
}
But this does not alter the behavior what-so-ever.
I have also tried adding an overflow: hidden property to the article element with no effect.

Limit content width in css grid column [duplicate]

This question already has answers here:
Prevent content from expanding grid items
(3 answers)
Closed 5 years ago.
I meet a confused problem with CSS grid. I have a grid with 2 columns, the first is 100px, the second is fit the remaining (grid-template-columns: 100px auto). Everything works right. But if the second column has an extra large element, the width of second column is overflow. I tried to use the max-width but it doesn't work.
Here is my fiddle, please check it: https://jsfiddle.net/truongwp/ka54e7u4/1/
.container {
display: grid;
grid-template-columns: 100px auto;
grid-gap: 30px;
width: 400px;
}
.right {
max-width: 100%;
}
.text {
width: 700px;
max-width: 100%;
}
<div class="container">
<div class="left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed finibus lorem in iaculis dictum. Etiam nec urna et erat volutpat ultrices non vel elit. Nullam commodo tortor a est luctus, et semper ipsum suscipit. Praesent in ipsum quis odio imperdiet posuere
in vitae leo.
</div>
<div class="right">
<div class="text">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed finibus lorem in iaculis dictum. Etiam nec urna et erat volutpat ultrices non vel elit. Nullam commodo tortor a est luctus, et semper ipsum suscipit. Praesent in ipsum quis odio imperdiet posuere
in vitae leo. Aliquam facilisis at justo vel pellentesque. Quisque vitae lobortis nibh, commodo facilisis ante. Nullam facilisis leo vel aliquet egestas. Etiam commodo porta lorem pretium suscipit. Morbi finibus est ac ex suscipit, at feugiat magna
facilisis. Sed tempor ex interdum lobortis gravida. Sed rutrum semper sapien, at finibus metus maximus in. In turpis augue, pellentesque at lectus nec, porta elementum justo. Sed consequat nec dui et interdum. Aenean placerat orci sem, ut blandit
ex semper sit amet.
</div>
</div>
</div>
Thank you very much!
Try to add
overflow: auto
Like this:
.right {
max-width: 100%;
overflow: auto
}
It will fix your trouble!
https://jsfiddle.net/ka54e7u4/2/

Background image won't go all the way to the bottom of page [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
The background image goes to the bottom of the page until you scroll:
Code:
body {
margin: 0;
padding: 0;
overflow: auto;
font-family: sans-serif;
}
body:before {
content: ' ';
display: block;
position: absolute;
width: 100%;
min-height: 100%;
opacity: 0.20;
background-image: url('http://i.imgur.com/KWp2vVP.gif');
}
you may set the image inside html and set an opaque color on top of it in body
html {
background: url('http://i.imgur.com/KWp2vVP.gif')/* fixed then maybe nothing to worry about :) */;
}
body {
margin:0;
min-height:100vh;
background:rgba(255,255,255,0.8);
}
main {
padding:1em;
width:800px;
max-width:100%;
margin:auto;
}
<main><h1>HTML Ipsum Presents</h1>
<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
<h2>Header Level 2</h2>
<ol>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ol>
<blockquote><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est.</p></blockquote>
<h3>Header Level 3</h3>
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ul>
<pre><code>
#header h1 a {
display: block;
width: 300px;
height: 80px;
}
</code></pre>
</main>
Or set the opacity to html:before with bg img in absolute position and sized via coordonates (top,left,bottom,right).
Body will need to be positionned too to stand on top.
html {
position:relative;
}
html:before {
content:'';
position:absolute;
background: url('http://i.imgur.com/KWp2vVP.gif');
top:0;
left:0;
right:0;
bottom:0;
opacity:0.2
}
body {
position:relative;
z-index:1;
margin:0;
min-height:100vh;
}
main {
padding:1em;
width:800px;
max-width:100%;
margin:auto;
}
<main><h1>HTML Ipsum Presents</h1>
<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
<h2>Header Level 2</h2>
<ol>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ol>
<blockquote><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est.</p></blockquote>
<h3>Header Level 3</h3>
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ul>
<pre><code>
#header h1 a {
display: block;
width: 300px;
height: 80px;
}
</code></pre>
</main>
Try adding background-size: cover; in your body:before
If it doesn't work, please provide us an working example on jsfiddle or somewhere else.
Move your background image to body and out of body:before. It should work fine.
body {
background-image: url('http:/i.imgur.com/KWp2vVP.gif');
}

Display Image over another Image

how to display image and text over another image, it looks like this site http://anilist.co/anime/20802/DigimonAdventuretri.
Hint is to use the position: relative with z-index. Basically z-index will put the elemets on top of each other when you will render it.
heres a little demo
header {
position:relative;
width:100%;
height:400px;
background:url('http://91ef69bade70f992a001-b6054e05bb416c4c4b6f3b0ef3e0f71d.r93.cf3.rackcdn.com/deep-forest-1009475.jpg')no-repeat center;
background-size:cover;
}
.img {
position:relative;
float:left;
margin:20px;
width:200px;
height:calc( 100% - 40px );
background:url('http://91ef69bade70f992a001-b6054e05bb416c4c4b6f3b0ef3e0f71d.r93.cf3.rackcdn.com/silhouetted-figure-and-tree-1008861.jpg')no-repeat center;
background-size:cover;
}
.description {
position:relative;
float:left;
margin:20px 0;
width:calc( 100% - 240px);
}
<header>
<div class="img"></div>
<div class="description">
<h2>Lorem Ipsum</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor..</p>
</div>
</header>
<section>
<h1>Actual text</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est.</p>
</section>
In your example, it feels like a container DIV with a background image, with a nested image inside said DIV.
to get a similar result for example :
HTML:
<div id="bg">
<div id="transparentContent">
<img src="imagePath" />
</div>
</div>
CSS:
#bg {
background-image: url("imagePath");
background-size: cover;
background-repeat: no-repeat;
}
#transparentContent {
background-color: rgba(0,0,0,0.5);
color: white;
}
The transparent content DIV is used to create the blackened background over the image.
There are of course, other ways to achieve similar results.

How to restyle website to flow content around sidebar?

I am attempting to write a userstyle to reformat another website (no chance to change html).
Currently the website has main content on left with a full height sidebar on RHS.
I have used CSS to remove much of the sidebar content and would now like the main content to expand to fill the width of the area below the sidebar.
If I had control of the HTML source I would place the sidebar first with 'float: right' in the style but I don't have control of the source and the sidebar div is after main content.
Traditionally this couldn't be done in CSS but can it be done now using CSS3? and if so how?
The pages I am actually attempting to style are TripAdvisor Forum pages such as this one but they are overly complicated to attempt use as an example so I have created this very simple web page to play with:
<!DOCTYPE html>
<html>
<head>
<style>
#mainbody {
border: 2px solid blue;
width: 600px;
}
#sidebar {
border: 2px solid green;
position: inherit;
float: right;
width: 250px;
}
#content {
position: inherit;
width: 550px;
}
</style>
</head>
<body>
<div id=mainbody>
<div id=content>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper
porta. Mauris massa. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper
porta. Mauris massa. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper
porta. Mauris massa.</p>
</div>
<div id=sidebar>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper
porta. Mauris massa. </p>
</div>
</div>
</body>
</html>}
With sidebar above content I get the desired format
Using jQuery you can do this:
$("#content").insertAfter("#sidebar");
http://jsbin.com/juvoc/1/edit

Resources