I need to make responsive header with H1, UL menu and H2.
The H1 - about 5% from the left corner. The H2 - about 5% from right corner. And between them is UL menu, which I need to place in the center. Everything in one line... And HR line under this line.
How to position UL menu in the CENTER ?
jsFiddle EXAMPLE
HTML :
<div class="container">
<header class="clearfix">
<!-- TITLE 1 -->
<h1>Title 1 </h1>
<!-- UL -->
<ul>
<li> menu 1</li>
<li> menu 2</li>
<li> menu 3</li>
</ul>
<!-- TITLE 2 -->
<h2>Title 2 <br/><span>span</span></h2>
<hr />
</header>
</div>
CSS :
.container > header {
width: 90%;
margin: 0 auto;
position: relative;
padding: 40px 30px 20px 30px;
}
.container > header h1 {
padding-left: 5px;
font-size: 30px;
line-height: 37px;
margin: 0 auto;
font-weight: 700;
color: #000;
display:inline !important;
float: left;
}
.container > header h2 {
padding-right: 5px;
font-size: 14px;
line-height: 14px;
margin: 0px 0px 0px auto;
font-weight: 700;
color: #000;
display:inline !important;
float: right;
text-align: right;
}
.container > header h2 span {
font-size: 10px;
line-height: 11px;
font-weight: 700;
color: #000;
}
.container > header ul {
font-size: 10px;
line-height: 11px;
font-weight: 700;
color: red;
}
.container > header ul li {
float: left;
list-style-type: none;
padding: 0px 5px 0px 5px;
}
.container > header hr {
border:0;
color:#000;
background:#000;
height:1px;
clear: both;
}
You can use floated divs and text-align to achieve this. Here's the HTML:
<header>
<div class="left">Left</div>
<div class="center">Center</div>
<div class="right">Right</div>
</header>
And the CSS to align them properly:
.left { float: left; width: 25% }
.center { float: left; width: 50%; text-align: center; }
.right { float: left; width: 25%; text-align: right; }
Here's a jsFiddle demo.
Related
I tried to make a responsive header for my website, it's all ok, but i can not set the margins of the links to 0. You cand see in the image: https://imgur.com/s5EzL6n
What i want to achieve is to make all that grey background 100% width.
I followed this youtube video: https://www.youtube.com/watch?v=lYw-FE60Dws
I probably set some things wrong, i am sure, but i am a beginner.
HTML:
<header>
<div class="container">
<div id="branding">
<img src="logo.png">
<a class="toggle">Meniu</a>
</div>
<nav>
<ul class="active">
<li class="current">Acasă</li>
<li>Despre</li>
<li>Servicii</li>
<li>Proiecte</li>
<li>Contact</li>
</ul>
</nav>
</div>
</header>
CSS:
/* responsive header*/
.toggle{
display: none;
position: absolute;
right: 10px;
top: 26px;
padding: 5px;
cursor: pointer;
text-decoration: none;
}
#media (max-width: 940px){
.toggle{
display: block;
}
header .toggle{
padding: 0 0;
font-size: 18px;
}
header ul li{
display: block;
width: 100%;
background-color: grey;
}
header ul.active{
display: block;
}
header ul li a{
display: block;
text-align: center;
}
header nav{
margin: 0;
width: 100%;
}
header ul li{
width: 100%;
}
}
/*normal page*/
header a{
color: #fcfcfc;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
padding-right: 25px;
}
header li{
float: left;
display: inline;
padding: 0 20px 0px 20px;
}
header #branding{
float: left;
height: 90px;
margin-left: 35px;
}
header a{
color: #fcfcfc;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
padding-right: 25px;
}
there is a default padding for ul, you have to remove it when you don't need it. Just add 0px to the ul and you will have a 100% div
Try to use css box models to solve such cases
https://www.youtube.com/watch?v=xF0dhepbzD8
This is my current code and the problem now is that image3, which is the 2nd box is not showing the correct height... The following is the updated code for my style.css:
body {
margin: 0;
padding: 0;
font-family: 'Arial', 'serif';
}
.nav {
background-color: #ffffff;
color: #000000;
list-style: none;
text-align: right;
padding: 20px 0 0 0;
}
.nav > li {
display: inline-block;
padding-right: 50px;
font-size: 12px;
}
.nav > li > a {
text-decoration: none;
color: #000000;
}
.nav > li > a:hover {
color: #c1c1c1;
}
.logo {
color: black;
float: left;
padding-left: 25px;
font-size: 12px;
font-weight: bold;
}
.logo > a {
text-decoration: none;
color:black;
}
.banner {
width: 100%;
display:block;
}
.banner > .banner-image {
width: 100%;
display: block;
height: 700;
}
.service1 {
width: 298px;
border: 1px solid #c1c1c1;
margin: 20px 10px;
padding: 0 5px;
float: left;
}
.service1 > p {
font-size: 14px;
color: #636363;
max-width: 200px;
text-align: justify;
}
.services {
width: 1500px;
margin:0 auto;
}
h1 {
font-size: 16px;
font-weight: bold;
background-color: #c1c1c1;
color: #ffffff;
padding: 10px 0;
margin: 0 -6px;
}
.image {
max-width: 135px;
margin: 15px 0 0 0;
}
.heading {
text-align:center;
font-size: 25px;
color: #000000;
margin:100px 0 50px 0;
font-weight: bold;
}
.service1 > image1 {
max-width: 120;
margin: 15px 0 0 0;
}
.service1 > image3 {
max-width: 120;
margin: 15px 0 15px 0;
}
.image:hover {
opacity: 0.2;
max-width: 200px;
margin-top:15px;
}
.image1:hover {
opacity: 0.2;
max-width: 200px;
margin-top:15px;
}
.message {
text-align: center;
font-size: 30px;
font-weight: bold;
}
.message ul {
text-align: center;
list-style-position: inside;
}
This is my index.html code:
<!DOCTYPE>
<html>
<head>
<link rel="stylesheet" type ="text/css" href="style.css">
<title>Pianocourse101</title>
</head>
<body>
<ul class="nav">
<div class="logo">
Pianocourse101
</div>
<li><a href="http://localhost/pianocourse101/register.php">Register</li>
</a>
<li>Login</li>
<li>About Me</li>
<li>Contact Us</li>
<div class="banner">
<img class="banner-image" src="images/mervin.gif">
</div>
<br></br>
<br></br>
<div class="message">
<p> At Pianocourse101, you will learn the following</p>
<ul>
<li>Basic hand positions</li>
<li>Posture</li>
<li>Rhythm</li>
<li>Finger numbers</li>
<li>Letter names</li>
</ul>
</div>
<div class="heading">Services</div>
<div align="center" class="services">
<div class="service1">
<h1>Download Section: Primer Level</h1>
<img class="image1" src="images/treble.png">
<p>Access full contents for just <strong>$50!</strong> Learn the
basic hand positions, finger numbers and letter names!</p>
</div>
<div class="service1">
<h1>Download Section: Level 1</h1>
<img class="image3" src="images/bass.jpg">
<p>Access full contents for just <strong>$100!</strong> Learn some
advanced pieces, slurs and staccatos!</p>
</div>
<div class="service1">
<h1>Download Section: Level 2</h1>
<img class="image" src="images/crotchet.png">
<p>Access full contents for just <strong>$150!</strong> Progress and
play some more advanced pieces hands together!</p>
</div>
<div class="service1">
<h1>Download Section: Level 3</h1>
<img class="image2" src="images/bass.jpg">
<p>Access full contents for just <strong>200!</strong> Feeling more
confident and need a challenge? Level 3 will provide you with more
challenging pieces!</p>
</div>
</div>
<section>
</section>
<footer>
</footer>
</body>
</html>
I am not sure why I have to add more comments but I can't figure out why my second box is not lining up correctly...
/* CSS alignment is read as top, left, bottom, right*/
I'm creating a page that looks like this:
Here is the code
body { min-height: 50vh;
line-height: 1;
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
margin: 0;
padding: 0;
}
#headlogo{
position: absolute;
top: 12px;
margin: 0 auto;
font-weight: bold;}
#header {
padding: 0;
background-color: #1565C0;
}
#header .section {
margin: 0 auto;
padding: 0;
width: 900px;
overflow: hidden;
}
#header .section ul {
display: inline-block;
float: right;
margin: 0;
overflow: hidden;
padding: 50px 0 10px;
}
#header .section ul li {
background: url(./images/headernav.gif) no-repeat top right;
display: inline-block;
float: left;
list-style: none;
margin: 0 10px;
padding: 0;
}
#header .section ul li a {
color: #fff;
display: inline-block;
font-size: 15px;
height: 30px;
line-height: 30px;
margin: 0;
padding: 0 8px;
text-align: center;
text-decoration: none;
font-weight: bold;
letter-spacing: 0.03em;
}
#header .section ul li a:hover {
background: url(./images/headernavselected.gif) no-repeat top right;
}
#header .section ul li.selected {
background: url(./images/headernavselected.gif) no-repeat top right;
}
#header .section ul li.selected a {
background: url(./images/headernavselected.gif) no-repeat top left;
color: #E3F2FD;
}
#body {
margin: 0 0;
background-color:#DEDEDE;
}
#body .section {
margin: 0 auto;
min-width: 800px;
width: 800px;
overflow: hidden;
background-color:#FFFFFF;
padding: 60px 100px 50px 100px;
min-height: 50vh
}
#footer {
background: #1565C0;
margin: 0;
padding: 0;
}
#footer .section {
margin: 0 auto ;
padding: 20px;
width: 800px;
overflow: hidden;
};
<div id="header">
<div class="section">
<img src="./images/headerlogo.png" width="340" height="110" alt="" title="">
<ul>
<li class="selected">
Home
</li>
<li>
Store
</li>
<li>
Products
</li>
<li>
Forum
</li>
<li>
Support
</li>
</ul>
</div>
</div>
<div id="body">
<div class="section">
Lorem ipsum
</div>
</div>
<div id="footer">
<div class="section">
© copyright 2023 | all rights reserved.
</div>
The CSS is available here:
http://jsfiddle.net/85L448ds/
But I don't know how to make the page more responsive to sizing inconsistency. I want the page to default to 800 pixels wide, except where there is wide content or the browser window is too small (it should have a gray background outside this area). Whereas the height should be such that the height should not be less than the browser height.
In other words, I'd like it to work something like:
Width = 800
If Width > Window_Width then
Width = Window_Width
If Content_Width > Width then
Width = Content_Width
Whereas height should be the greater of: Content_Height and Windows_Height.
Note: Content_Width/Height cannot be predicted because I have a forum where the table structure is sometimes oversize to accomodate large images.
I've tried setting the CSS min-width property to 800, but that makes the default width 100%.
I thought height would be easy, just need to set the body to 100% height or 100vh, but that seems to have no effect...
I believe CSS Media Queries will resolve your problem.
Of course it is possibly just one of the solutions, but it is purely CSS and really easy to manage.
For more information about media queries: http://www.w3schools.com/cssref/css3_pr_mediaquery.asp
Using media queries happens like in this following example, where your #headLogo is set to change its properties once the viewport width is less or equal to 768px:
#media (max-width: 768px)
{
#headLogo {
text-align: center;
max-width: 300px;
}
}
Run snippet in full page and then play with window size after reduce the size of window your menu will hide and one button you can see. now show menu on button click.
If you run snippet so at first time you can see button because your
window size is < 768px if you want see menu then see result in full page
for responsive site use width in % not in px.
and you can also use bootstrap for that.
body {
min-height: 50vh;
line-height: 1;
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
margin: 0;
padding: 0;
}
.smallButton{
display:none
}
#headlogo {
position: absolute;
top: 12px;
margin: 0 auto;
font-weight: bold;
}
#header {
padding: 0;
background-color: #1565C0;
width:100%;
height: 90px;
}
#header .section {
margin: 0 auto;
padding: 0;
overflow: hidden;
}
#header .section ul {
display: inline-block;
float: right;
margin: 0;
overflow: hidden;
padding: 50px 0 10px;
}
#header .section ul li {
display: inline-block;
float: left;
list-style: none;
margin: 0 10px;
padding: 0;
}
#header .section ul li a {
color: #fff;
display: inline-block;
font-size: 15px;
height: 30px;
line-height: 30px;
margin: 0;
padding: 0 8px;
text-align: center;
text-decoration: none;
font-weight: bold;
letter-spacing: 0.03em;
}
#header .section ul li a:hover {
background: url(./images/headernavselected.gif) no-repeat top right;
}
#header .section ul li.selected {
background: url(./images/headernavselected.gif) no-repeat top right;
}
#header .section ul li.selected a {
background: url(./images/headernavselected.gif) no-repeat top left;
color: #E3F2FD;
}
#body {
margin: 0 0;
background-color: #DEDEDE;
width:100%
}
#footer {
background: #1565C0;
margin: 0;
padding: 0;
width:100%;
}
#footer .section {
margin: 0 auto;
padding: 20px;
overflow: hidden;
}
#media (max-width: 768px)
{
#header .section ul {
display:none
}
.smallButton{
display:block;
position: absolute;
right: 0;
top: 32px;
}
#body .section {
margin: 0 auto;
overflow: hidden;
background-color: #FFF;
width: 500px;
height: 700px;
position: relative;
}
}
#media (min-width: 768px){
#body .section {
margin: 0 auto;
overflow: hidden;
background-color: #FFF;
width: 800px;
height: 700px;
position: relative;
}
}
<div id="header">
<div class="section">
<a href="index.html" id="headlogo">
</a>
<button class="smallButton">---</button>
<ul>
<li class="selected">
Home
</li>
<li>
Store
</li>
<li>
Products
</li>
<li>
Forum
</li>
<li>
Support
</li>
</ul>
</div>
</div>
<div id="body">
<div class="section">
Lorem ipsum
</div>
</div>
<div id="footer">
<div class="section">
© copyright 2023 | all rights reserved.
</div>
updated fiddle
You don't actually need media queries for that
html,
body {
width: 100%;
height: 100%;
}
will make body occupy all available space in window. It will shrink and expand with window re-size.
I am having a CSS issue, I have a div called 'current-property' and inside this div, I have a paragraph. What I am trying to do is what this paragraph at the bottom of the element at all times. Is this possible?
.current-property {
padding: 50px 0px 50px 0px;
clear: both;
min-height: 460px;
}
.current-property p {
float: left;
padding-left: 50px;
}
p {
text-align: left;
font-size: 18px !important;
font-weight: 400;
padding: 10px 0px;
color: #333;
line-height: 1.8;
}
.current-property img {
float: left;
width: 28%;
}
.current-property h2 {
float: left;
width: 60%;
text-align: left;
padding-left: 50px;
font-size: 32px;
}
.current-property ul {
padding-left: 80px;
list-style-type: disc;
padding-top: 10px;
}
.current-property ul li {
padding-bottom: 10px;
}
<div class="current-property">
<img src="images/commercial/default-image.png" class="animated" data-animation="fadeInLeft" data-animation-delay="300" />
<h2>123 Fake Street</h2>
<div class="property-info">
<ul>
<li>Location: Oakland</li>
<li>Up to 22,000 Sq. Ft.</li>
</ul>
<p>Call for Availability: 555-555-5555</p>
</div>
</div>
You can do this with positioning. Set the position on the div to relative, and absolute on the paragraph (background color added to visualize the div's space).
.current-property {
padding: 50px 0px 50px 0px;
clear: both;
min-height: 460px;
background: #ccc;
position: relative;
}
.current-property p {
float: left;
padding-left: 50px;
position: absolute;
bottom: 0;
}
p {
text-align: left;
font-size: 18px !important;
font-weight: 400;
padding: 10px 0px;
color: #333;
line-height: 1.8;
}
<div class="current-property">
<img src="images/commercial/default-image.png" class="animated" data-animation="fadeInLeft" data-animation-delay="300" />
<h2>123 Fake Street</h2>
<div class="property-info">
<ul>
<li>Location: Oakland</li>
<li>Up to 22,000 Sq. Ft.</li>
</ul>
<p>Call for Availability: 555-555-5555</p>
</div>
</div>
If I understand what your question is, you can just add display:blockto .property-info p like this:
.property-info p {display:block;}
This makes sure that it will take up the full width of the screen, and no elements will float or be inline to it.
EDIT
Add it to the p tag
Good Day
I am having a bad CSS day. I have 3-column div (horizontal, thats why I am using the float), but I want to align my text in the center, but to the left of the containing column div.
HTML:
<div id="footer">
<div class="footerColumn">
<ul>
<li><a>Contact Us</a></li>
<li><a>Home</a></li>
<li><a>Emergency Numbers</a></li>
</ul>
</div>
<div class="footerColumn">
<ul>
<li><a>Support</a></li>
<li><a>Privacy Policy</a></li>
<li><a>Terms of Use</a></li>
<li><a>Careers</a></li>
</ul>
</div>
<div class="footerColumn">
<ul>
<li><p><a>login</a></p></li>
<li><a>Sign Up</a></li>
</ul>
</div>
<div style="clear: both;"></div>
</div>
CSS:
#footer {
width: 960px;
margin: 0 auto;
padding: 10px;
background: url('/images/bg2.png') repeat-x center;
border-top: 6px solid #f3911f;
background: #1b1d21;
}
#footer div.footerColumn {
position: relative;
float: left;
width: 33%;
margin: 0 auto;
text-align: justify;
}
#footer div.footerColumn ul li {
}
#footer ul li a{
color: #fff;
font-family: Arial, sans-serif;
font-size: 14px;
text-decoration: none;
cursor: pointer;
}
#footer div.disclaimer {
color: #ccc;
font-family: verdana, Arial, sans-serif;
font-size: 12px;
}
SEE MY FIDDLE
Thank you
The reason why you are unable to center the <ul> element in your design is because the <li> elements are stretching the parent <ul> width to 100%, therefore using margin: 0 auto will not work.
Instead, I suggest that you use display: inline-block for your <ul> - allowing it to ONLY stretch as far as the width of inner contents (the child <li> elements), and not to the 100% width of the containing element.
As for the children <li>, you can set them to display as a block element, float them to the left and then clear the left float, therefore forcing each floated element to start on a new line (because you clear the left float for every element).
Simply implement the style suggested as follow:
#footer ul {
display: inline-block;
overflow: hidden;
}
#footer ul li {
display: block;
float: left;
clear: left;
}
#footer ul li a{
color: #fff;
font-family: Arial, sans-serif;
font-size: 14px;
text-decoration: none;
cursor: pointer;
}
Check the fiddle here ;) http://jsfiddle.net/teddyrised/DvXzB/48/
Use text-align:center in your footerColumn divs.
#footer div.footerColumn {
position: relative;
float: left;
width: 33%;
margin: 0 auto;
text-align: center;
}
#footer div.footerColumn {
position: relative;
float: left;
width: 33%;
margin: 0 auto;
text-align: center; /*new here*/
}
#footer div.footerColumn ul {
float: left; /*new here*/
}