How do I keep my navigation attached to this fluid image? - css

I created a break point for my background-image using media queries that starts below 989px (the largest image size). I am not using to display the image because I want to use different images for different devices (So that a mobile device doesn't download the largest image of course). (Each image is defined in a specific break-point). Just to say it early, this is live at http://www.glorkianwarrior.com
The css for this goes like so:
.splash {
max-width: 988px;
margin:auto;
height:380px;
}
#media (min-width: 989px) {
.splash {
background: url('../images/academy.png') no-repeat;
}
}
#media (max-width: 989px) and (min-width: 321px) {
.splash {
background: url('../images/academy-mid.png') no-repeat;
max-width: 640px;
padding: 4px;
position: relative;
background-size: 100%;
}
}
That makes it so once the page reaches 988 px or below (down to 321px), the splash image becomes fluid. It actually doesn't change it's width/height until the browser is less than 640px wide. What happens in the navigation bar below it which is nested under .splash won't change its location. This is because its connected to the height of the .splash. The html looks like so:
<header class="splashhead">
<div class="splash">
<nav class="kochalka">
<ul>
<li class="navclass first active"><a href="http://glorkianwarrior.com/" title="Home" >Home</a></li>
<li class="navclass"><a href="news/" title="News" >News</a></li>
<li class="navclass"><a href="gallery.html" title="Gallery" >Gallery</a></li>
<li class="navclass last"><a href="guide.html" title="Guide" >Guide</a></li>
</ul>
</nav>
</div>
</header>
If I don't give it that height, it will disappear. I have tried giving it 100% or a percentage of the page itself. I tried giving its parent a specific height and then doing 100% on .splash, but that didn't change the placement of the navigation bar.
Is it possible to have this navigation change its size based on browser size? Will I have to figure out a way to use images on the page each image within their own div and use media queries to display:none on non-relevant divs?

You need to wrap your nav within a div and then give it an aspect ration using some clever CSS. See Below -
Here is your code:
I have added a wrapper div around the navas you can see
<header class="splashhead">
<div class="splash">
<div class="wrapper">
<nav class="kochalka" style="">
<ul>
<li class="navclass first active">Home</li>
<li class="navclass">News</li>
<li class="navclass">Gallery</li>
<li class="navclass last">Guide</li>
</ul>
</nav>
</div>
</div></header>
Add the following style also and then it will work as you wish
<style>
.wrapper {
width: 100%;
display: inline-block;
position: relative;
}
.wrapper:after {
padding-top: 56.25%; /*16:9 ratio*/
display: block;
content: '';
}
</style>

Related

Make the content of a tab occupy 100% of the available space and avoid a vertical scrollbar [duplicate]

This question already has answers here:
Make a div fill the height of the remaining screen space
(41 answers)
Closed 2 years ago.
I'm trying to make the tab content take up 100% of the available space. but for some reason it is generating a vertical scroll because apparently it is adding the height of the tab. How can I make the content of the tab occupy the available space without generating the vertical scroll?
I am using ng-bootstrap, if you are not familiar with angular don't worry, in this live code you should only see the styles.css file and /app/app.component.html: https://stackblitz.com/edit/angular-ng-bootstrap-9obrp7?file=app%2Fapp.component.html
Note: I can fix this with an overflow, but I want to know why I am getting this problem?
Additional note: ngb-tabset adds 2 elements with class .tab-content and .tab-pane, I set them 100% height, otherwise the tab content would not grow.
This is my code:
<ngb-tabset [destroyOnHide]="false">
<ngb-tab id="nav-tabContent" class="h-100 border1" title="Relación causa con Emoción">
<ng-template ngbTabContent>
<div class="border2 h-100">holi</div>
</ng-template>
</ngb-tab>
</ngb-tabset>
body,html{
height:100%;
margin:0px;
padding:0px;
}
.h-100{
height:100%;
}
.tab-content {
height:100%;
}
.tab-pane {
height: 100%;
}
The reason it's happening is because the total height is actually getting calculated as 100% + the height of the tab element.
You can use flexbox to overcome this quite easily. You can make the container a flex container, and give it the 100% height. Then you use the flex property on it's children to determine whether they will stretch to use the space.
I've used the ngb-tabset element in your code as the container, and added the following CSS to make it take up 100% of the space and display the nav-tabs and tab-content in a column inside it:
ngb-tabset {
display: flex;
flex-direction: column; /* show the child elements in a column */
height: 100%; /* Use the full available height */
}
Then we add the following to tell the tab-content to stretch to the full available height after the nav-tabs, and to stop the nav-tabs from stretching:
ngb-tabset .nav-tabs {
flex: 0; /* do not grow or shrink */
}
ngb-tabset .tab-content {
flex: 1; /* grow or shrink to fill the remaining space */
}
(Note that I only needed to add the CSS for the container to your live code so some other CSS might be having the same effect, but you would usually need the other CSS also.)
Working Example: (I've added a container with id ngb-tabset to replace the ngb-tabset element in your Angular code)
body,html {
height: 100%;
margin: 0px;
padding: 0px;
}
#ngb-tabset, ngb-tabset {
display: flex;
flex-direction: column;
height: 100%;
}
#ngb-tabset .nav-tabs, ngb-tabset .nav-tabs {
flex: 0; /* do not grow or shrink */
}
#ngb-tabset .tab-content, ngb-tabset .tab-content {
flex: 1; /* grow or shrink to fill the remaining space */
}
.tab-pane {
height: 100%;
}
.border2 { border: 1px solid blue;}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<div id="ngb-tabset">
<ul class="nav nav-tabs justify-content-start">
<li class="nav-item">
<a class="nav-link active" href="" role="tab" id="nav-tabContent" aria-controls="nav-tabContent-panel" aria-expanded="true" aria-disabled="false">
Relación causa con Emoción
</a>
</li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="nav-tabContent-panel" aria-expanded="true">
<div class="border2 h-100">holi</div>
</div>
</div>
</div>

vertical and horizontal responsive list

i want to ask you how can i make a responsive list with 3 items in wich when i reduce the size of my browser the items go vertical and the one is below the other, when the browser window is growing the items will be in one. My code for the list is the following , i managed to order them in center and in one row but i am getting confused about the responsive..
<div class="list">
<ul id="2" class="3">
<li>< </li>
<li> </li>
<li> </li>
</ul>
</div>
and the css
.list{
position: relative;
width: 100%;
display: block;
}
.list li {
width: 33.3%; /* nice 3 columns */
float: left;
padding: 0; /* should have zero paddng/margin */
margin: 0;
}
.list li > span {
margin: 6% 6% 0 0; /* now margins are specified relative to outer <li> width */
display: block;
}
What you are looking for are css media queries. For example, add this to your css:
#media (max-width:500px){
.list li {
float:none;
}
}
Here's a jsfiddle.
Suggest you read this:
https://developers.google.com/web/fundamentals/layouts/rwd-fundamentals/use-media-queries?hl=en
https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries
http://cssmediaqueries.com/what-are-css-media-queries.html
You can use media queries to set a breakpoint and set the ".list li" width to 100% when the window width is less than the size you want.
Here's a link about media queries: http://cssmediaqueries.com/

Border Width 100% of HTML + Responsive menu border & icon not correct

The first situation I have with my website is the border bottom of my navigation bar. I have tried changing the box-sizing to border-box but it still doesn't work. I want the border to be 100% width of the browser.
Second, I'm trying to create a responsive menu for both tablet and mobile changing my list items into a hamburger slider. Right now, it is awkward since my header image is floated left, and when i put in the hamburger menu, it does not jump below the logo even after i put clear both. Also, the border of the li is messed up, I want it to fill the width of the screen..
I have yet to put the javascript for the menu icon yet, I don't want to continue until I find a fix to these problems please help :(
html:
<header>
<img src="images/brand.png" alt="George Designs Logo" class="brand">
<img src="images/menu.png" alt="menu" class="menu-trigger">
<nav class="nav-menu">
<ul class="clearfix">
<li>Home</li>
<li>Work</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</header>
The css is in the js fiddle
Here is the full project:
http://jsfiddle.net/ntnzz1fj/2/
You have set some margins which are unwanted on mobile or tablet deives.
You need to remove them for mobile devices in order to have a full width menu.
#media screen and (max-width: 768px) {
.nav-menu {
margin: 0;
}
nav ul {
margin: 0;
padding: 0;
}
nav ul li {
margin-right: 0;
}
}
JSFiddle DEMO
Also remove the browser default margin.
body {
margin: 0;
}
As for making elements fit the whole width of the screen, this combination will ensure it's a block element.
.myElement {
margin: 0;
padding: 0;
display: block;
}
Make to include margin: 0; on the body as well. I would recommend using Normalize.css before your main stylesheet. This normally prevents a lot of common kinks in styling.
http://necolas.github.io/normalize.css/

HTML5/CSS: How to prevent stacking inside a div?

I suppose that this is already in some topic, but I couldn't find the answer that I'm looking for.
I have a header that looks like this:
And its code is the following one:
<header>
<section id="login">
#Html.Partial("_LoginPartial")
</section>
<div class="content-wrapper">
<div class="float-left" id="image-maintitle">
<img src="~/Images/DirecTV.jpg" width="70" height="43" />
<div id="main-title">
<h1 class="site-title">#Html.ActionLink("Disponibilidad de Señal", "Index", "Home")</h1>
</div>
</div>
<div class="float-right">
<nav>
<ul id="menu">
<li>
Ir a sistema de monitoreo
</li>
</ul>
</nav>
</div>
</div>
</header>
The problem is that both div are stacking when I reach a width of 850px, like you can see in this image:
I tried setting up a min-width in content-wrapper class or in "header" tag, but isn't working. The strange thing is that when I try to select "inspect element" of this div on the browser, I can't do it... only I can do it with the elements on the inside.
Here is my CSS document of this classes:
.float-left {
float: left;
}
.float-right {
float: right;
}
header, footer, hgroup,
nav, section
{
display: block;
}
ul#menu
{
font-size: 18px;
font-weight: 600;
margin: 0 0 5px;
padding: 15px 0 0 0;
text-align: right;
}
.content-wrapper {
min-width: 1000px !important;
}
I want to hide the right div behind the scrollbar when its container reaches 1000px of width.
Is there another way to prevent this behavior?
Just set a media query to the "right div", like this:
#media (max-width: 1000px) {
#right-div {
display: none;
}
}
This will only show the right div when the screen resolution is > 1000px in width.
Have you tried max-width instead of min-width? min-width specifies things you want to show if the window is a certain size or larger, whereas max-width specifies things you want to show if the window is at a certain size or smaller.
You may need to set the CSS display property correctly.
Try display:inline-block; or display:block; in the css for each of the elements.
Also setting the max-width:1000px; in the right div
to do this inline use <div style="display:block">
Edit after seeing the Css: Try changing the widths to suit your setup
.float-left {
float: left;
position:relative;
width:80%;
}
.float-right {
float: right;
position:relative;
width:20%;
}

Media Query Not Working With Larger Viewport Sizes

I have a set of social media icons at the top of my sidebar: outtacontext. But I'm having trouble positioning them in the right place at different viewport sizes. Actually, it's working for all the smaller viewports but the positioning is off for the larger screens.
Here's my main css for this positioning:
#top #sidebar_bg .social_bookmarks {
position: absolute;
right: 69px;
z-index: 152;
margin-top: 102px;
}
#media only screen and (max-width: 989px) and (min-width: 768px){
#top #sidebar_bg .social_bookmarks {
right: 33px;
margin-top: 65px;
}
}
For some reason, with the larger screens the icons appear to get centered within the sidebar. But any media queries I make to adjust just start adding problems.
Can anyone point me in the right direction? Thx.
First of all, I'm Argentinean, so forgive me for my English!
Here's my help...
The HTML markup is:
<div id="sidebar_bg">
<ul class="social_bookmarks">
<li class='twitter'>
<a href='http://twitter.com/outtacontext'>Follow us on Twitter</a>
</li>
<li class='facebook'>
<a href='http://facebook.com/chamomileteaparty'>Join our Facebook Group</a>
</li>
<li class='gplus'>
<a href='https://plus.google.com/106461359737856957875/posts'>Join me on Google Plus</a>
</li>
<li class='linkedin'>
<a href='http://linkedin.com/jeffgates'>Add me on Linkedin</a>
</li>
<li class="rss">
RSS
</li>
<li class="flickr">
Flickr
</li>
</ul>
</div>
The CSS styles:
#top #sidebar_bg {
text-align: center; /* This will center EXACTLY on the middle the icons (acording to the #sidebar_bg width on every screen resolution */
}
#top #sidebar_bg .social_bookmarks {
display: inline-block;
z-index: 152;
margin-top: 102px;
}
#media only screen and (max-width: 989px) and (min-width: 768px){
#top #sidebar_bg .social_bookmarks {
margin-top: 65px;
}
}
ALTERNATIVE CSS - if you want to put it right or left, and use media queries to determine the separation width from one of the sides, you can use this:
#top #sidebar_bg {
text-align: *****; /* right or left */
}
#top #sidebar_bg .social_bookmarks {
margin-*****: 40px; /* right or left */
display: inline-block;
z-index: 152;
margin-top: 102px;
}
#media only screen and (max-width: 989px) and (min-width: 768px){
#top #sidebar_bg .social_bookmarks {
margin-*****: 25px; /* right or left */
margin-top: 65px;
}
}
I solved the problem. I had tried making a media query for what I thought was the largest viewport size. As it turns out, I wrote it for the wrong width (just "barely" wrong but you know what that means -g). The media query for positioning should have been set for a min-width of 1140 px. I had set it for 1122px. So close. LOL

Resources