I have the following HTML (Fiddle Example):
<header>
<div class="wrapper">
<em class="brand">
<img src="http://via.placeholder.com/200x40?text=LOGO"/>
</em>
<nav class="menu">
<ul class="menu">
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</div>
<div class="slides">
<div class="slide">
<div class="frame">
<img src="http://via.placeholder.com/1200x400?text=Image to Crop" />
</div>
<div class="text">
<h2>Our Message</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</div>
</div>
</header>
<main>
Main content
</main>
And correspondent CSS:
header {
text-align: center;
}
div.wrapper {
margin: 0 auto;
max-width: 640px;
text-align: left;
position: relative;
}
em.brand img {
display: block;
}
ul.menu {
list-style: none;
margin: 0;
padding: 0;
}
ul.menu li {
display: inline-block;
margin: 0;
padding: 8px;
}
ul.menu li a {
text-decoration: none;
font-size: 18px;
color: white;
}
em {
border: 1px solid red;
position: absolute;
z-index: 2000;
}
nav {
position: absolute;
z-index: 2000;
right: 0;
}
.slides {
width: 100%;
position: relative;
}
.slide .frame img {
width: 100%;
margin: 0 -100px;
}
.slide .text {
position: absolute;
text-align: center;
top: 80px;
width: 100%;
}
.slide .text h2 {
color: white;
font-size: 40px;
margin: 8px;
}
.slide .text p {
color: white;
font-size: 20px;
margin: 8px;
}
main {
border: 1px solid red;
font-size: 20px;
}
Using media queries I need, sometimes, to adjust the image by cropping it on Left/Right or on Bottom/Top:
.slide .frame img {
width: 100%;
margin: 0 -100px;
}
This does not change the image. It only changes it if I try Top/Bottom:
.slide .frame img {
width: 100%;
margin: -100px 0;
}
Any idea why?
You have to set up the negative margins to the image's container, and set the image width: 100%
.slides {
width: 100%;
position: relative;
overflow: hidden; // so the "negative" part is not visible
}
.slide .frame {
margin: 0 -100px;
}
.slide .frame img {
width: 100%;
}
But maybe you should the image as a background and use the property background-size: cover; and background-position: center;
Related
I am currently having an issue where my navigation bar and banner shrink when I set their position to fixed.I have many things like changing z-index,setting its top position to 0,adding auto margin etc, and none of it worked.I hope someone can point me to my mistake.This is my html code:
html,
body {
margin: 0;
background-color: #ffeecc;
font-family: 'Chivo', sans-serif;
}
.container {
margin: auto;
width: 75%;
}
.nav_left {
width: 100%;
background-color: #258e25;
height: 50px;
float: left;
text-align: left;
}
.banner {
width: 100%;
overflow: hidden;
background-color: white;
}
.banner img {
width: 70%;
height: 150px;
padding: 0 15%;
}
.top {
position: fixed;
}
nav {
text-align: center;
}
nav ul {
list-style-type: none;
padding: 0;
margin: 0;
display: inline-block;
width: 100%;
height: 100%;
}
nav ul li {
float: left;
text-align: center;
height: 100%;
width: 25%;
}
nav ul li a {
display: inline-block;
width: 100%;
font-weight: bold;
line-height: 50px;
text-decoration: none;
color: white;
}
nav ul li a:hover {
background-color: white;
color: black;
}
<div class="container">
<div class="top">
<div class="banner">
<img src="images/winwin-logo-cover.jpg" alt="winwin logo">
</div>
<nav>
<div class="nav_left">
<ul>
<li>PROIZVODI</li>
<li>O NAMA</li>
<li>KONTAKT</li>
</ul>
</div>
<div class="nav_right"></div>
</nav>
</div>
this is how it should look like
this is how it looks like when i put .top{position:fixed}
When you set an element to absolute or fixed position, it will be out of the the normal content flow and trigger the shrink to fit feature. You can apply the offsets and width/height to position and recreate the box size you wish to have.
.top {
position: fixed;
left: 0; /* ADDED */
top: 0; /* ADDED */
width: 100%; /* ADDED */
}
html,
body {
margin: 0;
background-color: #ffeecc;
font-family: 'Chivo', sans-serif;
}
.container {
margin: auto;
width: 75%;
}
.nav_left {
width: 100%;
background-color: #258e25;
height: 50px;
float: left;
text-align: left;
}
.banner {
width: 100%;
overflow: hidden;
background-color: white;
}
.banner img {
width: 70%;
height: 150px;
padding: 0 15%;
}
.top {
position: fixed;
left: 0;
top: 0;
width: 100%;
}
nav {
text-align: center;
}
nav ul {
list-style-type: none;
padding: 0;
margin: 0;
display: inline-block;
width: 100%;
height: 100%;
}
nav ul li {
float: left;
text-align: center;
height: 100%;
width: 25%;
}
nav ul li a {
display: inline-block;
width: 100%;
font-weight: bold;
line-height: 50px;
text-decoration: none;
color: white;
}
nav ul li a:hover {
background-color: white;
color: black;
}
<div class="container">
<div class="top">
<div class="banner">
<img src="images/winwin-logo-cover.jpg" alt="winwin logo">
</div>
<nav>
<div class="nav_left">
<ul>
<li>PROIZVODI</li>
<li>O NAMA</li>
<li>KONTAKT</li>
</ul>
</div>
<div class="nav_right"></div>
</nav>
</div>
Because .top has no width. However, when set to fixed it is using the viewport width to calculate the width. You might want to set it to 75%.
You also might want to set .container to position: relative so .top will relate to its borders.
body {
margin: 0;
background-color: #ffeecc;
font-family: 'Chivo', sans-serif;
}
.container {
margin: auto;
width: 75%;
position: relative;
}
.top {
position: fixed;
width: 75%;
}
.nav_left {
width: 100%;
background-color: #258e25;
height: 50px;
float: left;
text-align: left;
}
nav {
text-align: center;
}
nav ul {
list-style-type: none;
padding: 0;
margin: 0;
display: inline-block;
width: 100%;
height: 100%;
}
nav ul li {
float: left;
text-align: center;
height: 100%;
width: 25%;
}
nav ul li a {
display: inline-block;
width: 100%;
font-weight: bold;
line-height: 50px;
text-decoration: none;
color: white;
}
nav ul li a:hover {
background-color: white;
color: black;
}
<div class="container">
<div class="top">
<nav>
<div class="nav_left">
<ul>
<li>PROIZVODI</li>
<li>O NAMA</li>
<li>KONTAKT</li>
</ul>
</div>
<div class="nav_right"></div>
</nav>
</div>
i would like to have my logo centred to the four images. How do i do this? i would like the four images to fill the window and the logo to centre to them. I also don't want to stretch the images but would consider resizing them if needs be
.header {
background-color: black;
border-bottom: 1px solid #466995;
overflow-y: auto;
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 10;
}
ul {
margin: 30px auto;
text-align: center;
}
li {
color: #FFF;
display: inline-block;
font-family: 'Oswald', sans-serif;
font-size: 16px;
text-align: left;
font-weight: 300;
text-transform: uppercase;
padding: 0 100px;
}
li:hover {
color: #DBE9EE;
}
body {
margin: 0;
}
img {
max-width: 100%;
height: auto;
}
#container {
max-width: 100%;
z-index: -100;
margin: 0;
padding: 0;
}
.containermenu {
}
.containermenu img{
width: 50%;
height: 50%;
float: left;
}
#logo {
width: 20%;
margin: 0 auto;
position: absolute;
z-index: 20;
left: 40%;
right: 40%;
}
#process img {
width: 100%;
}
#process {
width: 100%;
}
<div id="container">
<div id="logo"><img src="http://oi68.tinypic.com/2njh9id.jpg"></div>
<div class="containermenu"><img src="http://oi67.tinypic.com/vgmv80.jpg"></div>
<div class="containermenu"><img src="http://oi67.tinypic.com/vgmv80.jpg"></div>
<div class="containermenu"><img src="http://oi67.tinypic.com/vgmv80.jpg"></div>
<div class="containermenu"><img src="http://oi67.tinypic.com/vgmv80.jpg"></div>
</div>
Codepen link
To center an item perfectly in the page use the following CSS
position: absolute;
left: 50%;
top: 50%;
transform: translateX(-50%) translateY(-50%);
EDIT: Updated Codepen
Use transform to center in css More infor here
.header {
background-color: black;
border-bottom: 1px solid #466995;
overflow-y: auto;
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 10;
}
ul {
margin: 30px auto;
text-align: center;
}
li {
color: #FFF;
display: inline-block;
font-family: 'Oswald', sans-serif;
font-size: 16px;
text-align: left;
font-weight: 300;
text-transform: uppercase;
padding: 0 100px;
}
li:hover {
color: #DBE9EE;
}
body {
margin: 0;
}
img {
max-width: 100%;
height: auto;
}
#container {
max-width: 100%;
z-index: -100;
margin: 0;
padding: 0;
}
.containermenu {} .containermenu img {
width: 50%;
height: 50%;
float: left;
}
#logo {
width: 20%;
position: absolute; /*fixed*/
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
#process img {
width: 100%;
}
#process {
width: 100%;
}
<div id="container">
<div id="logo">
<a href="index.html">
<img src="http://oi68.tinypic.com/2njh9id.jpg">
</a>
</div>
<div class="containermenu">
<a href="packaging.html">
<img src="http://oi67.tinypic.com/vgmv80.jpg">
</a>
</div>
<div class="containermenu">
<a href="photography.html">
<img src="http://oi67.tinypic.com/vgmv80.jpg">
</a>
</div>
<div class="containermenu">
<a href="illustration.html">
<img src="http://oi67.tinypic.com/vgmv80.jpg">
</a>
</div>
<div class="containermenu">
<a href="about.html">
<img src="http://oi67.tinypic.com/vgmv80.jpg">
</a>
</div>
</div>
I'm trying to make a caption appear whenever I hover on the image. I want the height of the image to be set to 200px, but the width to be auto. How can I make the span with the caption also correspond to the image width? Thanks!
HTML:
<div class="projects">
<a name="folder"></a>
<h1 class="heading">Projects</h1>
<p class="classProjectsInfo">Recent class projects</p>
<div class="classProjects">
<ul class="img-list">
<li>
<img src="checkers_cover.JPG">
<span class="description2"><span>Checkers61B</span></span>
</li>
<li>
<img src="cover_ngram.JPG">
<span class="description2"><span>NGramMap</span></span>
</li>
<li>
<img src="gitlet_cover.JPG">
<span class="description2"><span>Gitlet</span></span>
</li>
</ul>
</div>
</div>
CSS:
.classProjects {
text-align: center;
margin: 0;
padding: 0;
list-style-type: none;
}
.classProjects li {
display: inline-block;
padding: 5px;
margin: 10px;
position: relative;
height: 250px;
width: auto;
}
.classProjects img {
height: 250px;
width: auto;
}
ul.img-list {
list-style-type: none;
margin: 0;
padding: 0;
text-align: center;
}
ul.img-list li {
display: inline-block;
height: 250px;
position: relative;
width: auto;
}
span.description2 {
background: rgba(0,0,0,0.5);
color: white;
cursor: pointer;
display: table;
height: 250px;
left: 0;
position: absolute;
top: 0;
width: auto;
}
span.description2 span {
display: table-cell;
text-align: center;
vertical-align: middle;
}
span.description2 {
background: rgba(0,0,0,0.5);
color: white;
cursor: pointer;
display: table;
height: 250px;
left: 0;
position: absolute;
top: 0;
width: auto;
opacity: 0;
}
ul.img-list li:hover span.description2 {
opacity: 1;
}
I’m creating this website and I made this nav bar. It had dummy links in the anchor tags and I had a hover property on my buttons. All of this was working properly. I had made a few changes to the code and now none of it works. I cannot figure out where I went wrong. I was editing properties and things just stopped working.
* {
margin: 0 auto;
height: 100%;
width: 100%;
margin: 0;
padding: 0;
font-family: "Arial";
color: white;
}
html,
body {
margin: 0 auto;
background-color: black;
max-width: 940px;
min-height: 100%;
}
.wrapper {
margin: 0 auto;
width: 92%;
background-image: url("images/backgrounds/wood.jpg");
}
/*********************************************************************************************************************************************
HEADER STYLING
*********************************************************************************************************************************************/
.header {
position: relative;
height: 100px;
background-color: #111111;
}
.header h1 {
position: relative;
margin: 0;
height: 20px;
text-align: center;
font-size: 2.3em;
top: 25%;
}
.header p {
position: relative;
top: 25%;
width: 100%;
font-size: 1em;
text-align: center;
}
/*********************************************************************************************************************************************
NAVIGATION BAR STYLING
*********************************************************************************************************************************************/
nav {
height: 40px;
}
nav ul {}
nav ul li {
background-color: #111111;
text-align: center;
list-style-type: none;
width: 25%;
float: left;
/*margin: 0 1%;
border-radius: 10px;
box-shadow: 5px 5px 5px #000;*/
}
nav ul li a {
text-decoration: none;
line-height: 40px;
display: block;
}
nav ul li a:hover {
background-color: #222222;
}
/*********************************************************************************************************************************************
JUMBOTRON STYLING
*********************************************************************************************************************************************/
.jumbotron {
position: relative;
background-image: url(images/jumbotron/studiopic.jpg);
background-repeat: no-repeat;
background-size: cover;
width: 100%;
max-height: 53%;
}
.jumbotext h1 {
display: inline-block;
position: absolute;
bottom: 0px;
text-align: right;
}
/*********************************************************************************************************************************************
FOOTER STYLING
*********************************************************************************************************************************************/
.footer {
height: 100px;
width: 100%;
background-color: #111111;
}
<!DOCTYPE html>
<html>
<head>
<title>CM Sound | Home</title>
<meta charset="UTF-8">
<meta name="description" content="CM Sound's studio webpage">
<meta name="author" content="Ryan Buck | May 2015">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="wrapper">
<div class="header">
<h1>CM Sound</h1><br/>
<p>Create with us</p>
</div>
<nav>
<ul>
<li>Home</li>
<li>Audio</li>
<li>Pricing</li>
<li>Contact</li>
</ul>
</nav>
<div class="jumbotron">
<div class="jumbotext">
</div>
</div>
<div class="footer">
</div>
</div>
</body>
</html>
Add this in nav ul li a
:
position: relative;
* {
margin: 0 auto;
height: 100%;
width: 100%;
margin: 0;
padding: 0;
font-family: "Arial";
color: white;
}
html, body {
margin: 0 auto;
background-color: black;
max-width: 940px;
min-height: 100%;
}
.wrapper {
margin: 0 auto;
width: 92%;
background-image: url("images/backgrounds/wood.jpg");
}
/*********************************************************************************************************************************************
HEADER STYLING
*********************************************************************************************************************************************/
.header {
position: relative;
height: 100px;
background-color: #111111;
}
.header h1 {
position: relative;
margin: 0;
height: 20px;
text-align: center;
font-size: 2.3em;
top: 25%;
}
.header p {
position: relative;
top: 25%;
width: 100%;
font-size: 1em;
text-align: center;
}
/*********************************************************************************************************************************************
NAVIGATION BAR STYLING
*********************************************************************************************************************************************/
nav {
height: 40px;
}
nav ul {
}
nav ul li {
background-color: #111111;
text-align: center;
list-style-type: none;
width: 25%;
float: left;
/*margin: 0 1%;
border-radius: 10px;
box-shadow: 5px 5px 5px #000;*/
}
nav ul li a {
text-decoration: none;
line-height: 40px;
display: block;
position: relative;
}
nav ul li a:hover {
background-color: #222222;
}
/*********************************************************************************************************************************************
JUMBOTRON STYLING
*********************************************************************************************************************************************/
.jumbotron {
position: relative;
background-image: url(images/jumbotron/studiopic.jpg);
background-repeat: no-repeat;
background-size: cover;
width: 100%;
max-height: 53%;
}
.jumbotext h1 {
display: inline-block;
position: absolute;
bottom: 0px;
text-align: right;
}
/*********************************************************************************************************************************************
FOOTER STYLING
*********************************************************************************************************************************************/
.footer {
height: 100px;
width: 100%;
background-color: #111111;
}
<div class="wrapper">
<div class="header">
<h1>CM Sound</h1><br/>
<p>Create with us</p>
</div>
<nav>
<ul>
<li>Home</li>
<li>Audio</li>
<li>Pricing</li>
<li>Contact</li>
</ul>
</nav>
<div class="jumbotron">
<div class="jumbotext">
</div>
</div>
<div class="footer">
</div>
</div>
nav {
height: 40px;
position: relative;
}
just add the position relative to nav
I have the following: http://jsfiddle.net/5mbK8/2/
The text Link is supposed to function as a link, but it doesn't work because .container .image has a z-index of -1. If I remove the z-index, it works, but then the image isn't behind the yellow shadow.
How can I make the text clickable while keeping the background image behind the yellow box shadow?
HTML:
<div class="container">
<div class="side"></div>
<div class="image" style="background: url('http://i.imgur.com/T0VWLqZ.png');">
<div class="menu">
<ul>
<li><a href="#">Link</li>
</ul>
</div>
</div>
</div>
CSS:
a {
color: black;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.container {
width: 900px;
height: 300px;
}
.container .image {
width: 598px;
height: 300px;
float: right;
position: relative;
z-index: -1;
}
.container .side {
float: left;
width: 302px;
height: 300px;
background: red;
box-shadow: 5px 0 5px -5px yellow;
}
.container .image .menu {
position: absolute;
bottom: 0;
left: -25px;
}
.container .image .menu ul {
list-style: none;
margin: 0;
}
.container .image .menu ul li {
display: inline-block;
text-align: center;
padding: 10px;
background: white;
}
Check out this fiddle: http://jsfiddle.net/5mbK8/5/
A solution would be to position the menu outside the .image div.
And of course you will have to adapt the left: 300px; depending on what width the .side will have.
EDIT (added code):
<div class="container">
<div class="side"></div>
<div class="image" style="background: url('http://i.imgur.com/T0VWLqZ.png');"> </div>
<div class="menu">
<ul>
<li>Link</li>
</ul>
</div>
</div>
CSS:
a {
color: black;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.container {
position: relative;
width: 900px;
height: 300px;
}
.container .image {
width: 598px;
height: 300px;
float: right;
position: relative;
z-index: -1;
}
.container .side {
float: left;
width: 302px;
height: 300px;
background: red;
box-shadow: 5px 0 5px -5px yellow;
}
.container .menu {
position: absolute;
bottom: 0;
left: 300px;
}
.container .menu ul {
list-style: none;
margin: 0;
}
.container .menu ul li {
display: inline-block;
text-align: center;
padding: 10px;
background: white;
}