I have the following HTML and CS(Fiddle Example):
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%;
}
.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;
}
<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://lorempixel.com/1200/675/nature/1" />
</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>
The logo and menu are on left and right both on top of image.
Message and caption and centered on top of image ...
So far so good. But in some screen sizes I need to crop the image.
I do it placing the image in a DIV with negative margins (Fiddle Example):
<div class="frame">
<img src="http://lorempixel.com/1200/675/nature/1" />
</div>
.slide .frame {
margin: -20px 0;
}
The problem is, as you can see in the online example, the logo, main content and menu are moved ...
Is there a way to solve this?
You can include the image in CSS using the
background-image:url('...')
property. Then you can crop it with the
background-size: 999px ... ;
attribute.
If I think better of your problem you have to set the margin .slide .frame img or you can use this image within CSS background-image:url('...')
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 {
margin: -20px 0;
width: 100%;
}
.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;
position: relative;
top: 20px;
}
<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://lorempixel.com/1200/675/nature/1" />
</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>
if you to crop the image of 20px top and bottom, apply the negative margins to it and hide overflow from its parent : http://jsfiddle.net/hxdhv147/6/
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 {overflow:hidden}
.slide .frame img {
width: 100%;
margin: -20px 0;
}
.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;
}
<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://lorempixel.com/1200/675/nature/1" />
</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>
note that CSS
use to have the clip(); rules to crop content.
but now i would advise object-fit about image
Related
I have tried this. But it doesn't work. I don't know why it makes the parent div appear like that. I want the divisionContainer to contain them. But it doesn't appear like that.
* {
box-sizing: border-box;
}
body {
font-family: arial;
}
.mainContainer {
border: 1px solid #000;
width: 65%;
}
.header {
width: 100%;
height: 85px;
background: #19578c;
}
.header .container {
padding: 5px;
float: right;
}
.header .headerTitle {
color: #4e94d0;
;
font-family: monospace;
margin: 0;
font-size: 300%;
}
.header .navBar li {
display: inline;
padding: 5px;
}
/* here's the problem */
.divisionContainer {
border: 1px solid #000;
margin-top: 2px;
}
.sidebarContainer {
width: 30%;
float: left;
}
.contentContainer {
width: 70%;
float: right;
}
/* here's the problem */
.navBar {
list-style: none;
padding: 0;
margin: 5px 0 0 0;
color: white;
}
<html>
<head>
<title>thepoopstation</title>
</head>
<body>
<div class="mainContainer">
<div class="header">
<div class="container">
<h1 class="headerTitle">[thepoopstation]</h1>
<ul class="navBar">
<li>home</li>
<li>search</li>
<li>global</li>
</ul>
</div>
</div>
<div class="divisionContainer">
<div class="sidebarContainer">
<div class="container">
<ul class="navBar">
<li>my profile</li>
<li>my friends</li>
</ul>
</div>
</div>
<div class="contentContainer">
<div class="container">
<div class="containerHeading">about thepoopstation</div>
<div>
</div>
</div>
</div>
</body>
</html>
It appears as if the parent divisionContainer is not containing them at all. I wanna fix it.
It because how float works...floated elements are out of flow..so you will need to put a in-flow elements below that div to enforce the parent div to take all the inner element space using :after pseudo element
Stack Snippet
* {
box-sizing: border-box;
}
body {
font-family: arial;
}
.mainContainer {
border: 1px solid #000;
width: 65%;
}
.header {
width: 100%;
height: 85px;
background: #19578c;
}
.header .container {
padding: 5px;
float: right;
}
.header .headerTitle {
color: #4e94d0;
;
font-family: monospace;
margin: 0;
font-size: 300%;
}
.header .navBar li {
display: inline;
padding: 5px;
}
/* here's the problem */
.divisionContainer {
border: 1px solid #000;
margin-top: 2px;
}
.sidebarContainer {
width: 30%;
float: left;
}
.contentContainer {
width: 70%;
float: right;
}
/* here's the problem */
.navBar {
list-style: none;
padding: 0;
margin: 5px 0 0 0;
color: white;
}
.divisionContainer:after {
content: "";
display: table;
clear: both;
}
<div class="mainContainer">
<div class="header">
<div class="container">
<h1 class="headerTitle">[thepoopstation]</h1>
<ul class="navBar">
<li>home</li>
<li>search</li>
<li>global</li>
</ul>
</div>
</div>
<div class="divisionContainer">
<div class="sidebarContainer">
<div class="container">
<ul class="navBar">
<li>my profile</li>
<li>my friends</li>
</ul>
</div>
</div>
<div class="contentContainer">
<div class="container">
<div class="containerHeading">about thepoopstation</div>
<div>
</div>
</div>
</div>
</div>
</div>
Please help, I need the white space on the right bar gone and the position of the main content placed at the middle of the page.
What should I do? Any suggestion?
This is my site : http://www.plebonline.co.uk
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 16px 18px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #111;
}
.active {
background-color: #ea730b;
}
.clock {
color: white;
text-align: center;
padding: 16px 18px;
display: block;
}
.leftbar {
float: left;
background-color: #333;
width: 10%;
margin: 0;
padding: 1em;
margin-bottom: -5000px;
padding-bottom: 5000px;
overflow: hidden;
}
.rightbar {
float: right;
background-color: #333;
width: 10%;
margin: 0;
padding: 1em;
margin-bottom: -5000px;
padding-bottom: 5000px;
overflow: hidden;
}
.maincontent {
padding: 0;
float:left;
margin-left: 10%;
margin-right: 10%;
background-color: #ff00ff;
width: 80%;
}
<ul>
<li><a class="active" href="index.html">Home</a></li>
<li>Projects</li>
<li>Notes</li>
<li>About</li>
<li>Contact</li>
<li style="float:right" class="clock" id="clock"></li>
<script>
var today = new Date();
document.getElementById('clock').innerHTML=today;
</script>
</ul>
<div class="leftbar"></div>
<div class="maincontent"></div>
<div class="rightbar"></div>
There is a div tag close without opening that may be causing the problem.
Change:
<div class="leftbar"></div>
<div class="maincontent"></div>
</div>
<div class="rightbar"></div>
To:
<div class="leftbar"></div>
<div class="maincontent"></div>
<div class="rightbar"></div>
I notice that you didn't put your rightbar and leftbar in any div. In my code here, I remove the right and left bar. You can adjust the code if you want them back.
It's better to add some container to hold all of your element. As you notice the header and the maincontent is inside the div class .container.
Hope this help.
html,body {
margin:0;
padding:0;
height: 100%;
/*
* The container which hold the header and the main content
*/
.container {
width:100%;
position: absolute;
height:1200px;
background:#333;
}
/*
* Header which contain your menu and date
*/
.header {
width:100%;
}
/*
* The main content of your site
*/
.maincontent {
width:80%;
max-width:1000px;
background-color: #fff;
float:left;
left:50%;
height:100%;
margin-left:-500px;
position: absolute;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 16px 18px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #111;
}
.active {
background-color: #ea730b;
}
.clock {
color: white;
text-align: center;
padding: 16px 18px;
display: block;
}
</style>
<body>
<div class="container">
<div class="header">
<ul>
<li><a class="active" href="index.html">Home</a></li>
<li>Projects</li>
<li>Notes</li>
<li>About</li>
<li>Contact</li>
<li style="float:right" class="clock" id="clock"></li>
<script>
var today = new Date();
document.getElementById('clock').innerHTML=today;
</script>
</ul>
</div>
<div class="container">
<div class="maincontent">
<h1>This is the content</h1>
</div>
</div>
</body>
i build a basic sidebar, with an navigation list inside. What i'm trying is to get the last div container .sidebar-footer on the bottom of the sidebar. When i gave the class a position absolute, it's overlaying over the list item, what should i do to get it like in our design pic?
<div class="pulse-menu">
<div class="menu-bg clearfix">
<div class="sidebar-profile">
<img src="img/users/avatar.jpg" class="sidebar-img" alt="Candice Swanepoel" title="Candice Swanepoel" />
<h5>Candice Swanepoel</h5>
</div>
</div>
<nav>
<ul>
<li>Dashboard</li>
<li>Models</li>
<li>Kunden</li>
<li>Finanzen</li>
<li>Mitarbeiter</li>
<li>Einstellung</li>
</ul>
<div class="sidebar-footer">
<li><i class="icon-cloud-upload circle-icon"> </i></li>
</div>
</nav>
</div>
Css:
.pulse-menu {
background-color: #fafafa;
width: 19.286em;
position: fixed;
z-index: 1050;
top: 0;
bottom: 0;
height: 100%;
text-transform: uppercase;
overflow-y: scroll;
}
.menu-bg {
width: 270px;
height: 230px;
background: url(../img/media/menu_bg.svg) ;
background-size: 270px 221px;
background-repeat: no-repeat;
}
.sidebar-profile {
margin: 0 auto;
width: 100%;
text-align: center;
box-sizing: border-box;
padding: 20px 0;
color: #333;
line-height: 0.6em;
}
.sidebar-profile img {
border-radius: 100%;
height: 60px;
width:60px;
}
.sidebar-profile h5 {
padding-top: 0.50em;
color: #a8a8a8;
font-size: 1.02em;
}
.pulse-menu>nav ul {
padding: 0;
list-style-type: none;
}
.pulse-menu>nav>ul>li>a {
color:#333;
display:block;
font-size:1.02em;
height:40px;
line-height:0px;
padding-bottom:1.5em;
padding-left:2em;
padding-right:2em;
padding-top:1.5em;
text-align:center;
}
here is a working jsfiddle with my code
Give your footer class this styles
.sidebar-footer{
height: 50px;
position: absolute;
width: 100%;
bottom: 0;
list-style-type: none;
padding-bottom:5.5em;
}
You can use the :last-child selector in your CSS.
HTML:
<nav>
<ul>
<li>Dashboard</li>
<li>Models</li>
<li>Kunden</li>
<li>Finanzen</li>
<li>Mitarbeiter</li>
<li>Einstellung</li>
</ul>
<div class="sidebar-footer">
<li><i class="icon-cloud-upload circle-icon"> </i></li>
</div>
</nav>
CSS
.nav ul li:last-child {
//your styling
}
CSS
<style>
.pulse-menu {
background-color: #fafafa;
width: 19.286em;
position: fixed;
z-index: 1050;
top: 0;
bottom: 0;
height: 100%;
text-transform: uppercase;
overflow-y: scroll;
}
.menu-bg {
width: 270px;
height: 230px;
background: url(../img/media/menu_bg.svg) ;
background-size: 270px 221px;
background-repeat: no-repeat;
}
.sidebar-profile {
margin: 0 auto;
width: 100%;
text-align: center;
box-sizing: border-box;
padding: 20px 0;
color: #333;
line-height: 0.6em;
}
.sidebar-profile img {
border-radius: 100%;
height: 60px;
width:60px;
}
.sidebar-profile h5 {
padding-top: 0.50em;
color: #a8a8a8;
font-size: 1.02em;
}
.pulse-menu>nav ul {
padding: 0;
list-style-type: none;
}
.pulse-menu>nav>ul>li>a {
color:#333;
display:block;
font-size:1.02em;
height:40px;
line-height:0px;
padding-bottom:1.5em;
padding-left:2em;
padding-right:2em;
padding-top:1.5em;
text-align:center;
}
.specialelement {
padding-top: 500px;
display:block;
padding-left:6em;
list-style-type: none;
color: #333;
}
</style>
HTML
<div class="pulse-menu">
<div class="menu-bg clearfix">
<div class="sidebar-profile">
<img src="img/users/avatar.jpg" class="sidebar-img" alt="Candice Swanepoel" title="Candice Swanepoel" />
<h5>Candice Swanepoel</h5>
</div>
</div>
<nav>
<ul>
<li>Dashboard</li>
<li>Models</li>
<li>Kunden</li>
<li>Finanzen</li>
<li>Mitarbeiter</li>
<li class="specialelement">
<li>Einstellung</li>
</li>
<div class="sidebar-footer">
<li><i class="icon-cloud-upload circle-icon"> </i></li>
</div>
</nav>
</div>
Result
I'm trying to have a full screen header and at the bottom of that (but within it) have a link which says learn more. Then below the header have the rest of the website content, in this case "test".
The two issues I have is:
Learn more should sit at the bottom middle but it doens't, it sits slightly to the right
The div class "content" is sat within the gray box not under it.
This is the code I am working with:
* {
padding: 0;
margin: 0;
}
html, body {
height: 100%;
}
a {
text-decoration: none;
}
.header {
height: 100%;
width: 100%;
background: lightgray;
text-align: center;
min-height: 350px;
position: relative;
}
li {
list-style: none;
}
.nav {
display: block;
padding: 20px;
}
.nav img {
float: left;
}
.nav ul {
float: right;
font-size: 0;
}
.nav ul li {
display: inline-block;
font-size: 16px;
padding-left: 10px;
}
.nav ul li:first-child {
padding-left: 0px
}
.nav ul li a {
padding: 0 10px;
}
.learn {position: absolute; bottom: 0; width: 200px;}
.content {background-color: blue; display: block;}
<html>
<body>
<div class="header">
<div class="nav">
<img width="39" height="35" alt="" src="#">
<ul>
<li>Services
</li>
<li>Writings
</li>
<li>Contact
</li>
</ul>
</div>
<span class="billboard">Hello!</span>
<a class="learn">Learn More</span>
</div>
<div class="content">Test</div>
</body>
</html>
You have an unclosed anchor tag. And you need to set left: 50%; width: auto; to your .learn class in order to center it.
* {
padding: 0;
margin: 0;
}
html, body {
height: 100%;
}
a {
text-decoration: none;
}
.header {
height: 100%;
width: 100%;
background: lightgray;
text-align: center;
min-height: 350px;
position: relative;
}
li {
list-style: none;
}
.nav {
display: block;
padding: 20px;
}
.nav img {
float: left;
}
.nav ul {
float: right;
font-size: 0;
}
.nav ul li {
display: inline-block;
font-size: 16px;
padding-left: 10px;
}
.nav ul li:first-child {
padding-left: 0px
}
.nav ul li a {
padding: 0 10px;
}
.learn {position: absolute; bottom: 0; width: auto; left: 50%;}
.content {background-color: blue; display: block;}
<html>
<body>
<div class="header">
<div class="nav">
<img width="39" height="35" alt="" src="#">
<ul>
<li>Services
</li>
<li>Writings
</li>
<li>Contact
</li>
</ul>
</div>
<span class="billboard">Hello!</span>
<a class="learn">Learn More</span></a>
</div>
<div class="content">Test</div>
</body>
</html>
To center align 'Learn more', use
.learn {
position: absolute; bottom: 0; width: 200px;
left: 50%; transform: translateX(-50%);
}
Before the content, <a class="learn">Learn More</span> closing tag should be </a>
https://jsfiddle.net/afelixj/efty6zjL/
I am new to CSS and have been trying to build a 2-column website. The code is here: JSFiddle. There is a left-side menu with a right-side content area. If the window is large enough, there is no problem with the layout. However, when resizing the window to a narrow one, the content overflows to the menu area and I don't know how to fix it without making the position fixed or absolute, which I don't want to do because I want to have a footer at the end of the page. Can someone help me fix the problem? Thank you so much!
I also apologize in advance for the long code. I don't know which part lies the problem and pasted everything
html code:
<body>
<div id="wrapper">
<div id="menunav">
<img src="images/logo.jpg" alt="siteLogo" class="centered" id="logo"/>
<nav id="nav">
<ul>
<li>Portfolio</li>
<li>About Me</li>
<li>Resume</li>
</ul>
</nav>
</div>
<div id="content">
<div class="grid3">
<article class="bucket" >
<a href="#">
<img src="images/baskerville1.jpg" alt=""/>
<div class = "img-overlay">
<h3>Monogram</h3></div>
</a>
</article>
<article class="bucket">
<a href="#">
<img src="images/Gastalt.png" alt=""/>
<div class="img-overlay">
<h3>Gastalt Composition</h3>
</div>
</a>
</article>
<article class="bucket">
<a href="#">
<img src="images/redThread.png" alt=""/>
<div class="img-overlay">
<h3>The Red Thread - A Visual Book</h3>
</div>
</a>
</article>
<article class="bucket">
<a href="#">
<img src="images/poster copy.png" alt=""/>
<div class="img-overlay">
<h3>Typographic Hierarchy</h3>
</div>
</a>
</article>
<article class="bucket">
<a href="#">
<img src="images/Spaces.png" alt=""/>
<div class="img-overlay">
<h3>Living in Two Spaces</h3>
</div>
</a>
</article>
</div>
</div>
<div id="footer">©2014</div>
</div>
</body>
css code:
#charset "UTF-8";
*{
margin:0;
}
html, body {
margin: 0;
background-color: #FFFFFF;
height: 100%;
padding: 0;
}
#wrapper {
background-color: #FFFFFF;
width: 1000px;
padding-bottom: 0px;
margin:0 auto;
position:relative;
min-height: 100%;
}
#menunav {
position: fixed;
width:180px;
padding-top:80px;
height: 100%;
display: block;
margin: 0px;
}
#logo {
width: 70%;
position: static;
}
#menunav ul {
list-style-type: none;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
}
#menunav a {
display: block;
padding-top: 8px;
padding-bottom: 8px;
margin-top: 12px;
margin-right: 0px;
margin-left: 0px;
text-align: left;
padding-left: 20px;
background-color: rgba(193,193,193,1.00);
color: rgba(0,0,0,1.00);
}
#menunav a:hover, #menunav a:active, #mainnav a:focus, #menunav a.thispage {
background-color: rgba(0,174,210,1.00);
color: rgba(255,255,255,1.00);
text-decoration: none;
}
#content {
display: block;
margin: 0 auto;
padding-left:225px;
padding-top:80px;
background-color:#fffeee;
}
.centered {
margin-left: auto;
margin-right: auto;
display: block;
margin-top: auto;
margin-bottom: auto;
}
a {
text-decoration: none;
}
.bucket {
position:relative;
float: left;
margin-left: 3.2%;
margin-bottom:30px;
}
.grid3 .bucket:nth-of-type(3n+1){
margin-left: 0;
clear: left;
}
.grid3 .bucket{
width: 31.2%;
}
.img-overlay h3 {
opacity: 1;
display: inline-block;
margin: auto;
height: 20px;
position: absolute;
top: 0;
bottom: 0;
right: 0;
left:0;
color: rgba(255,254,254,1.00);
text-align: center;
vertical-align: middle;
}
.img-overlay {
background-color: rgba(0,0,0,0.6);
bottom: 0px;
top: 0px;
opacity: 0;
overflow:hidden;
filter: alpha(opacity=0);
position: absolute;
width: 100%;
z-index: 1000;
transition: opacity 0.3s;
-webkit-transition: opacity 0.3s;
}
.bucket:hover .img-overlay {
opacity:1;
filter: alpha(opacity=100);
}
.bucket img {
width: 100%;
}
#footer{
clear:both;
text-align: center;
line-height:20px;
vertical-align: middle;
}
#media screen and (max-width:740px){
/*change 3 column to 2 column*/
.grid3 .bucket:nth-of-type(3n+1) {
margin-left: 3.2%;
clear: none;
}
.grid3 .bucket:nth-of-type(2n+1) {
margin-left: 0;
clear: left;
}
}
Set z-index:1 and set background-color: #FFFFFF; in #menunav
#menunav {
z-index: 1;
background-color: #FFFFFF;
position: fixed;
width:180px;
padding-top:80px;
height: 100%;
display: block;
margin: 0px;
}
Here it is http://jsfiddle.net/n9V3W/2/ working!!!