Two divs on top of each other. Make them equal width? - html

I have two <div> stacked on top of each other and centered. How to make them of equal width? If one of them has width: 96%; and when I give the other one the same width, it looks smaller than the first one.
Here's the HTML:
<div class="background-image">
<div class="container">
<header>
<ul id="menu">
<li>Main</li>
<li>Apartments</li>
<li>Services</li>
<li>Blog</li>
<li>Contacts</li>
</ul>
</header>
</div>
<div class="slider">
.....smth
</div>
and the CSS:
body{position:absolute; ....}/*needed this because of the body background image*/
.container{
width: 96%;
height: 350px;
background: #fff;
margin-top: 50px;
box-shadow: 0 0 20px #777;
padding: 60px;
}
.slider {
position: relative;
max-height: 500px;
margin: 0 auto;
}
So I need to make the .slider div the same width as the .container

If you include both divs inside another parent div, you can control the width for both at once by setting the style of that parent element. Then the padding around your 1st div will stretch out the parent div, and the 2nd div will fill the horizontal space of the parent. This version works:
HTML:
<div class="background-image">
<div class="mycolumn">
<div class="container">
<header>
<ul id="menu">
<li>Main</li>
<li>Apartments</li>
<li>Services</li>
<li>Blog</li>
<li>Contacts</li>
</ul>
</header>
</div>
<div class="slider">
.....smth
</div>
</div>
</div>
CSS:
body{position:absolute; ....}
.mycolumn {
width: 96%;
margin-top: 50px;
}
.container{
height: 350px;
background: #fff;
padding: 60px;
box-shadow: 0 0 20px #777;
}
.slider {
position: relative;
max-height: 500px;
margin: 0 auto;
}

https://jsfiddle.net/jq9qrfrw/1/
This is closer to what you want, the background image should be placed as the body background instead of in that unclosed div. Let me know what updates you need to get it closer to how you want.
<div class="container">
<header>
<ul id="menu">
<li>Main</li>
<li>Apartments</li>
<li>Services</li>
<li>Blog</li>
<li>Contacts</li>
</ul>
</header>
</div>
<div class="slider">
.....smth
</div>
CSS:
html,
body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
.container {
padding: 0;
overflow: hidden;
width: 96%;
height: 350px;
background: #fff;
margin: 50px auto 0 auto;
box-shadow: 0 0 20px #777;
}
.slider {
padding: 0;
width: 96%;
position: relative;
max-height: 500px;
margin: 0 auto;
background-color: red;
}

Just set the width on both elements in the CSS
body{position:absolute; ....}/*needed this because of the body background image*/
.container{
width: 96px;
height: 350px;
background: #fff;
margin-top: 50px;
box-shadow: 0 0 20px #777;
padding: 60px;
}
.slider {
width: 96px;
position: absolute;
max-height: 500px;
margin: 0 auto;
width: 100%;
//box-shadow: 0 0 20px #777;
}
Feel free to uncomment the box-shadow in the .slider element to check the width is correct.

Related

child's padding is bigger than parent's size

I would like to make my tag is big as the parent div (#logo, and i'm having trouble making a 100% padding without making it bigger than the parent's tag.
HTML
<div id="header">
<div id="logo">
</div>
<div class="hide" id="navigation">
<ul>
<li>About</li>
<li>Examples</li>
<li>Form</li>
<li>Contact</li>
</ul>
</div>
</div>
CSS
div#logo {
background: url(https://i.imgur.com/sHTtXk4.png) no-repeat center center;
background-size: cover;
float: left;
line-height: 80px;
width: 10%;
height: 80px;
text-align: center;
}
div#logo a {
background: #fff;
width: 100%;
height: 100%;
padding: 100%;
https://jsfiddle.net/vwbo9exg/
Remove padding and add display for a tag
div#logo a {
background: #fff;
width: 100%;
height: 100%;
/* padding: 100%; */
display: inline-block; /*Add this*/
}

Overlayer pushing away side navigation

So I'm creating an single page website with a dot navigation at the side. I have a picture as background on the first section, because the website exists out of 5 section where you can scroll downwards.
The black screen is pushing away my right navigation downwards, i used z-index but thats only the makes sure that the navigation is displayed on top. margin and padding also on 0. I want the black screen with 50% opacity but that isn't working either.
What I need is a black screen with 50% opacity on top of my background picture covering the whole section without pushing away other elements.
.back{
background-color: black;
opacity: 50%;
width: 100%;
height: 110%;
margin: 0;
padding: 0;
display: block;
position: sticky;
z-index: -1;
background-size: cover;
}
#section1{
background-image: url("../Content website/background.png");
background-repeat: no-repeat;
background-size: cover;
z-index: 50;
}
/* Dot navigation */
.dotstyle-scaleup{
float: right;
margin-right: 3%;
}
.dotstyle-scaleup li{
background-color: #eeeeee;
width: 15px;
height: 15px;
border-radius: 50%;
margin: 80px 0 0 0;
list-style: none;
}
.dotstyle-scaleup .current1{
background-color: #54a59f;
width: 20px;
height: 20px;
border-radius: 50%;
margin: 80px 0 0 0;
list-style: none;
margin-left: -2.5px;
}
.dotstyle-scaleup li a {
width: 100%;
height: 100%;
display: block;
}
<html lang="en">
<body>
<div id="wrapper">
<!-- Landings -->
<div class="section" id="section1" data-anchor="page1">
<div class="back"></div>
<div class="dotstyle-scaleup">
<ul>
<li class="current1"></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</div>
</body>
</html>
Changes you need to make:
Add position:relative to your section container.
Position your back in fixed position in your section with position:fixed and use the top,left,bottom,right as 0 so it stretches over the entire length of your section.
.back {
background-color: black;
top:0;
left:0;
right:0;
bottom:0;
opacity:0.5;
position: fixed;
}
#section1 {
position:relative;
background-image: url("../Content website/background.png");
background-repeat: no-repeat;
background-size: cover;
z-index: 50;
}
/* Dot navigation */
.dotstyle-scaleup {
float: right;
margin-right: 3%;
}
.dotstyle-scaleup li {
background-color: #eeeeee;
width: 15px;
height: 15px;
border-radius: 50%;
margin: 80px 0 0 0;
list-style: none;
}
.dotstyle-scaleup .current1 {
background-color: #54a59f;
width: 20px;
height: 20px;
border-radius: 50%;
margin: 80px 0 0 0;
list-style: none;
margin-left: -2.5px;
}
.dotstyle-scaleup li a {
width: 100%;
height: 100%;
display: block;
}
<div id="wrapper">
<!-- Landings -->
<div class="section" id="section1" data-anchor="page1">
<div class="back"></div>
<div class="dotstyle-scaleup">
<ul>
<li class="current1">
</li>
<li>
</li>
<li>
</li>
<li>
</li>
<li>
</li>
</ul>
</div>
</div>

Bootstrap Fixed part layout issue

I am creating bootstrap page we have four parts of page container.
Please find below of model screen,
<div id="fixedheader">
<header>
</header>
<div class="a">
</div>
</div>
<!--Fixed header End-->
<!--Search content part start-->
<div class="searchcontent">
</div>
<!--Search Content End-->
I want "fixed-header" part should be fixed part of my page. i added style below,
#fixedheader
{
position:fixed;
overflow: hidden;
left:0;
right:0;
}
Now "search content" part some of the content hide in fixed header part in normal view ,find below of my sample output screen
How to fix the issue.
Try
css:
body{
margin: 0;
padding: 0;
background: #80B196;
}
header{
height: 150px;
background: yellow;
}
h1{
margin: 0 auto;
padding: 50px 0 0 0;
width: 300px;
color: #333333;
}
ul{
margin: 0;
padding: 0 0 0 50px;
list-style-type: none;
background: pink;
}
ul li{
display: inline-block;
padding: 6px;
background: rgba(0,0,0,0.4);
vertical-align: top;
}
.wrapper{
height: 1000px;
}
p{
margin: 0 auto;
width: 60%;
}
.fixed-nav{
width: 100%;
position: fixed;
top: 0;
left: 0;
}
and HTML
<div>
<header>
<h1>Header</h1>
</header>
<nav id="main-nav">
<ul>
<li>div</li>
<li>class</li>
</ul>
</nav>
<span id="mine"></span>
<div class="wrapper">
</div>
Codepen Example

Why is margin top not working on an image replacement logo?

I have a navigation menu splited by the logo:
<div id="header">
<div id="header-container">
<div class="left-nav">
<ul>
<li>Home</li>
<li>Portfolio</li>
<li>Awards</li>
</ul>
</div>
<div class="logo">
<h1>Magdi Designs</h1>
</div>
<div class="right-nav">
<ul>
<li>Testimonials</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
CSS
#header {
height: 60px;
margin-top: 30px;
}
#header-container {
width: 80%;
margin: auto;
position: relative;
}
#header li {
display: inline;
line-height: 60px;
}
#header .left-nav {
position: absolute;
top: 0;
left: 0;
}
#header h1 {
background: url(logo.png) no-repeat;
width: 284px;
height: 30px;
margin-top: 15px;
text-align: center;
margin: auto;
}
#header .right-nav {
position: absolute;
top: 0;
right: 0;
}
The <h1> logo tag doesn't seem to apply the margin top.
Sorry if I'm putting too much irrelevant code, but I'm not sure what's causing the problem.
I've also tried padding but still doesn't work.
jsFiddle Demo
Secondary question:
Is this a good way to do the split menu?
Try:
#header h1 {
margin: 15px auto 0;
}
instead of:
#header h1 {
margin-top: 15px;
margin: auto;
}
You're setting margin: auto after margin-top: 15px which is removing the desired margin. The margin: auto isn't needed anyway.

Fixed header won't obey page width

I'm building the framework for a responsive site that has a fixed header and 25px padding on both right & left sides of the page. I'm not encountering any issue with the padding or width on the content, but the fixed header runs off the right side of the browser when the display is too small. I'd like the header to obey the same rules and design as the rest of the page, and always show a 25px padding unless the display is narrower than my min-width.
Any help would be appreciated. This seems rather simple, but I'm pulling my hair out.
CSS:
#main {
padding: 0 0px 0 25px;
min-width: 725px;
max-width: 1000px;
margin: 0 auto;
}
#page {
padding: 0 25px 0 25px;
display: block;
margin: 0 auto;
max-width: 1000px;
min-width: 725px;
position: relative;
}
ul#header-nav {
margin: 33px 0px 0 0px;
list-style:none;
width:500px;
font-family: "ss-bol", Helvetica, Arial, sans-serif;
overflow: hidden;
}
ul#header-nav li a {
text-decoration:none;
padding-left: 30px;
color:#000000;
float:left;
text-align: right;
display:inline;
}
#container {
padding-top: 100px;
left: 0;
height: 100%;
}
#header-main {
width: 100%;
margin: 0 -25px 0 0px;
}
#header-frame {
z-index: 10;
background-color: #c9dcb1;
float: right;
}
#header-box {
width: 100%;
max-width: 1000px;
min-width: 725px;
padding-left: -25px;
height: 100px;
background-color: #ffffff;
margin:0px;
position: fixed;
background-color: #c9dcb1;
z-index: 11;
}
#content {
padding-top: 100px;
width: 100%;
background-color: #75efe8;
}
HTML:
<body>
<!-- BeginHeader -->
<div id="page" class="clearfix heed">
<div id="header-main">
<div id="header-box">
<div id="header-frame">
<ul id="header-nav">
<li>NEW</li>
<li>SHOP</li>
<li>WINE</li>
<li>BLOG</li>
<li>LOOKBOOK</li>
<li>ABOUT</li>
</ul>
</div>
</div>
</div>
<div id="content">
TEST CONTENT TEXT
</div>
</div>
</body>
padding, margin and border are added to the with of an element. So, when your display is to small, by telling max-width: 1000px, you imply 1050px because of the padding.
The easy solution is to replace width: 100% by this left and right set as 0, and center your inner content.
<div id="header-box">
<div class="inner">header</div>
</div>
#header-box {
max-width: 1000px;
min-width: 725px;
position: fixed;
left: 0;
right: 0;
top: 0;
}
#header-box .inner {
max-width: 1000px;
margin: 0 auto;
}
Simon, I took the basics of your approach and expanded upon it to get what I needed.
Here's the final CSS:
#header-wrapper {
padding: 0;
margin: 0;
}
#header {
position: fixed;
width: 100%;
min-width: 800px;
height: 100px;
z-index: 9;
background-color: #ffffff;
}
#header .inner {
margin: 0 auto;
padding: 0 25px 0 25px;
max-width: 1000px;
height: 100px;
z-index: 10;
background-color: #ffffff;
}
ul#header-nav {
margin: 58px -20px 0 0px;
list-style: none;
width: 500px;
font-family: "ss-bol", Helvetica, Arial, sans-serif;
font-size: 14px;
overflow: hidden;
}
ul#header-nav li a {
text-decoration: none;
padding-left: 30px;
color: #000000;
float: left;
text-align: right;
display: inline;
}
And the HTML:
<div id="header-wrapper">
<div id="header">
<div class="inner">
<div class="right">
<ul id="header-nav">
<li>NEW</li>
<li>SHOP</li>
<li>WINE</li>
<li>BLOG</li>
<li>LOOKBOOK</li>
<li>ABOUT</li>
</ul>
</div>
</div>
</div>
Thanks again!