Dynamically fill as much width as possible - html

I have a fixed menubar in the left side. To the right of that I got a section. That section is suppossed to fill 100% of the viewport width minus the fixed menubar width and minus the margin and padding of the section itself.
Now I am also trying to center an image inside of this section - that is the black line that you can see in the fiddle. It is suppossed to be centered in the blue area (the section).
Issue
The section is too wide which you can see, by how the image is not centered but moved a little to the right.
Note:
It should not be possible to scroll the x-axis
Code -> https://jsfiddle.net/n9yyrxfm/
html,
body {
border-sizing: border-box;
font-family: "Dosis", "Arial", "Serif";
text-decoration: none;
font-size: 20px;
margin-left: 10px;
padding: 0;
height: 100%;
width: 100%;
}
.navbar-menu {
z-index: 100;
position: fixed;
width: 15vw;
height: 100%;
color: #000;
margin-top: 4vh;
}
.navbar-menu ul {
padding-left: 0;
}
.navbar-menu ul li {
display: block;
width: 140px;
font-size: 22px;
padding: 4px 0 4px 10px;
margin-top: 20px;
}
p {
width: 250px;
}
div#content {
/*margin-left: -140px*/
margin-left: 160px;
margin-right: 160px;
height: 200px;
}
section {
width: 100%;
color: #000;
display: block;
position: absolute;
top: 35px;
background: lightblue;
transition: opacity 0.9s linear;
-webkit-transition: opacity 0.9s ease-in-out;
-moz-transition: opacity 0.9s ease-in-out;
}
section#sec-home img {
width: 250px;
display: block;
margin: 0 auto 0 auto;
border-radius: 76px 171px 87px 171px;
-moz-border-radius: 76px 171px 87px 171px;
-webkit-border-radius: 76px 171px 87px 171px;
border: 5px solid #000000;
-webkit-box-shadow: 0px 0px 202px 0px rgba(0, 0, 0, 0.49);
-moz-box-shadow: 0px 0px 202px 0px rgba(0, 0, 0, 0.49);
box-shadow: 0px 0px 202px 0px rgba(0, 0, 0, 0.49);
}
<nav class="navbar-menu">
<ul id="list" class="test">
<li id="emph nav-home">Home</li>
<li id="nav-portfolio">Portfolie</li>
<li id="nav-skills">Færdigheder</li>
<li id="nav-erfaring">Erfaring</li>
<li id="nav-kontakt">Kontakt mig</li>
</ul>
</nav>
<div id="content">
<section class="animatedFade" id="sec-home">
<img src="images/portrait1.png" alt="">
<p>asdfr <span class="navn">asdfian</span></p>
</section>
</div>

Since you are using position: fixed for the left sidebar, please use a padding of the same for the parent. So instead of the content having both margin-left and margin-right, leave the content with full width, without the margin.
html,
body {
border-sizing: border-box;
font-family: "Dosis", "Arial", "Serif";
text-decoration: none;
font-size: 20px;
margin-left: 10px;
padding: 0 0 0 15vw; /* Change this to navbar width. */
height: 100%;
width: 100%;
margin: 0; /* Add this. */
box-sizing: border-box; /* Add this. */
}
.navbar-menu {
z-index: 100;
position: fixed;
width: 15vw;
height: 100%;
color: #000;
left: 0; /* Add this. */
margin-top: 4vh;
}
.navbar-menu ul {
padding-left: 0;
}
.navbar-menu ul li {
display: block;
width: 100%;
font-size: 22px;
padding: 4px 0 4px 10px;
margin-top: 20px;
}
p {
width: 250px;
}
div#content {
/* Remove these.
margin-left: 160px;
margin-right: 160px;
*/
height: 200px;
}
section {
/* width: 100%; remove */
color: #000;
display: block;
/* position: absolute; remove */
margin-top: 35px; /* replace */
background: lightblue;
transition: opacity 0.9s linear;
-webkit-transition: opacity 0.9s ease-in-out;
-moz-transition: opacity 0.9s ease-in-out;
}
section#sec-home img {
width: 250px;
display: block;
margin: 0 auto 0 auto;
border-radius: 76px 171px 87px 171px;
-moz-border-radius: 76px 171px 87px 171px;
-webkit-border-radius: 76px 171px 87px 171px;
border: 5px solid #000000;
-webkit-box-shadow: 0px 0px 202px 0px rgba(0, 0, 0, 0.49);
-moz-box-shadow: 0px 0px 202px 0px rgba(0, 0, 0, 0.49);
box-shadow: 0px 0px 202px 0px rgba(0, 0, 0, 0.49);
}
<nav class="navbar-menu">
<ul id="list" class="test">
<li id="emph nav-home">Home</li>
<li id="nav-portfolio">Portfolie</li>
<li id="nav-skills">Færdigheder</li>
<li id="nav-erfaring">Erfaring</li>
<li id="nav-kontakt">Kontakt mig</li>
</ul>
</nav>
<div id="content">
<section class="animatedFade" id="sec-home">
<img src="images/portrait1.png" alt="">
<p>asdfr <span class="navn">asdfian</span></p>
</section>
</div>
This is an issue of Fixed Fluid Layout. Please refer to my guide on Science behind Fixed-Fluid Layouts.

Since your .navbar-menu has position: fixed it gets ignored by all other elements.
However, since it has a fixed width, you can easily solve your problem using calc like this:
section {
width: calc(100% - 15vw);
}
Note that you will then also need to remove Margins from your section as to not make it bigger than that.

Related

div Hover Issue when reaches border

I want hover effect on div, I have applied bottom style when hover on div and everything is working but when hover border/edge of the div means the div jerking/jumping continuously.
my code :
.traning-box {
background: #fff;
padding-top: 70px;
padding-bottom: 30px;
box-shadow: 0 0 35px 5px rgba(0, 0, 0, .07);
border-radius: 5px;
width: 120px;
text-align: center;
}
.traning-box:hover {
bottom: 15px;
position: relative;
}
<div class="traning-box">
<p> Test box</p>
</div>
Try to use :after pseudo-element. When the .traning-box goes up, the :after goes down, so the cursor will still over the .traning-box (because it is a parent block for the :after).
.traning-box {
background: #fff;
border-radius: 5px;
box-shadow: 0 0 35px 5px rgba(0, 0, 0, .07);
padding-top: 70px;
padding-bottom: 30px;
position: relative;
text-align: center;
width: 120px;
}
.traning-box:after {
bottom: 0;
display: block;
content: '';
height: 15px;
left: 0;
position: absolute;
width: 100%;
}
.traning-box:hover {
margin-top: -15px;
}
.traning-box:hover:after {
bottom: -15px;
}
<div class="traning-box">
<p>Test box</p>
</div>
You could use animation to achieve it.
.traning-box {
background: #fff;
padding-top: 70px;
padding-bottom: 30px;
box-shadow: 0 0 35px 5px rgba(0, 0, 0, .07);
border-radius: 5px;
width: 120px;
text-align: center;
margin:20px;
position:relative;
}
.traning-box:hover {
animation-name:move;
animation-duration:1s;
animation-iteration-count:1;
animation-timing-function: ease;
position: relative;
border:1px solid red;
}
#keyframes move{
50%{
transform:translateY(-15px);
}
}
<div class="traning-box">
<p> Test box</p>
</div>
You need to use transition and translate together to achieve smooth hover effect.
.traning-box {
background: #fff;
padding-top: 70px;
padding-bottom: 30px;
box-shadow: 0 0 35px 5px rgba(0, 0, 0, .07);
border-radius: 5px;
width: 120px;
text-align: center;
transition: all 0.5s linear;
}
.traning-box:hover {
transform: translateY(-15px);
position: relative;
}
<div class="traning-box">
<p> Test box</p>
</div>
Try below. You have to use inner div to write a hover effect.
.traning-box{
background: #fff;
padding-top: 70px;
padding-bottom: 30px;
box-shadow: 0 0 35px 5px rgba(0, 0, 0, .07);
border-radius: 5px;
width: 120px;
text-align: center;
}
.traning-box1 {width:120px;}
.traning-box1:hover .traning-box{
bottom: 15px;
position: relative;
}
<br/>
<br/>
<div class="traning-box1">
<div class="traning-box">
<p> Test box</p>
</div>
</div>

CSS only image gallery with thumbnails and zoom

Is it possible to have an image gallery with thumbnails and big preview with zoom? Something like cloudzoom but without any JS, jQuery, Scripts etc as all form of 'scripts and actions' are forbidden and will not work.
We can only use HTML5 and CSS3 no scripts
thanks
Look on this. Hope it helps you.
#images-box {
/* The total width of the image-box, mainly for centering */
width: 850px;
margin: 0px auto;
position: relative;
top: 70px;
}
.image-lightbox img {
/* Inherit the width and height from the parent element */
width: inherit;
height: inherit;
}
.holder {
/* The width and height, you can change these */
width: 250px;
height: 166px;
/* Float left, so everything aligns right */
float: left;
margin: 0 20px 0 0;
}
.image-lightbox {
/* Inherit width and height from the .holder */
width: inherit;
height: inherit;
padding: 10px;
/* Box shadow */
box-shadow: 0px 0px 10px rgba(0,0,0,0.1);
background: #fff;
border-radius: 5px;
/* Position absolutely so we can zoom it out later */
position: absolute;
top: 0;
font-family: Arial, sans-serif;
/* Transitions to provide some eye candy */
-webkit-transition: all ease-in 0.5s;
-moz-transition: all ease-in 0.5s;
-ms-transition: all ease-in 0.5s;
-o-transition: all ease-in 0.5s;
}
.image-lightbox span {
display: none;
}
.image-lightbox .expand {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
.image-lightbox .close {
position: absolute;
width: 20px; height: 20px;
right: 20px; top: 20px;
}
.image-lightbox .close a {
height: auto; width: auto;
padding: 5px 10px;
color: #fff;
text-decoration: none;
background: #22272c;
box-shadow: inset 0px 24px 20px -15px rgba(255, 255, 255, 0.1), inset 0px 0px 10px rgba(0,0,0,0.4), 0px 0px 30px rgba(255,255,255,0.4);
border-radius: 5px;
font-weight: bold;
float: right;
}
.close a:hover {
box-shadow: inset 0px -24px 20px -15px rgba(255, 255, 255, 0.01), inset 0px 0px 10px rgba(0,0,0,0.4), 0px 0px 20px rgba(255,255,255,0.4);
}
div[id^=image]:target {
width: 450px;
height: 300px;
z-index: 5000;
top: 50px;
left: 200px;
}
div[id^=image]:target .close {
display: block;
}
div[id^=image]:target .expand {
display: none;
}
div#image-1:target, div#image-2:target, div#image-3:target { left: 200px; }
div#image-1 { left: 0; }
div#image-2 { left: 290px; }
div#image-3 { left: 580px; }
<div id="images-box">
<div class="holder">
<div id="image-1" class="image-lightbox">
<span class="close">X</span>
<img src="http://www.techinsights.com/uploadedImages/Public_Website/Content_-_Primary/Teardowncom/Sample_Reports/sample-icon.png" alt="earth!">
<a class="expand" href="#image-1"></a>
</div>
</div>
<div class="holder">
<div id="image-2" class="image-lightbox">
<span class="close">X</span>
<img src="http://www.techinsights.com/uploadedImages/Public_Website/Content_-_Primary/Teardowncom/Sample_Reports/sample-icon.png" alt="earth!">
<a class="expand" href="#image-2"></a>
</div>
</div>
<div class="holder">
<div id="image-3" class="image-lightbox">
<span class="close">X</span>
<img src="http://www.techinsights.com/uploadedImages/Public_Website/Content_-_Primary/Teardowncom/Sample_Reports/sample-icon.png" alt="earth!">
<a class="expand" href="#image-3"></a>
</div>
</div>
</div>
You can use css hover to implement image zoom. And using hover property you can create a Image zoom gallery pretty much like you want.
Here is a sample for it.
https://codepen.io/Remedy/pen/ZYJrpp
<style>
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
}
.item {
position: relative;
border: 1px solid #333;
margin: 2%;
overflow: hidden;
width: 540px;
}
.item img {
max-width: 100%;
-moz-transition: all 0.3s;
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
.item:hover img {
-moz-transform: scale(1.1);
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
</style>
<div class="item">
<img src="https://upload.wikimedia.org/wikipedia/en/thumb/5/58/Pepsi_logo.svg/1280px-Pepsi_logo.svg.png" alt="pepsi" width="540" height="548">
<div class="item-overlay top"></div>
</div>
You can also have a look at these links below for complete implementation.
https://codepen.io/elad2412/pen/yfEGp
https://codepen.io/samuelmaggs/pen/ZWpjPN
It is not possible to zoom a image without javascript or JQuery, we need to use a Javascript or JQuery functiononmouseover

CSS Overlay woes

I have some image thumbnails and, on hover, I want the title to be displayed on top of a transparent black <div> overlay which covers the width and height of the thumbnail.
I'm using display: table and display: table-cell; respectively (to allow for vertical middle positioning).
However, every time I try this, the overlay <div> is acting as a small strip rather than covering the whole <div>.
I've tried adding padding and margins but am still unable to get my desired behaviour.
http://jsfiddle.net/jameshenry/t92qukz8/2/
The CSS:
.griditem {
position: relative;
background-color: #777;
-webkit-box-shadow: 0 1px 5px rgba(0, 0, 0, 0.5);
-moz-box-shadow: 0 1px 5px rgba(0, 0, 0, 0.5);
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.5);
width: 50%;
overflow: hidden;
}
.titles {
position: absolute;
display: table;
left: 0px;
top: 0px;
bottom: 0px;
right: 0px;
width: 100%;
opacity:0;
-webkit-transition: opacity .5s ease;
-moz-transition: opacity .25s ease;
background: rgba(0, 0, 0, 0.5);
color: #FFFFFF;
text-decoration: none;
z-index: 999;
}
.titles p {
display: table-cell;
vertical-align: middle;
text-align: center;
text-decoration: none;
}
.griditem:hover .titles {
text-decoration: none;
opacity:1;
}
h5 {
font-family: Helvetica Neue;
font-size: 5em;
color: #FFFFFF;
padding-bottom:0;
margin-bottom:-30px;
}
h6 {
padding-top: 0;
}
}
and the HTML
<div class="griditem" style="background-image:url(https://upload.wikimedia.org/wikipedia/commons/8/80/Aspect_ratio_-_16x9.svg); background-size:100% 100%;">
<img src="http://i.imgur.com/JnW9SPx.png" width="100%" alt="Spacer 16x9" />
<a href="http://www.google.com" class="titles">
<p>BIG TEXT<br>
small Title<p>
</a>
</div>
How can I alter my css/html to get my desired behaviour?
In order to have the table take up 100% height, it needs to have a height context to reference (since no parent is set to any 'height', it collapses). Your problem can be solved by adding a wrapper to your table that sets that context, and adding height:100%; to your display:table; element.
.griditem {
position: relative;
background-color: #777;
-webkit-box-shadow: 0 1px 5px rgba(0, 0, 0, 0.5);
-moz-box-shadow: 0 1px 5px rgba(0, 0, 0, 0.5);
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.5);
width: 50%;
overflow: hidden;
}
/*added overlay CSS*/
.overlay {
position: absolute;
left: 0px;
top: 0px;
bottom: 0px;
right: 0px;
width: 100%;
height: 100%;
}
.titles {
display: table;
width: 100%;
height: 100%; /*important, forces to 100% height of parent*/
opacity:0;
-webkit-transition: opacity .5s ease;
-moz-transition: opacity .25s ease;
background: rgba(0, 0, 0, 0.5);
color: #FFFFFF;
text-decoration: none;
z-index: 999;
}
.titles p {
display: table-cell;
vertical-align: middle;
text-align: center;
text-decoration: none;
}
.griditem:hover .titles {
text-decoration: none;
opacity:1;
}
h5 {
font-family: Helvetica Neue;
font-size: 5em;
color: #FFFFFF;
padding-bottom:0;
margin-bottom:-30px;
}
h6 {
padding-top: 0;
}
<div class="griditem" style="background-image:url(https://upload.wikimedia.org/wikipedia/commons/8/80/Aspect_ratio_-_16x9.svg); background-size:100% 100%;">
<img src="http://i.imgur.com/JnW9SPx.png" width="100%" alt="Spacer 16x9" />
<div class="overlay">
<a href="http://www.google.com" class="titles">
<p>BIG TEXT<br>
small Title<p>
</a>
</div>
</div>
You could easily solve this by using a bit of jquery like so. Demo can be found here.
var pheight = $(".griditem").height();
$(".titles p").css("height", pheight);
$(window).resize(function () {
var pheight = $(".griditem").height();
$(".titles p").css("height", pheight);
});

Div hover function resize css

I've created a div that contains a box, within that box is text and a link. What I want is when a person hovers over this box with the link, a red line appears on the bottom of the box. At the moment I've managed this but I want the red line to be the width of the grey box and only 5 pixels in height.
#teamspeak_box {
width: 159px;
height: 43px;
background: #212121;
bottom: 82px;
right: 76px;
position: absolute;
border-radius: 0px 0px 5px 5px;
}
#teamspeak_box_2 {
width: 43px;
height: 43px;
background: #313131;
bottom: 82px;
right: 191px;
position: absolute;
border-radius: 0px 0px 0px 5px;
}
#teamspeak_text {
color: white;
bottom: 93px;
right: 66px;
position: absolute;
}
#teamspeak_image {
bottom: 80px;
right: 104px;
position: absolute;
}
#teamspeak_image a:hover {
background-color: #C62828;
transition: all 0.5s ease;
}
<div id="teamspeak_box"></div>
<div id="teamspeak_box_2">
</div>
<div id="teamspeak_text">
<p>TEAMSPEAK
<P/>
</div>
<div id="teamspeak_image">
<a href="ts3server://craft412.serveminecraft.net:9987">
<img src="images/CRAFT412 - Box - Teamspeak.png" alt="TEAMSPEAK">
</a>
</div>
I find your element positioning insane. Try this one
HTML
<a href="ts3server://craft412.serveminecraft.net:9987">
<div class="teamspeak-box">
<div class="teamspeak-icon">
<img src="http://filepic.ru/file/1436899103.png" alt="">
</div>
<p>TEAMSPEAK</p>
</div>
</a>
CSS
.teamspeak-box{
width: 159px;
height: 43px;
background: #212121;
border-radius: 0px 0px 5px 5px;
overflow: hidden;
color: white;
display: table;
}
.teamspeak-icon{
width: 43px;
height: 43px;
background: #313131;
display: table-cell;
transition: all 0.5s ease;
}
.teamspeak-icon img{
width: 100%;
}
.teamspeak-box p{
display: table-cell;
text-align: center;
vertical-align: middle;
}
.teamspeak-box:hover .teamspeak-icon{
-webkit-box-shadow: inset 0px -5px 0px 0px rgba(255,0,0,1);
-moz-box-shadow: inset 0px -5px 0px 0px rgba(255,0,0,1);
box-shadow: inset 0px -5px 0px 0px rgba(255,0,0,1);
}
Run this code on JSFiddle
Basically you want to change the styling on one element while hovering another. This can be done the following way:
#teamspeak_image a:hover ~ #teamspeak_box {
background-color: #C62828;
transition: all 0.5s ease;
}
See this answer for more info. And you might consider adding a border-bottom: 5px solid red; to the box instead of background-color.
In order for the red line to be the width of the grey box and 5px tall,
use the css property to set the display of the grey box to block. Thus, for the grey box use:
display:block;
height:5px;
After that you can set other css properties for the links inside the grey box.

Body text goes over the top of fixed nav bar

I have a fixed nav bar, that follows when scrolling.
But upon scrolling over text/images within tags it seems to go in front of the navbar, rather then behind.
Why is this? How can I fix it?
Fiddle
nav {
background-color: #262626;
height: 60px;
width: 100%;
position: fixed;
top: 0;
bottom: 0;
-webkit-box-shadow: 0px 0px 8px 0px #000000;
-moz-box-shadow: 0px 0px 8px 0px #000000;
box-shadow: 0px 0px 8px 0px #000000;
}
nav a {
font-family: 'Open Sans', sans-serif;
font-size: 16px;
line-height: 60px;
text-transform: uppercase;
margin: 7px;
}
nav a:link {
color: #C8C8C8;
-o-transition: .5s;
-ms-transition: .5s;
-moz-transition: .5s;
-webkit-transition: .5s;
transition: .5s;
}
nav a:visited {
color: #C8C8C8;
}
nav a:hover {
color: #199ABA;
}
#menu {
margin-right: 375px;
margin-left: 375px;
text-align: right;
margin-top: 0px;
margin-bottom: 0px;
}
#headertop {
margin: 0px;
width: 100%;
height: 650px;
font-family: 'Open Sans', sans-serif;
}
#headertop h1 {
position: absolute;
margin-left: 375px;
margin-right: 375px;
margin-top: 178px;
line-height: 45px;
font-size: 50px;
color: #33CCFF;
width: 550px;
height: 100%;
}
<nav>
<div id="menu">
<strong>Home</strong>
</div>
</nav>
<div id="headertop">
<h1>THANKS</h1>
</div>
This is usually caused by your z-index, make sure you put:
CSS
z-index: 500 // or whatever number that is a positive real number.
Yep, I was right, see this DEMO.
nav {
background-color: #262626;
height: 60px;
z-index:1; //any higher integer value
width: 100%;
position: fixed;
top: 0;
bottom: 0;
-webkit-box-shadow: 0px 0px 8px 0px #000000;
-moz-box-shadow: 0px 0px 8px 0px #000000;
box-shadow: 0px 0px 8px 0px #000000;
}
Refer z-index in W3Schools
also Refer CSS-Tricks
If anything is overflowing the nav or any div, try using z-index.