I need to get 3 row layout in HTML + CSS in my Angular.js app.
It should work like this:
My problem is when I resize my middle div get onto my top bar.
Here's some of my code:
.top-pos {
&.small {
padding-bottom: 130px;
}
&.big {
padding-bottom: 170px;
}
}
.bottom-pos {
bottom: 10px;
right: 0;
width: 100%;
position: absolute;
}
.middle {
#include align(vertical);
width: 100%;
}
HTML
<div class="top-pos small">
<div class="position-container">
<div class="top">
<h1 class="title">Some title</h1>
</div>
<div class="middle">
<input type="text" />
<input type="text" />
</div>
</div>
</div>
<div class="bottom-pos">
<button class="submit">Search</button>
</div>
Generally the top bar div should be always on top of the page, the bottom bar should be ALWAYS on bottom and the middle should be always on the middle between top and bottom bar. And the scrollbar should appear when all the elements are like on the second picture.
If older browser support is not an issue you could use css3 flex box to achieve something like this (not exact replica of the images):
#container{
display:flex;
flex-flow:column;
justify-content:space-around;
align-items:center;
width:50%;
height:100%;
}
#container div {
width:90%;
color:#fff;
background:black;
}
#top,#bottom{
height:50px;
}
#middle{
height:100px;
}
Demo
I have created a Fiddle which uses media queries to solve your problem. Hope that helps
CSS:
#media (min-width:400px) {
.top,.middle{
margin-bottom:20px
}
}
#media (max-width:399px) {
.top,.middle{
margin-bottom:2px;
}
h1{
margin:0;
}
}
For creating grid-like layouts that respond to window size changes, you should really consider Bootstrap. It allows you to very easily define layouts that are responsive to the window size. It also really nicely works together with Angular, since Angular defined directives that replace the Javascript part of Bootstrap. However, if you are only interested in the Grid layout part of Bootstrap, you do not need any Javascript at all, since it is all defined in CSS. See this link for more info on the Grid layout of Bootstrap:
http://getbootstrap.com/examples/grid/
Related
I have two separate non nested sections with a background image. The one displays the other does not. The one does not display because takes up no space even though a height is specified. When I put content in it, it shows, but only at the height of the content. So the bg image is not the problem. Both have no content except for an absolutely positioned item (which does not count as content to browser). The section that displays is inside a regular div. The section that does not display is inside of a flexbox. Don't know why that would make a difference.
I've seen answers on the web and at stack overflow and they all consist of either changing the path of the background image to the correct one, or giving a height to the element with bg image. I already knew about both of those requirements and I have them in both tags (unless there's a typo). But it works in one, but not the other. Do I have a typo that I can't see from looking at it too much? Driving me nuts over what should be a simple thing. A second pair of eyes would be very helpful
this works:
<section class="headingImg">
<p class="container headerText">
Increase your home's value<br />and enchance your lifestyle
</p>
</section>
Related styles. Container class attribute comes from bootstrap therefore not defined in css
.headerText {
text-shadow: 2px 2px 2px #222;
color:#f4e9da;
font-size:36px;
padding-top:235px;
font-style:italic;
line-height:36px;
}
.headingImg {
background-image:url('images/browndeck.jpg');
background-position: center;
background-repeat:no-repeat;
background-size:cover;
height:350px;
margin-bottom:40px
}
this does not work because section with bgimage has no height even though one is specified
<div class="container">
<section class="flex">
<div class="flexDiv bgColor">
<section id="kitchens" class="imgBoxSize cover relative">
<h2 class="absCenter">Kitchens</h2>
</section>
<p>Enhance the lifestyle of your mice, cock roaches and flies</p>
</div>
</section>
</div>
Related styles
.bgColor{
background-color:white;
}
.flex {
display:flex;
justify-content:space-around;
flex-wrap:wrap;
}
.flexDiv {
background-color:#CCC;
width:30%;
margin:0 auto;
}
#kitchens {
background-image:url("images/kitchen1.jpg");
background-repeat:no-repeat;
}
.imageBoxSize {
height:200px;
width:100%
}
.cover {
background-size:cover;
background-position:center;
}
.relative {
position:relative
}
.absCenter {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin:auto;
}
In the HTML you call class imgBoxSize while in the CSS it is called imageBoxSize. Those darn typo's..
before I go ahead, please read the complete question details before tagging this question as a duplicate.
I've searched the whole StackOverflow, and have spent more than 5 hours on gitter, and haven't been able to solve this problem.
#container {
max-width: 50%;
margin: 5% auto;
border: 5px solid black;
}
#container:after {
content: " ";
height: 0;
display: block;
clear: both;
}
#doin, #rgb {
max-width: 100%;
}
#doin:hover {
background: blue;
color: white;
}
#left {
float: left;
max-width: 30%;
}
#right {
max-width: 70%;
float: left;
}
.doin, .rgb {
max-width: 96%;
display: block;
margin: 2% auto;
}
<!DOCTYPE html>
<html>
<head>
<title>Ayush Bahuguna | Work</title>
<link rel="stylesheet" type="text/css" href="assets/css/work.css">
</head>
<body>
<div id="header"><h1>Projects</h1></div>
<div id="container">
<nav id="left">
<ul>
<li id="doin">Doinmin</li>
<li id="rgb">Guess The RGB</li>
</ul>
</nav>
<div id="right">
<img src="assets/img/doinmin.png" class="doin"><p class="doin" id="dpara">This project started as a basic to-do app, but along the way I turned it into something that I use while practicing a musical instrument. The app can be used to deal with big tasks that can be broken down into smaller tasks, with each task being dealt with for a certain amount of time. It prevents you from getting overwhelmed. The app is built using HTML5, CSS3, and jQuery.</p>
<img src="assets/img/rgb.png" class="rgb"><p class="rgb" id="rpara">This is the second major project that I undertook while learning JavaScript. The code relies heavily on functional programming, particularly, the use of higher order functions. A random rgb(x, y, z) is generated, and one has to guess the correct color out of the 6, under hard level, or 3, under easy level, colors. </p>
</div>
</div>
<div id="clear"></div>
<script type="text/javascript" src="assets/js/work.js"></script>
</body>
</html>
let me explain what I am trying to achieve: https://docs.google.com/drawings/d/1DvQIzW74lRTZHJCdPh-VBkGv4OXIIqtVxEJRp3S-mk4/edit
The content inside my two floated divs is really messed up.I am trying to increase the width of my left div, but it doesn't affect its width, and the right div shifts further towards left, increasing the white space on the right.
What I really want is to have my nav items take up the whole space, which they do, but I am not able to increase the width.
Moreover, I want the content on the right to be vertically aligned in the middle.
I tried inline-block, but the content in the left div got pushed down to the bottom. If you guys think that using inline-block would be a better idea, then please guide me with that.
Thank You
so the summary, what do u want to achieve is nav in the left and content in the right. and a content it self are vertical align middle. and i dont remember if it should be horizontally center.
forget about the float:left
use flex from the start, you can find it in here all about flex
see my code
if you like it, delete your code and adapt with mine
.wrap{
width:100%;
height:300px;
display:flex;
align-items:center;
justify-content:center;}
.wrapception{
width:75%;
height:100%;
position:relative;
display:flex;
flex-direction:row;
flex-wrap:wrap;
}
nav{
background:yellow;
width:30%;
height:100%;}
section{
background:red;
width:70%;
height:100%;
display:flex;
align-items:center;}
<body>
<h1>Projects</h1>
<div class="wrap">
<div class="wrapception">
<nav>asdasd</nav>
<section>asdasdsad</section>
</div>
</div>
</body>
I have some DIVs on a page. How can I make the DIVs create a new column on the right when the bottom of the page is reached. So I have some small fixed height DIVs with images inside them. After every DIV, there is a line and then the next div and so on. On smaller displays, the screen requires scrolling to see the DIVs. So I added overflow: hidden to the body, to disable the scrolling. Now the DIVs at the very bottom are cut out, so I want the DIVs that are cut out, to create a new column to the right.
Example: .
body {
overflow: hidden;}
#icon {
background: #000;
color:#fff;
height:50px;
width:50px;
}
<body>
<div id=icon>1</div><br>
<div id=icon>2</div><br>
<div id=icon>3</div><br>
<div id=icon>4</div><br>
<div id=icon>5</div><br>
<div id=icon>6</div><br>
<div id=icon>7</div><br>
<div id=icon>8</div><br>
<div id=icon>9</div>
There's a lot of solutions to this and all run into polyfill issues. Columns are notorious for this.
A good option with decent coverage is to use flexboxes. Flexboxes were pretty much made for this kind of stuff.
Wrap all the divs in another div (i used section) and give the wrapping container some flexbox rules:
body {
overflow: hidden;}
.wrap {
display: flex;
flex-direction: column;
flex-wrap: wrap;
height: 100vh; /*the height will need to be customized*/
width: 50px;
}
#icon {
background: #000;
color:#fff;
height:50px;
width:50px;
margin-left: 10px;
}
<section class="wrap">
<div id=icon>1</div><br>
<div id=icon>2</div><br>
<div id=icon>3</div><br>
<div id=icon>4</div><br>
<div id=icon>5</div><br>
<div id=icon>6</div><br>
<div id=icon>7</div><br>
<div id=icon>8</div><br>
<div id=icon>9</div>
</section>
You'll need to give height and width rules to the wrapper, however. If it's in another container with a set height, you should be able to give it height: 100% and it will reach the bottom of the page.
Word of warning: columns and flexboxes are notorious for having cross-browser compatability issues, though mobile browsers are somewhat better at this. A good solution is to use a library with a focus on responsive or mobile design, like Bootstrap or SpaceBase (though the latter is a SASS library)
#samuel-denty are you looking for CSS Columns ?
here is jsfiddle: https://jsfiddle.net/zk7578vj/
try using class (.) icon instead of id (#) on css, like this:
body {
overflow: hidden;
-webkit-columns: 50px 2;
-moz-columns: 50px 2;
columns: 50px 2;
}
.icon {
background: #000;
color:#fff;
height:50px;
width:50px;
}
<body>
<div class="icon">1</div><br>
<div class="icon">2</div><br>
<div class="icon">3</div><br>
<div class="icon">4</div><br>
<div class="icon">5</div><br>
<div class="icon">6</div><br>
<div class="icon">7</div><br>
<div class="icon">8</div><br>
<div class="icon">9</div>
</body>
I'm trying to create a layout using flexbox but I'm stumped as to why I can't force a particular section of my UI to overflow with scrollbars. Everything seems to work great until a large child is added which seems to expand everything.
Here's the pen: http://codepen.io/tuckwat/pen/NNWRaB?
Notice that scrollbars appear on the whole page, I want scrollbars to appear on the #view container (dark blue) when a child gets too big.
Here's a pen with the overflow: auto added to #view - http://codepen.io/tuckwat/pen/VawKyp
How can I get this layout to work? I don't want to use absolute positioning on the view because the sidebar or appbar can dynamically resize.
HTML
<div id="body">
<div id="appbar">appbar</div>
<div id="main">
<div id="sidebar">side</div>
<div id="content">
<div id="navbar">nav</div>
<div id="view">
This view container should scroll
<div id="view-content">
This content makes the view grow too large
</div>
</div>
</div>
</div>
</div>
CSS
#body{
background: #ccc;
display:flex;
flex-direction: column;
position:absolute;
left: 0px;
right: 0px;
bottom: 0px;
top:0px;
}
#appbar{
height:55px;
}
#main{
display: flex;
flex:1;
background: #ddd;
}
#sidebar{
height:100%;
background:#660099;
width:50px;
flex-shrink:0;
}
#content{
display:flex;
flex:1;
flex-direction:column;
}
#navbar{
height:20px;
background:#3cd;
}
#view{
flex:1;
background:#126;
overflow: auto;
}
#view-content{
width:1500px;
height:1500px;
background: #ff6600;
}
Another wrinkle... I found a similar blog post that outlines the issue with a solution: http://geon.github.io/programming/2016/02/24/flexbox-full-page-web-app-layout
When applied to my codepen it works great in Chrome and IE but scrollbars don't show up in Firefox. I thought the days of fighting browser quirks were over...
http://codepen.io/tuckwat/pen/qZBrya
#body{
overflow: hidden;
...
}
#content{
overflow: hidden;
...
}
Finally - solution
I was close, but Firefox requires min-height on Flexbox items. Here's a pen that works across IE, Chrome, and Firefox: http://codepen.io/tuckwat/pen/oxNZJW
This is rather odd.
All three of your codepens are missing "overflow: auto;" for the view class. Adding it adds does exactly what you wanted, as shown in the absolutely positioned codepen.
What browser are you using?
(I would do this in a comment, but I don't have enough rep yet.)
So, i'm super new to HTML/CSS. For my class I have to make a portfolio webiste.
I want to be very simple. So, I'm starting off with my name centered in the middle of the page, and then underneath I want it to look like this:
About Graphic Design Studio Art (but, spaced out a little obviously)
Here is my html:
<!-- BEGIN: Sticky Header -->
<div id="header_container">
<div id="header">
</div>
<div id="indexheader"><a rel="title">THIS IS MY NAME</a>
</div>
<div id="links">
<a rel="#about">About</a>
</div>
<div id="links">
<a rel="#design">Graphic Design</a>
</div>
<div id="links">
<a rel="#art">Studio Art</a>
</div>
</div>
</div>
<!-- END: Sticky Header -->
Here is my CSS:
/* Make Header Sticky */
#header_container {
background:transparent;
height:60px;
left:0;
position:fixed;
width:100%;
top: 40px;
text-align: center;
}
#header {
left: 0;
position: fixed;
right: 0;
text-align: center;
top: 160px;
z-index: 999;
float: right;
}
body.top-navigation-position-below-banner #navigation-bottom {
position: fixed;
top: 0;
border-bottom: none;
z-index: 999;
}
#page-header-wrapper {
margin-top: 180px;
}
#links {
height: auto;
width: 100%;
margin-top:30px;
background-color:transparent;
text-align: center;
margin-top: 10px;
margin-left:0%;
padding: 0px;
}
http://jsfiddle.net/r7K26/
I also tried to make it a sticky-header. Not sure if that's right either. IM A HUGE NOOB. Forgive me.
You are closing your div with id #header immediately, so the elements beneath is are not receiving any styling. That might be what you want, but then you have an extra at the end of your html.
You can center your div a lot of ways, but the following should work fine:
#indexheader {display:block;width:100%;text-align:center;}
Good luck!
Well, you don't need that many divs first of all. Look at this, for example:
Html:
<div class="myInfo">
<h1>Your Name</h1>
<ul class="myLinks">
<li>link</li>
<li>link</li>
<li>link</li>
</ul>
</div>
And actually, you don't even need a div in this case but regardless, having the class on one div you can style with selectors such as:
.myInfo H1 {....}
.myInfo UL {..}
etc
or just
.myLinks {} for the url and then:
.myLinks li {} for the list items.
I know this is a fast answer but as you are learning, I think it might be better to 'sort of' give you some pointers instead of just doing it all, right?
:)
You're very close, and here's one solution using your code as a base. Try this styled JSFiddle and see if its what you need. Please feel free to play around with the code, and hit the Run button when you are ready to see the results. http://jsfiddle.net/TalkingRock/MAuzN/
The structure:
The html code is simplified by using "header_container" to wrap the entire header (title and menu). The "indexheader" is placed in its own div. A new menu div now contains/wraps only the menu items.
<div id="header_container">
<div id="indexheader">THIS IS MY NAME</div>
<div id="menu">
<div class="links">About</div>
<div class="links">Graphic Design</div>
<div class="links">Studio Art</div>
</div> <!-- end menu -->
</div> <!-- end header_container -->
The CSS
Inline-block is used to shrink wrap, center, and display the menu items in a single line. Inline-block has a natural 4px margin around each item, and that can be removed by removing the white space in-between each inline-block item in the html code. You'll also need to add "vertical-align:top". Inline-block is a good style to learn, has good browser support, and comes in handy.
#header_container {
margin:0px;
padding:0px;
border:0px;
min-height:80px; /* use min-height so the div will expand around the contents, regardless of height. */
width:100%;
background-color:transparent;
position:fixed;
top:40px;
}
#indexheader {
text-align:center;
padding:10px;
}
#menu {
text-align:center; /* text-align center works because of the inline-block */
}
.links {
display:inline-block;
vertical-align: top
}
Good article on lnline-block: http://robertnyman.com/2010/02/24/css-display-inline-block-why-it-rocks-and-why-it-sucks/
Inline-block support: http://caniuse.com/#feat=inline-block
Here are a few other articles you'll find useful. CSS Fixed Menus:http://www.w3.org/Style/Examples/007/menus.en.html
The Z Index: http://coding.smashingmagazine.com/2009/09/15/the-z-index-css-property-a-comprehensive-look/
Note: The div that holds your contents needs a top padding or margin tall enough to make sure it isn't covered up by the fixed menu. Position fixed will be buggy in touch devices, especially handheld phones. In your original code there is an extra div in your html, id's can only be used once per page, use href for your links, and "backgound-color:transparent" (transparent is the default style).