Aligning Div inside another Div - css

You can visit the site I am working on here. Currently, I am working on making the site relative. I am adjusting the CSS for a resolution with a width less than 820px. This involves adjusting the menu from this
to this . As you can see, I have outlined my divs with a red border to demonstrate the problem. I want to the menu bar to sink to the bottom of its parent div. However, setting it to bottom: 0 nothing changes. How can I get the div class="nav" to sink to the bottom of div class="header" at a resolution of less than 820px?
Here is my HTML
<div class="header">
<div id="narrow-logo"><img src="Images/pantry logo.png" width="536" height="348"></div>
<div class="nav">
<ul>
<li class="link">HOME</li>
<li class="link">MENU</li>
<li id="logo"><img src="Images/pantry logo.png" width="536" height="348"></li>
<li class="link">CONTACT</li>
<li class="link">ABOUT</li>
</ul>
</div>
</div>
And my CSS
.header {
width: 960px;
height: 150px;
margin: 0 auto;
text-align: center;
position: relative;
padding: 100px 0px 0px 0px;
}
.header div#narrow-logo {
display: none;
}
.nav ul li {
display: inline-block;
vertical-align: middle;
margin-right: 70px;
}
#logo a img {
max-width: 250px;
height: auto;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%,-50%);
transform: translate(-50%,-50%);
}
#logo {
width: 250px;
position: relative;
}
#media screen and (max-width: 1080px) {
.header {
width: 700px;
height: 125px;
padding: 75px 0px 0px 0px;
}
#logo a img {
max-width: 180px;
}
#logo {
width: 180px;
}
#media screen and (max-width: 820px) {
.header {
border: 2px solid red;
width: 475px;
padding: 0;
margin-top: 40px;
height: 200px;
}
.header div#narrow-logo {
border: 2px solid red;
display: inherit;
position: absolute;
left: 50%;
-webkit-transform: translate(-50%);
transform: translate(-50%);
}
.header div#narrow-logo a img {
width: 200px;
height: auto;
}
.nav {
border: 2px solid red;
bottom: 0px;
}
.nav ul li {
margin-right: 25px;
}
.nav ul li:nth-child(3) {
display: none;
}
#logo a img {
display: none;
}
#logo {
width: 0;
}
I know that is a lot of code and I apologize. I just wanted to make sure I included all positioning attributes that could be causing my issue. Let me know if I can clarify anything, and I appreciate your time and advice.

For bottom:0 to work, you need the element that it's being applied to to be absolutely positioned. You also need, in this case, to have it's parent relatively positioned. Try this:
.nav ul li {
display: inline-block;
margin-right: 70px;
position:absolute;
bottom:0;
}

Adding position value will resolve your issue.Please update your css in the following section.
#media screen and (max-width: 820px) {
.nav {
border: 2px solid red;
bottom: 0px;
position:absolute;
left:16%;
}
}

For bottom:0; to work, your class="nav" has to have absolute positioning.
CSS:
.nav {
position: absolute;
bottom: 0;

Related

Divs side-by-side, centred, and overflowing edge of screen

I am trying to design a landing page to link to 2 web apps. I am trying to make the design as visually attractive as possible. I think it would look good if the Divs containing the links were side-by-side at the centre of the screen, with their edges overflowing the left and right of the screen. I can then put a border-radius on them and some nice blocky colour:
Goal:
I have tried numerous options, including inline-block and overflow:hidden:
HTML
<div id="centre-pane">
<div class="app-btn">
<img src="icon.png">link text
</div>
<div class="app-btn">
<img src="icon2.png">link text
</div>
</div>
CSS
.app-btn
{
width:1000px;
height:320px;
display:inline-block;
border:10px solid black;
border-radius: 50px;
}
#centre-pane {
width:2000px;
margin:0 auto;
text-align:center;
overflow-x: hidden;
}
Is this possible? I have found several ways of getting them side-by-side (eg here) but nothing that also lets them overflow the screen.
Just using position absolute would do the trick.
I've added a wrapper but it may not be required.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body,
html,
.wrapper {
height: 100%;
}
.wrapper {
position: relative;
}
.btn {
width: 45%;
height: 30%;
background: lightblue;
border: 2px solid blue;
position: absolute;
top: 50%;
transform: translateY(-50%);
}
.left {
left: 0;
border-radius: 0 25% 25% 0;
border-left: none;
}
.right {
right: 0;
border-radius: 25% 0 0 25%;
border-right: none;
}
<div class="wrapper">
<div class="btn left"></div>
<div class="btn right"></div>
</div>
You can achieve this with absolute positioning and negative margins (for the right item). You'll have to fix the size of the body though in order to achieve the effect. I've also added individual classes to the first and second item respectively (.app-btn-1 and .app-btn-2):
body {
width: 2000px;
overflow-x: hidden;
}
.app-btn {
width:1000px;
height:320px;
position: absolute;
border:10px solid black;
border-radius: 50px;
overflow-x: hidden;
}
.app-btn-1 {
left: -500px;
text-align: right;
}
.app-btn-2 {
left: 100%;
margin-left: -500px;
}
DEMO
NOTE: For my demo to look right in jsfiddle, I've quartered the sizes so you can see the effect in the small window
Here is the code you need:
.menu {
display: inline-block;
height: 200px;
width: 40%;
margin-top: calc(50% - 100px);
border: 2px solid red;
background-color: brown;
color: black;
text-decoration: none;
transition: all 0.5s;
}
#left {
float: left;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
margin-left: -10px;
}
#right {
float: right;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
margin-right: -10px;
}
.menu:hover {
background-color: gray;
border-color: brown;
color: red;
}
<div class="menu" id="left">Left</div>
<div class="menu" id="right">Right</div>
I made a
JS Fiddle for you.

Rectangle with oval bottom shape

Is it possible to create a flat oval that is as round as the example below?
I've looked at several examples on how to create the oval itself using CSS from the following sources:
http://css-tricks.com/the-shapes-of-css/
http://jsfiddle.net/QGtzW/1/
Unfortunately, as you size it down in height the oval just doesn't want to retain the rounded shape. Here is my current code on how I'm trying to achieve the same visual look as the image above:
HTML
<ul>
<li>
<a href="#">
<span class="text">Home</span>
<span class="oval"></span>
</a>
</li>
</ul>
CSS
a {
position: relative;
padding: 10px 30px 0px 30px;
text-transform: uppercase;
background-color: red; color: #fff;
}
.text {
position: relative;
z-index: 1;
}
.oval {
position: absolute;
bottom: -8px; left: 0;
z-index: 0;
display: block;
width: 100%; height: 20px;
border-radius: ~"20px/10px"; /* I'm using LESS and it requires ~"" to make it work */
background-color: red;
}
As a thank you for everyone here and as help for anyone in the future, here is my final code:
HTML
<ul>
<li>
Home
</li>
</ul>
CSS
a {
overflow: hidden;
position: relative;
padding: 10px 30px 20px 30px;
text-transform: uppercase;
color: #fff;
&:before {
content: '';
position: absolute;
top: 0; left: -25%; bottom: 4px;
z-index:-1;
width: 150%;
border-bottom-left-radius: 100%;
border-bottom-right-radius: 100%;
background-color: #AECE33;
border: 3px solid #6B6A65; border-top: 0;
}
}
Here is a responsive version of this shape using a pseudo element to minimize markup :
DEMO
Output :
HTML :
<div>Home</div>
CSS :
div {
position:relative;
width:40%; height:100px;
overflow:hidden;
margin:10px auto;
text-align:center;
font-size:1.8em;text-transform:uppercase;line-height:90px;color:#fff;
}
div:before {
content:'';
position:absolute;
top:0; left:-25%; bottom:4px;
width: 150%;
background-color: #AECE33;
border-bottom-left-radius: 100%;
border-bottom-right-radius: 100%;
border:4px solid #6B6A65;
border-top:0;
z-index:-1;
}
DEMO1
.cover{ height:100px; width:300px; overflow:hidden;}
.set {
background-color: #80C5A0;
width: 400px;
height: 100px;
margin-left:-50px;
border-radius: 50% / 100%;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
<div class="cover">
<div class="set"></div></div>
and this is what you want
DEMO2
and for creating a fluid menu as you asked below use DEMO3
Try this CSS
div {
background-color: #80C5A0;
width: 400px;
height: 100px;
-webkit-border-radius: 100% 100% 100% 100% / 0% 0% 100% 100%;
border-radius: 100% 100% 100% 100% / 0% 0% 100% 100%;
}
jsfiddle

Div to the right of a float is causing a horizontal scroll

I have a div which is floating to the left with a menu in it and another div to the right which is filling the rest of the space, the problem is, the div on the right is set to 100% but is going off to the right of the page and creating an unwanted scroll. I think the cause is the left-margin I have put on it to allow for the left floating div. Is there a way to make the right div fill the rest of the space without creating a horizontal scroll but so that I can also align things left: 0px against the edge of the float.
I have put the page onto one of my other domains so you can see:
http://aspiresupportandhousing.com/cleanserve/
HTML:
<body>
<div id="lp_bt">
<div id="logo_container_s">
</div>
<div id="menu_container_s">
<nav id="secondary_nav">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Our Services</li>
<li>Cleaning</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</div>
<div id="left_panel">
<div id="logo_container">
</div>
<div id="menu_container">
<nav id="primary_nav">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Our Services</li>
<li>Cleaning</li>
<li>Contact Us</li>
</ul>
</nav>
</div>
</div>
<div id="right_panel">
<div id="main_container">
<div id="title">
</div>
</div>
</div>
</body>
CSS:
html {
height: 100%;
min-width: 1000px;
}
* {
margin: 0px;
padding: 0px;
}
body {
height: 100%;
min-width: 1000px;
color: #000000;
}
/* Hidden */
#lb_bt {
height: 30px;
width: 30px;
left: 30px;
}
#logo_container_s {
left: -150px;
width: 150px;
height: 42px;
position: absolute;
background: url(logo.jpg);
z-index: 3000;
}
#menu_container_s {
left: -150px;
height: 400px;
width: 150px;
position: absolute;
z-index: 3000;
}
/* End Hidden */
/* Left Panel */
#left_panel {
height: 100%;
width: 150px;
float: left;
background-color: #26609E;
z-index: 2000;
}
#logo_container {
width: 150px;
height: 42px;
left: 0px;
top: 0px;
position: relative;
background: url(logo.jpg);
z-index: 3000;
}
#menu_container {
height: 400px;
width: 150px;
top: 0px;
left: 0px;
position: relative;
}
ul {
list-style: none;
text-align: left;
border-top: solid 1px #002954;
}
ul li {
display: list-item;
}
ul li a:link, ul li a:visited {
font-family: Verdana, Geneva, sans-serif;
font-size: 14px;
font-weight: normal;
width: 800;
color: #FFFFFF;
line-height: 38px;
margin: 0px 10px;
padding: 0px 5px 8px 0px;
text-align: left;
text-decoration: none;
}
ul li a:hover, ul li a:active {
color: #2593C1;
}
#media only screen and (min-width: 280px) and (max-width: 800px) {
body {
background: none rgba(161, 220, 254, 0.4);
}
#left_panel {
left: -150px;
position: absolute;
}
#lp_bt {
top: 0px;
left: 0px;
background: url(menu.jpg);
width: 30px;
height: 30px;
}
#lp_bt:hover {
width: 150px;
height: 100%;
background: none #26609E;
}
#lp_bt:hover #secondary_nav {
display: list-item;
}
#lp_bt:hover #logo_container_s {
left: 0px;
top: 0px;
position: relative;
}
#lp_bt:hover #menu_container_s {
top: 0px;
left: 0px;
position: relative;
}
}
/* End Left Panel */
/* Right Panel */
#right_panel {
height: 100%;
width: 100%;
margin-left: 150px;
background: url(bg.jpg) no-repeat top left fixed;
background-size: cover;
position: absolute;
z-index: 1;
}
#main_container {
width: 700px;
height: 50%;
margin-left: auto;
margin-right: auto;
margin-top: auto;
background: rgba(255, 255, 255, 0.8);
border-radius: 30px 30px 30px 30px;
}
#title {
width: 600px;
height: 104px;
margin-left: auto;
margin-right: auto;
top: 30px;
background: url(title.png) no-repeat center center;
position: relative;
}
#media only screen and (min-width: 280px) and (max-width: 800px) {
#right_panel {
background: none;
}
}
Your Scroll Is caused beacuse yo have a margin-left for your
#right_panel
You have three solutions wich envolve make some changes in CSS for the #right_panel
One use method calc() to set the width:
#right_panel {
width: calc( 100% - 150px);
}
Two change your z-index value and delete margin-left:
#right_panel {
width:100%;
margin-left:0;
z-index:-1;
}
Three use box-sizing and padding instead of margin:
#right_panel {
box-sizing:border-box;
padding-left:150px;
width:100%;
margin:0;
}
Seen as though #left_panel and #right_panel are positioned absolutely, you can simply remove the negative margin form #left_panel:
#left_panel {
left: 0px;
position: absolute;
}
... then remove the 100% width from #right_panel and position it thusly:
#right_panel {
top:0; right:0; bottom:0; left:150px;
}
http://jsfiddle.net/Pz7PP/
You need use CSS position.
A little example
Codepen
CSS
*{margin:0;padding:0;}
#divleft {
position:absolute;
top:0;bottom:0;left:0;
width:250px;
background: red;
}
#divright {
position:absolute;
top:0;
bottom:0;
left:250px;
right:0;
background: green;
}

DIV styling problems

Hi I am currently working on a project that has lots of DIVs and sections and such.
I am currently having problems with my header. The search bar and the panes div are going down or going out from the "header" section when I'm trying to minimize the browser window.
Structure goes like this.
As you can see on the image above, the red part is the header and it has 3 divs inside it.
This is how it goes on the view:
<div id = "header" class = "fixed-top">
<div class = "wrapper">
<div id = "logo">
</div>
<div id = "search-box">
</div>
<div id = "panes">
</div>
</div>
</div>
The header's width is 100% and having a class of position-fixed.
The wrapper class has a width of 980px and margin is 0 auto/auto centre. I also made its position to absolute.
The logo style looks like this:
#logo {
width: 130px;
height: 45px;
float: left;
background:url(image.png);
position: relative;
margin: 4px 0 0 2px;
}
The search bar on the other hand looks like this:
#search-box {
width: 440px;
padding: 2px 8px;
float: left;
position: relative;
margin-left: 90px;
}
Lastly, the panes style is:
#panes {
float: right;
width: 170px;
height: 48px;
position: relative;
margin-right: 10px;
}
And by the way, the search-box div also have child divs. And panes div has a UL list and each LIs are floated left.
Is there anything I am missing out why this happens?
I also tried the "clearfix" but it is still happening.
Thanks.
Just Try This CSS code, it will work nice
*{
margin:0;
padding:0;
}
#header{
background-color:#ED1C24;
width:740px;
float:left;
}
#logo {
width: 124px;
height: 45px;
background:url(image.png);
position: relative;
margin: 4px 0 0 2px;
float:left
}
#search-box {
width: 420px;
margin-left:20px;
position: relative;
float:left
}
#panes {
width: 160px;
height: 48px;
position: relative;
margin-right: 10px;
float:left
}
Like this
DEMO
CSS
* {
margin: 0;
padding: 0;
}
#header {
background-color: #ED1C24;
display: table;
vertical-align: middle;
}
#logo {
width: 130px;
height: 45px;
background: url(image.png);
position: relative;
margin: 4px 0 0 2px;
display: table-cell;
}
#search-box {
width: 440px;
padding: 2px 8px;
position: relative;
margin-left: 90px;
display: table-cell;
}
#panes {
width: 170px;
height: 48px;
position: relative;
margin-right: 10px;
display: table-cell;
}

Trying to get three divisions side by side

Here is my current code but i don't see what the problem is. I'm new to html so i'm not really sure. I'd like to have a column on the left at about 20% space, column in the center which takes 60% of the space and column on the right that takes 20% space.
#wrapper {
background-color: #788D9A;
padding-bottom: 1000px;
margin-bottom: -1000px;
}
#mainleft {
width: 20%;
float: left;
padding: 10px;
text-align: center;
background-color: #ABB8C0;
padding-bottom: 1000px;
margin-bottom: -1000px;
border-right: solid black;
display:inline-block;
}
#maincenter {
width: 60%;
float: left;
overflow: hidden;
text-align: center;
padding: 10px;
padding-bottom: 1000px;
margin-bottom: -1000px;
display:inline-block;
}
#mainright {
width: 20%;
float: left;
padding: 10px;
text-align: center;
background-color: #ABB8C0;
padding-bottom: 1000px;
margin-bottom: -1000px;
border-right: solid black;
}
You need to be mindful when using padding-left padding-right margin-left margin-right border-left and border-right when you want that type of layout.
Each of those styles affect the overall width of that element so adding a padding: 10px will actually make your div width = 20% + 20px.
If you want to have that inner padding and border style an inner div
Example: http://jsfiddle.net/b62Ju/2/
HTML
<div id="wrapper">
<div id="mainleft">
<div>L</div>
</div>
<div id="maincenter">
<div>C</div>
</div>
<div id="mainright">
<div>R</div>
</div>
</div>​
CSS
#wrapper {
background-color: #788D9A;
}
#wrapper > div
{
height: 1000px;
float: left;
text-align: center;
}
#mainleft {
width: 20%;
background-color: #ABB8C0;
}
#maincenter {
width: 60%;
}
#mainright {
width: 20%;
background-color: #ABB8C0;
}
#maincenter > div
{
height: 1000px;
border-left: solid black;
border-right: solid black;
}
#mainleft > div,
#maincenter > div,
#mainright > div
{
padding: 10px;
}
Alternatively you could use the box-model styles:
.box
{
box-sizing: border-box;
ms-box-sizing: border-box;
webkit-box-sizing: border-box;
moz-box-sizing: border-box;
}
more info: http://www.quirksmode.org/css/box.html
The display: table properties seem like the best choice here. You get your equal height columns (I assume that's what the crazy bottom margin/padding was for), no extra markup, and padding without having to worry about adjusting the box-model (learn more about the box-model here: http://css-tricks.com/the-css-box-model/).
http://jsfiddle.net/b62Ju/3/
#wrapper {
display: table;
width: 100%;
}
#wrapper > div
{
display: table-cell;
padding: 1em;
}
#mainleft {
width: 20%;
background-color: orange;
}
#maincenter {
width: 60%;
}
#mainright {
width: 20%;
background-color: green;
}
For your Reference if we need to place three dives side by side,
HTML:
<div class="main">
<div class="left">...</div>
<div class="center">...</div>
<div class="right">...</div>
</div>
CSS:
.main {
width: 1000px;
float: left;
display: inline-block;
}
.left {
width : 20%;
float: left;
display: inline-block;
}
.right {
width : 20%;
float: left;
display: inline-block;
}
.center {
width : 60%;
float: left;
display: inline-block;
}
it will work.
I think in your code you need set width for main wrapper div.

Resources