Overlap with a translucent div in a responsive website - html

I have been working on a self-project to duplicate the reddit page for javascript using the JSON data available. But am not able to replicate the behaviour of the original website in its header section, where the header is responsive (behaviour when screen size is decreased).
GIF : how the original website header section works.
The problem :
Overlap the right side (Login page options) over the left hand side. The overlapping is such that the behind text is not shown. I have managed to do the overlapping, but since the background for the divs are translucent, the behind text too shows. Can't think of any solution for this.
GIF : my header (behind text seen)
The navbar elements transcend down when space is not enough. This is not how it is in the original, where they get hidden by the more and Login section. I cannot figure out how to go about having it in a single row.
GIF : my header (header elements move down)
A smaller, similar sample snippet :
.custom-header-full{
background: rgba(255,255,0,1);
}
/* Top */
.custom-top-header-container{
background: rgba(0,0,0,0.7); /* translucent */
position:absolute;
top:0;
width: 100%;
}
#top-right-div{
position: absolute;
right: 0;
z-index: 1000;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
rel="stylesheet"/>
<div class="navbar navbar-static-top custom-header-full">
<!-- TOPMOST header with Links and Login/Signup -->
<div class="navbar-header custom-top-header-container">
<!-- Left side with various links -->
<div id="top-left-div">
<a class="navbar-brand" href="#">MY SUBREDDITS ▼</a>
<a class="navbar-brand" href="#">POPULAR</a>
<a class="navbar-brand" href="#">ALL</a>
<a class="navbar-brand" href="#">RANDOM</a>
</div>
<!-- Login/Signup on the right -->
<div id="top-right-div">
<span class="navbar-brand">Want to join?
Log in or sign up
in seconds |
<button class="glyphicon glyphicon-wrench tools-icon"></button>
</span>
</div>
</div>
</div>
In case you want to check with the full project, the link on Github.
An interesting point to Note : in the header, the left sided titles are being overlapped by the right sided section. So it is a smooth transaction where the possibility is such that even partial of the text is seen in a title when overlapped. Basically its not a matter of making the title element invisible by width as that would make the whole title invisible.
Ex :
The title has TODAYIL
The title has TODAYILEARNED (whole of the title)

If you're able to use CSS flexbox, I think this solution works the way you want:
.custom-header-full{
background: rgba(255,255,0,1);
}
/* Top */
.custom-top-header-container{
background: rgba(0,0,0,0.7); /* translucent */
position:absolute;
top:0;
width: 100%;
display: flex;
}
#top-left-div {
flex: 1 1 0%;
overflow: hidden;
display: flex;
white-space: nowrap;
}
#top-right-div{
flex: 0 0 auto;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
rel="stylesheet"/>
<div class="navbar navbar-static-top custom-header-full">
<!-- TOPMOST header with Links and Login/Signup -->
<div class="navbar-header custom-top-header-container">
<!-- Left side with various links -->
<div id="top-left-div">
<a class="navbar-brand" href="#">MY SUBREDDITS ▼</a>
<a class="navbar-brand" href="#">POPULAR</a>
<a class="navbar-brand" href="#">ALL</a>
<a class="navbar-brand" href="#">RANDOM</a>
</div>
<!-- Login/Signup on the right -->
<div id="top-right-div">
<span class="navbar-brand">Want to join?
Log in or sign up
in seconds |
<button class="glyphicon glyphicon-wrench tools-icon"></button>
</span>
</div>
</div>
</div>
What I did:
Make .custom-top-header-container display:flex to ensure the left and right display side-by-side.
Make #top-right-div only ever take up the space that its content needs (i.e. don't grow or shrink)
Make #top-left-div fill whatever space remains in the container, and use overflow:hidden to hide any content that might overlap with #top-right-div on small widths.
Set #top-left-div to white-space: nowrap to prevent links with spaces (like "My Subreddits") from breaking onto multiple lines when the screen shrinks small enough.

I've managed to implement a pure-CSS solution without flex of what I assume you wanted to get.
I will highlight some of the changes I've made (the ones that don't directly pertain to the problem and could therefore be overlooked):
Got rid of .navbar, .navbar-static-top, .navbar-header, .custom-header-full and .custom-top-header-container. Please find a way to overwrite their behaviour at your own time if you really need those classes. I can try to help if it proves too difficult.
Removed CAPS LOCK from source and substituted it with text-transform: uppercase; inside the CSS file. This can really help in the future if one happens to fall asleep while adding a new navigation link.
Substituted "▼" with an HTML entity (▼). Modern browsers normally don't care, but it's still good practice.
Here is a Fiddle of the end result. Let me know if you have any questions.

A little hack can help you I guess. Try doing these CSS changes :
#top-right-div {
position: absolute;
right: 0px;
z-index: 1000;
background: rgba(255,255,0,1);
}
And add background: rgba(0, 0, 0, 0.7); to the .navbar-brand under top-right-div in html.
This would create an illusion of what you are trying to achieve.
.custom-header-full{
background: rgba(255,255,0,1);
}
/* Top */
.custom-top-header-container{
background: rgba(0,0,0,0.7); /* translucent */
position:absolute;
top:0;
width: 100%;
display: flex;
}
#top-left-div {
flex: 1 1 0%;
overflow: hidden;
display: flex;
white-space: nowrap;
}
#top-right-div{
flex: 0 0 auto;
background: rgba(255,255,0,1);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
rel="stylesheet"/>
<div class="navbar navbar-static-top custom-header-full">
<!-- TOPMOST header with Links and Login/Signup -->
<div class="navbar-header custom-top-header-container">
<!-- Left side with various links -->
<div id="top-left-div">
<a class="navbar-brand" href="#">MY SUBREDDITS ▼</a>
<a class="navbar-brand" href="#">POPULAR</a>
<a class="navbar-brand" href="#">ALL</a>
<a class="navbar-brand" href="#">RANDOM</a>
</div>
<!-- Login/Signup on the right -->
<div id="top-right-div">
<span class="navbar-brand" style="background: rgba(0, 0, 0, 0.7);">Want to join?
Log in or sign up
in seconds |
<button class="glyphicon glyphicon-wrench tools-icon"></button>
</span>
</div>
</div>
</div>

for Overlap you can use this style:
.custom-header-full{
background: rgba(255,255,0,1);
}
/* Top */
.custom-top-header-container{
background: rgba(0,0,0,0.7);
position:absolute;
top:0;
width: 100%;
}
#top-right-div {
width: 45%;
float: left;
}
#top-left-div {
display: inline-block;
width: 53%;
float: left;
}
Like :demo
and other device you can use media queries Like :
#media (min-width:0px) and (max-width:799px) { add style }
write style according to device.
i thing it's helpful for you.

To handle the stretching issues. Try to inspect the website using responsive option
responsive button
Then you can know the dimension of the screen when the texts are overlapping or the navigation bar is two line high
get the width
So at last you can add your media query to create differences from the desktop website. In case it's 450px
#media only screen and (max-width: 450px) {
/* Add your css specification here. */
}

Related

CSS translateX(100%) on <input> in a parent with overflow causes 'flickering' and inconsistent width

What i'm trying to achieve
example of the closed version /
example of the opened version
At the top of the page in a 'fixed' header, i have a 'search' button next to a 'toggle' for the main menu. The header-search div (magnifying glass) is positioned next to the menu toggler (green). A form is currently positioned 'absolute' within the header to take up the full width of the header minus the padding on each side and its controls (search and toggler) as follows:
styles from header
.header {
top: 0;
left: 0;
width: 100%;
position: fixed;
background-color: var(--color-primary-700);
}
styles from header__aux
.header__aux {
display: flex;
column-gap: 1rem;
flex-flow: nowrap row;
}
.header-search {
display: block;
position: static;
}
.header-search__form {
top: 1.5rem;
height: 4rem;
overflow: hidden;
position: absolute;
left: var(--g-gutter);
width: calc(100% - (7rem + (var(--g-gutter)*2)));
}
.header-search__form-label {
top: -99.9rem;
left: -99.9rem;
color: inherit;
position: absolute;
}
.header-search__form.is-active
.header-search__form-input {
transform: translateX(0%);
}
.header-search__form-input {
width: 100%;
height: 4rem;
padding: 0 1.2em;
transform: translateX(100%);
border: .2rem solid #8097b3;
border-top-left-radius: 2rem;
border-bottom-left-radius: 2rem;
transition: transform 1s ease-in-out
background-color: var(--color-primary-700);
}
A input field inside this form is given 100% width and then using transform: translateX(100%) pushed completely to the right outside the overflow of the form (which retains it's width as set above). When a user presses the 'search' button a class is-active sets this transform: translateX(100%) to 0 and the input field should slide (from the right) to it's original position 100% of the width as seen in this image.
What this looks like in HTML
<header class="header section">
<div class="header__container container">
<a class="header__brand" href="#" aria-label="x">
<!-- svg brand -->
</a>
<div class="header__navs" id="headerNavs">
<div class="header__mask">
<ul id="headerMenu" class="header-menu">
</ul> <div class="header__langs header-langs">
Language
</div>
</div>
</div>
<div class="header__aux">
<div class="header__search header-search">
<button aria-label="Open of sluit het invoerveld voor een zoekopdracht" class="header-search__toggle" id="headerSearchToggle" aria-pressed="false" role="button" tabindex="0">
<i id="headerSearchIcon" class="far fa-search"></i>
</button>
<form class="header-search__form" action="/" id="headerSearchForm" role="search" method="get">
<label class="header-search__form-label" for="headerSearchInput">Zoeken</label>
<div class="header-search__form-slide">
<input placeholder="Zoeken …" required="" class="header-search__form-input" id="headerSearchInput" minlength="2" type="search" value="" name="s">
</div>
</form>
</div>
<a aria-label="" class="header__toggle header-toggle" aria-controls="headerNavs" aria-expanded="false" id="headerToggle" href="#">
Toggle
</a>
</div>
</div>
</header>
The problem
When opening the 'search' the input immediately jumps to the end of the animation which is seen in the example of the opened version (top) and then continues moving left, constantly correcting it's position back to what is seen in the image causing a weird 'flickering' effect usually in this position. Sliding the input 'back' to the right works perfectly.. What's even weirder is that it sometimes does work correctly for a few attempts once i've been on the page for a while. Then suddenly it breaks again.
What i've tried
Different types of browsers, including checking it on my own mobile device (not in the dev tools)
Giving the input the same fixed width as the parent
Removing a translateY on the parent and reverting to 'top' top position it in the vertical center
Adding 1 or multiple parents to the input to force it to inherit that width
As mentioned in a comment, adding transform:translateZ(0.1px); to force rendering using the GPU
What works, but i can't explain
Removing the overflow on the parent form element works and allows the animation to play smoothly, but that shows the input behind the element as seen in this image
I can think of some ways to make this look better, but i just really want to know what i'm missing. I believe i've done these types of simple animations 1000s of times now. A parent with overflow, hiding a child that's translated over.. or perhaps i'm mistaken. Hopefully someone can make sense of this - many thanks if you've taken the time to do so :)

Bulma centered navbar mobile issues

I'm creating a navbar for a current project in react (create-react-app). I'm using the Bulma framework for all css-related things. The current problem lies in the navigation bar, the elements of which should together be centered and visible on mobile.
While this isn't possible with Bulma alone, I used some scss modifications I've found to make it somewhat work:
Stylesheets
.navbar-start { // fixes is-expanded on the navbar items
flex-grow: 1;
flex-shrink: 1;
display: flex;
text-align: center;
}
.navbar-item {
border-style: solid;
border-color: black;
border-width: medium;
}
#center-item {
border-right-width: 0;
border-left-width: 0;
}
HTML (navbar only)
<div>
<nav className="navbar is-dark" role="navigation" aria-label="main navigation">
<div className="container has-text-centered ">
<div className="navbar-menu">
<div className="navbar-start">
<Link className="navbar-item is-expanded has-text-weight-semibold is-size-5" to="/">/home</Link>
<Link id="center-item" className="navbar-item is-expanded has-text-weight-semibold is-size-5" to="/visual">/visual</Link>
<Link className="navbar-item is-expanded has-text-weight-semibold is-size-5" to="/about">/about</Link>
</div>
</div>
</div>
</nav>
</div>
Finally, to make this horizontal navbar visible on mobile, I've also modified a bulma variable according to this in the scss file.: $navbar-breakpoint: 0.
In the end, the issue is the following:
This is on an iPhone 7. I haven't been able to reproduce it on desktop Firefox by resizing the window. For further examination, you can use this is the live version of the site: http://51.15.246.99/. I've tried many things in fixing this issue so any help would be appreciated.
The solution to the issue is somewhat hacky. After posting about it on GitHub's issue page for Bulma and after some careful on-device debugging the issue turned out to be caused by this (abridged) css rule in Bulma:
.navbar-menu {
margin-right: -0.75rem;
}
In quoting the creator of the framework "It's to align the navbar container with the other containers. But it should only exist on desktop". It existed on mobile as I've set the navbar-breakpoint to 0. The fix was to just include this in my custom css:
.navbar-menu {
margin-right: 0 !important;
}
GitHub issue: https://github.com/jgthms/bulma/issues/3055

Why are items in my web image gallery disappearing on ios?

I have a gallery of images in a scrolling layout on a website. On PC, all the images show. On Android, all the images show. On iPhone, using the same browser as on Android (Chrome or Firefox), when scrolling through the images some of them don't appear, or only half-appear until they are scrolled offscreen and then back again. The images still exist in the layout and can still be tapped to open the lightbox. Why is this happening? I'm using lozad.js to try to solve this problem (because I thought it might be just loading too much data at once) but the problem existed before I implemented lozad. Here's my code for each image:
.gallery {
padding-top: 13px;
z-index: 3;
position: relative;
overflow: scroll;
-webkit-overflow-scrolling: touch;
height: calc(100vh - 13px);
}
.thumbnail {
min-height: 25%;
width: 25%;
margin: 10px;
border-radius: 10px;
}
/** LIGHTBOX MARKUP **/
.lightbox {
/** Default lightbox to hidden */
display: none;
/** Position and style */
position: fixed;
z-index: 999;
width: 100%;
height: 100%;
text-align: center;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.8);
}
.lightbox img {
/** Pad the lightbox image */
max-width: 90%;
max-height: 80%;
margin-top: 5%;
}
.lightbox:target {
/** Remove default browser outline */
outline: none;
/** Unhide lightbox **/
display: block;
}
<div id="mobile" class="gallery">
<!-- thumbnail image wrapped in a link -->
<a href="#img1-mobile">
<img src="thumb/lo/1.jpg" data-src="thumb/hi-mobile/1.jpg" class="lozad thumbnail">
</a>
<!-- lightbox container hidden with CSS -->
<a href="#_" class="lightbox" id="img1-mobile">
<img src="img/lo/1.jpg" data-src="img/hi/1.jpg" class="lozad">
</a>
<!-- thumbnail image wrapped in a link -->
<a href="#img2-mobile">
<img src="thumb/lo/2.jpg" data-src="thumb/hi-mobile/2.jpg" class="lozad thumbnail">
</a>
<!-- lightbox container hidden with CSS -->
<a href="#_" class="lightbox" id="img2-mobile">
<img src="img/lo/2.jpg" data-src="img/hi/2.jpg" class="lozad">
</a>
<!-- thumbnail image wrapped in a link -->
<a href="#img3-mobile">
<img src="thumb/lo/3.jpg" data-src="thumb/hi-mobile/3.jpg" class="lozad thumbnail">
</a>
<!-- lightbox container hidden with CSS -->
<a href="#_" class="lightbox" id="img3-mobile">
<img src="img/lo/3.jpg" data-src="img/hi/3.jpg" class="lozad">
</a>
...
</div>
Here’s a hacky but effective fix:
#mobile img {
transform: translate3d(0, 0, 0);
}
“But why does this work?”
Because it’s a mobile browser engine, WebKit WebCore cuts a lot of corners when performing Composite and Paint stages. It does this in the name of battery life, and generally that’s a great tradeoff. By applying a 3D transformation (even a null one), these two stages are passed off to the hardware-accelerated (read: more power hungry) graphics engine.
In your case, this corner-cutting occurs when an image is off-screen up until the point it’s interacted with by the user (clicking on it does the trick).
Since these calls only occur when the page requires a repaint (scrolling & zooming mostly), the penalty to your users battery-wise should be minimal.
It turns out mobile versions of WebKit have struggled with image-heavy pages for almost 6 years. The solution there, incidentally, is effectively the same. Sometimes the old ways still work best :p

bootstrap overlay list group

I'm trying to give a button slide in effect just for a mock up using bootstrap lists and overlays. I want to make it look like the button is coming in from the right. Here is the code for what Im trying to do. I'm trying give the li element a positive relative and z-index so it is "above" the .pull-right div.
Any idea what I could do for this to work? The button labeled Test should look like it is coming in from the right, therefore half the text should be visible and half should be not.
As per my understanding I think you might have to hide the overflow of the li
So, I added a class to your html structure
<ul class="list-group">
<li class="list-group-item pos-rel overflow-x-fix">
<p class="inline-block">Test</p>
<div class="pull-right pos-abs">
<button>Text</button>
<button>Test</button>
</div>
</li>
</ul>
And changed the CSS like this
inline-block{
display: inline-block;
}
.pos-rel{
position: relative;
z-index: 999;
}
.pos-abs{
position: absolute;
right: -2%;
top: 20%;
z-index: 1;
}
.overflow-x-fix {overflow-x: hidden;}
Here is the example

CSS positioning?

I was hoping someone might be able to assist me with a simple CSS positioning question.
I have a link I want to show next to my top navigation but I do not want it to move in different browser sizes.
I have create a div with a class called "language" as seen below.
<!-- nav -->
<nav id="nav-main" role="navigation">
<?php alanbrandt_nav(); ?>
</nav>
<div class="language">
Dansk
</div>
I have also created the following CSS class but when I use this all the article links in the menu can't be clicked. It's as if the link has been removed from the menu items.
.language {
position:relative;
left:340px;
top:-27px;
}
Ideally the link should appear aligned to the right hand edge of the image but horizontally aligned with the top navigation bar. The above achieves the correct layout but stops the navigation from working as none of the menu items are active.
http://alanbrandt.com
Can someone tell me how I go about this?
Thanks
You should put your language div into the nav, and use absolute positioning :
HTML
<!-- nav -->
<nav id="nav-main" role="navigation">
<?php alanbrandt_nav(); ?>
<div class="language">
Dansk
</div>
</nav>
CSS
#nav-main {
position: relative;
width: 760px;
margin: 0 auto;
}
#nav-main .language {
position: absolute;
right: 0;
top: 0;
}
you need a dot before the class name:
.language {
position:relative;
left:200px;
top:40px;
}