Overflowing issues - css

I am working on a HTML/CSS website, with mainly 4 divs (wrapping, top, menu and content), using a centered layout.
The problem is that the text inside my #content overlaps and I can't force it inside the div. Also, when I enable scrolling on the div and disable it on HTML, the scrolling just won't work for the div. So I get stuck with the overlapping content and no option to scroll down.
So, resuming it, I want to use 3 fixed divs, centered, leaving two side-borders and want my background-image to not move. Only the content should scroll inside of it.
Here's my CSS code:
<style type=text/css>
html
{
overflow: none;
}
head
{
}
body
{
background-color: #030B12;
}
p
{
font-family: verdana;
font-size: 12px;
color: #FFFFFF;
text-align: left;
}
h1
{
margin-top: 25px;
font-family: verdana;
font-size: 16px;
color: #FFFFFF;
text-align: center;
}
bg2
{
position: fixed;
top: 0;
left: 0;
}
#wrapper
{
height: 100%;
width: 70%;
margin: auto;
background-image: url('bg2.jpg');
background-position: fixed;
background-repeat: no-repeat;
}
#top
{
background-image:url('top.jpg');
background-repeat: no-repeat;
background-position: fixed;
height: 15%;
width: 100%;
margin: auto;
}
#menu
{
height: 60px;
width: 100%;
background-image: url('navi_bg.png');
}
#content
{
overflow: auto;
display: block;
}
ul
{
list-style-type: none;
height: 60px;
width: 663px;
margin: auto;
}
ul a
{
background-image: url(navi_bg_divider.png);
background-repeat: no-repeat;
background-position: right;
padding-right: 22px;
padding-left: 16px;
display: block;
line-height: 60px;
text-decoration: none;
font-family: Georgia, "Times New Roman", Times, serif;
font-size: 21px;
color: #FFFFFF;
}
ul li
{
list-style-type: none;
float: left;
}
ul a:hover
{
color: #3F5F7B;
}

Based on what is available, I've created a layout that I think is what you are looking for. There are some issues with getting the top li menu items to center, but I am sure you could work that out pretty easily. You should specify the height of the content area if you want to scroll just that area, and keep the wrapper's background static.
div#content{
max-height:300px;
overflow-y:scroll;
}
Here is the fiddle

Related

Margin not giving any results on divs

I'm not any kind of CSS pro. But margin doesn't seem to work in any other parts than the ul/li list provided below.
I have played with positions and other divs.
html, body {
margin: 0;
padding: 0;
}
body {
background-color: rgb(184, 184, 184);
background-repeat: no-repeat;
background-position: center;
background-size: auto;
background-image: url('/images/landing.jpg');
font-family: Montserrat;
}
.header {
top: 0;
position: fixed;
background-color: gray;
width: 100%;
height: 60px;
justify-content: center;
align-items: center;
display: flex;
}
.menu {
position: fixed;
top: 6px;
right: 0;
}
.menu ul li {
display: inline;
}
.menu ul li a {
color: white;
text-decoration: none;
font-size: 16px;
font-weight: lighter;
padding: 0 20px;
}
.welcome {
position: absolute;
color: white;
font-size: 50px;
top: 459px;
margin: auto;
}
HTML:
<div class='welcome'>
<span>Hello!</span>
</div>
Trying to get welcome div to center
You are setting margin: auto on an absolute positioned element. I suppose you are trying to center the 'welcome' element (as per your question, this fact is not clear). An absolute positioned element is dependent on its ancestors positioning and size.
One of the many solutions to center an absolute positioned element if to move it to 50% from the top and left of it's parent, and than apply translate to nudge it to the center: top: 50%; left: 50%; transform: translateX(-50%) translateY(-50%).
welcome class position is absolute so welcome class parent should be relative to center the welcome div. And also if you want to horizontally center the div you should change margin: auto; to margin: 0 auto;
Or you can make the parent div display to flex, then use align-items, justify-content to center.
.parent { display: flex, align-items: center, justify-content: center }
Try changing your welcome css class to this:
.welcome {
position: absolute;
left: 50%;
transform: translate(-50%);
}
Replace your .welcome css class with this css code :
html, body {
margin: 0;
padding: 0;
}
body {
background-color: rgb(184, 184, 184);
background-repeat: no-repeat;
background-position: center;
background-size: auto;
background-image: url('/images/landing.jpg');
font-family: Montserrat;
}
.header {
top: 0;
position: fixed;
background-color: gray;
width: 100%;
height: 60px;
justify-content: center;
align-items: center;
display: flex;
}
.menu {
position: fixed;
top: 6px;
right: 0;
}
.menu ul li {
display: inline;
}
.menu ul li a {
color: white;
text-decoration: none;
font-size: 16px;
font-weight: lighter;
padding: 0 20px;
}
.welcome {
left:50%; right:50%;
top:50%; bottom:50%;
position: absolute;
}
<div class='welcome'>
<span>Hello!</span>
</div>

Remove white space from left & right side of header image

I'm currently in the process of setting up my blog, and I am having difficulty formatting the header in the way I had planned.
Here is my site. As you can see, their is extra space on the sides of the header. My goal would be to remove the space, so that the floral pattern is flush with the content box or whatever you call it.
I've gone through my theme's CSS multiple times, and have changed the margins, widths, and paddings on everything and anything possibly associated with the header image, but have had zero luck. Is their something I'm missing?
My blog is hosted through Wordpress and my parent theme is from the Genesis Framework.
Here is the CSS for the header image:
/*
Site Header
--------------------------------------------- */
.audrie .site-header {
background-position: center;
padding:0px 0;
width:100%;
}
/* Title Area
--------------------------------------------- */
.title-area {
padding: 0px 0;
margin-bottom: 30px;
margin-top: 20px;
}
.title-area h1 {
margin: 0 auto;
}
.title-area p {
margin: 0;
}
.header-image .title-area {
padding: 0;
width:100%;
}
.site-title,
.site-title a {
font-size: 64px;
font-weight: 600;
letter-spacing: 8px;
line-height: 1.2;
text-align: center;
text-decoration: none;
text-transform: uppercase;
overflow-wrap: break-word;
}
.site-title a,
.site-title a:hover {
color: #747474;
}
.site-description {
color: #808080;
font-family: Lato;
font-size: 13px;
font-weight: 300;
letter-spacing: .5px;
margin: 0;
text-align: center;
text-transform: none;
}
/* Full width header, no widgets */
.header-full-width .title-area,
.header-full-width .site-title {
width: 100%;
}
.header-image .site-description,
.header-image .site-title a {
display: block;
text-indent: -9999px;
}
/* Logo, hide text */
.header-image .site-header {
background-position: center !important;
background-size: 1000px 200px !important;
padding: 0;
margin-top:-90px;
padding-bottom:30px;
}
.header-image .site-title a {
float: none;
min-height: 200px;
width: 100%;
}
/* Widget Area
--------------------------------------------- */
.site-header .widget-area {
float: right;
text-align: right;
width: 720px;
}
.header-image .site-header .widget-area {
padding: 0px 0;
}
.site-header .search-form {
float: right;
margin-top: 22px;
}
Any help or guidance in the right direction would be greatly appreciated! Thanks!
Your header (.site-header) has a fixed background size of:
background-size: 1000px 200px !important;
But your .site-container div has a max width of 1100px, witch makes your image smaller than the rest. Instead, let it be responsive, as in:
background-size: 100% auto !important;
/*Assuming you have a reason for "!important" */
.site-container has a 36px horizontal padding which is causing the whitespace around your header. If you add:
.site-container {
padding-left: 0;
padding-right: 0;
}
your horizontal whitespace will disappear, but you'll also need to add:
header {
background-size: 1100px 200px !important
}
to get the top image to span full width.
Finally to clean it up I'd add:
.site-inner{
padding-left: 36px;
padding-right: 36px;
}
so your text has some room on the sides.
you could do something like this:
.site-container{
padding: 0
}
.header-image .site-header{
background-size: 1100px 200px !important;
}
.site-inner{
padding: 36px;
}
maybe some !important is needed and check the responsiv-behavior..

Two <li> are not lined up properly even tho they are the same width

body {
font: 18px/1.1em "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #ffffff;
}
a {
font: 18px/1.1em "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #ffffff;
text-decoration: none;
}
.container {
margin: auto;
margin-top: 5%;
width: 1280px;
height: 800px;
background-image: url(../img/background.jpg);
overflow: hidden;
}
.content {
margin: 100px 0 164px 170px;
}
.logo a {
font-size: 65px;
font-weight: 200;
line-height: 26px;
}
.main {
margin-top: 94px;
}
.main li {
background-position: center center;
background-repeat: no-repeat;
display: inline-block;
height: 150px;
width: 150px;
margin-right: 10px;
margin-bottom: 10px;
}
.main li.home {
background-color: #3387ea;
background-image: url(../img/home.png);
width: 150px;
height: 150px;
}
.main li.about {
background-color: #f9be3e;
background-image: url(../img/about.png);
width: 150px;
height: 150px;
}
.main li.portfolio {
background-color: #d3573e;
background-image: url(../img/portfolio.png);
width: 280px;
height: 150px;
}
.main li.photos {
background-color: #59b0e2;
background-image: url(../img/photos.png);
width: 150px;
height: 150px;
}
.main li.testimonials {
background-color: #33af95;
background-image: url(../img/testimonials.png);
width: 150px;
height: 150px;
}
.main li.hire {
background-color: #86a73f;
background-image: url(../img/hire.png);
width: 310px;
height: 150px;
}
.main li.blog {
background-color: #151a26;
width: 440px;
height: 150px;
}
.main li.contact {
background-color: #7e5b8c;
background-image: url(../img/contact.png);
width: 150px;
height: 150px;
}
The bottom 's are not lined up with top ones even though they match each other in total width.
Each has a margin-right 10px and margin-bottom 10px.
I am using reset style sheet to remove browser setting.
I cannot think of anything that will not allow it to align properly.
Codepen
Please help. Thank you!
This is because the white-space between inline block elements (in this case, the list items) also tabs and new lines between HTML elements are count as a white space.
You could either use CSS float or just remove the white space as follows:
EXAMPLE HERE
.main ul {
font: 0/0 a; /* Set font-size and line-height to 0 for the container */
}
.main li {
/* Then reset the valid value on list items */
font: 18px/1.1em "Helvetica Neue", Helvetica, Arial, sans-serif;
/* other declarations */
}
There are couple of ways to remove the space between inline(-block) elements:
Minimized the HTML
Negative margins
Comment the white space out
Break the closing tag
Set the font size of the parent to zero then reset that for children
Float the inline items instead
Use flexbox
Your choice.
That's because there's still a space between your tiles.
To solve this, make your hire me tile's width 315px.

how to make the div fits all of it's width?

i have a html div that is styled with css, this div contains some data(a string), and although setting the div width the same as the width of another div (25%) but the div only wraps the text that is written inside it while the other div fits the specified area perfectly.
the div with the problem :
.item_name {
background-color: #F30;
position: absolute;
height: 15%px;
width: 25%px;
background-repeat: repeat;
background-position: center center;
top: 0px;
font-family: Verdana, Geneva, sans-serif;
font-size: 18px;
line-height: 35px;
color: #FFFFFF;
}
the other div:
.item_block {
background-origin:content-box;
background-color:#FFECC1;
height: 20%;
width: 25%;
line-height: 450px;
font-family: Arial, Helvetica, sans-serif;
text-indent: 0px;
vertical-align: middle;
text-align: center;
position: relative;
float: left;
margin-top: 5px;
margin-right: 5px;
margin-bottom: 5px;
margin-left: 5px;
}
here's a JSfiddle contains my code
I think this has got to be the problem :
height: 15%px;
width: 25%px;
in class .item_name
Change it to
height: 15%;
width: 25%;
and add this to you css :
html, body {
height:100%;
width:100%;
margin:0;
padding:0;
}
this should do pretty much as the parent element has dimension set, child will inherit it in %age!!

Vertically Center HTML Element Within a Div of Dynamic Height [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
vertical-align: middle doesn't work
How can i make sure that the <a></a> is vertically centered in this div, regardless of the size of the div:
http://jsfiddle.net/XF9WM/
Thanks
Using display:table and display:table-cell, which works in all modern browsers (IE 8+):
.post {
width: 200px;
height: 200px;
background: rgba(0,0,0,0.8);
display:table;
}
.post h2 {
text-align: center;
width: 100%;
height: 100%;
display:table-cell;
vertical-align: middle;
}
.post h2 a {
color: #f7f7f7;
font-size: 2.2em;
font-weight: normal;
font-style: italic;
width: 100%;
}
I wanted to achieve it in a different way, (just for fun), and this one is working too:
jsFiddle
The idea is using a :before block element of 50% height.
html, body{
height:100%;
}
.post {
width: 400px;
height: 300px;
background: rgba(0,0,0,0.8);
}
.post h2:before{
content:"";
display:block;
height:50%;
}
.post h2 {
text-align:center;
height:100%;
}
.post h2 a {
color: #f7f7f7;
font-size: 2.2em;
margin-top:-20px;
display: block;
}
Hope it helps :-)
Give your link a line-height larger than the text will ever be, and vertically align it in the middle. Then absolutely position it's parent within the div to be at top: 50% and margin top minus half the link's line-height:
jsFiddle
.post {
position: relative;
}
.post h2 {
text-align: center;
width: 100%;
position: absolute;
top: 50%;
margin-top: -150px;
}
.post h2 a {
vertical-align: middle;
line-height: 300px;
white-space: nowrap;
}
It even works in IE7.
[UPDATED]
You can also do it like this: jsFiddle
.post {
width: 400px;
height: 200px;
background: rgba(0,0,0,0.8);
position:relative;
}
.post h2 {
position:absolute;
top:50%;
width:100%;
text-align:center;
}
.post h2 a {
line-height:100%;
color: #f7f7f7;
font-size: 2.2em;
margin-top:-20px;
display: block;
}
If you don't mind adding an extra HTML class, your simplest way is just to use vertical-align: middle.
http://jsfiddle.net/Wexcode/HtNJM/
<div class="post">
<span></span><h2>Hello!</h2>
</div>
CSS:
* { margin: 0; padding: 0; }
.post {
background: rgba(0,0,0,0.8);
width: 200px;
height: 200px; }
.post span {
height: 100%;
vertical-align: middle;
display: inline-block; }
.post h2 {
position: relative;
text-align: center;
width: 100%;
vertical-align: middle;
display: inline-block; }
.post h2 a {
color: #f7f7f7;
font-size: 2.2em;
font-weight: normal;
font-style: italic;
display: block; }

Resources