how to center a div inside the header from the top - html

I have a header it contains two divs [ left div and right div ] and offset 4-cols before them . What i want is to make the right div at the middle of the header .
.header
{
background-color: #FFF;
padding: 15px;
}
.header .left img { width: 90%; }
.header .right > div { display: inline-block; }
.header .right span { color: #0095AE }
.header .right > span:first-child { font-size: 22px; }
.header .right > div p
{
font-weight: bold;
font-size: 13px;
margin:0;
padding: 0;
color: #0095AE
}
.header .right > div p:first-child { text-align: right }
<div class="header">
<div class="row">
<div class="col-md-4 col-md-offset-4 ">
<div class="left">
<img class ="logo" src="images/logo.png">
</div>
</div>
<div class="col-md-4 ">
<div class="right">
<span>By</span>
<img src="images/crescent.png" >
<div>
<p> الهلال الأحمر الأردني </p>
<p> JORDAN RED CRESCENT </p>
</div>
</div>
</div>
</div>
</div>
This how it looks , I tried padding 50% but doesn't work as what i want.
enter image description here

Not sure how exactly you want it. But from what i understand ,you can make use of display:flex here
check this snippet
.header {
background-color: #FFF;
padding: 15px;
}
.row {
display: flex;
justify-content: center;
}
.col-md-4 {
display: flex;
}
.col-md-4:last-child {}
<div class="header">
<div class="row">
<div class="col-md-4 col-md-offset-4 ">
<div class="left">
<img class="logo" src="images/logo.png">
</div>
</div>
<div class="col-md-4 ">
<div class="right">
<span>By</span>
<img src="images/crescent.png">
<div>
<p>الهلال الأحمر الأردني</p>
<p>JORDAN RED CRESCENT</p>
</div>
</div>
</div>
</div>
</div>
Hope this helps

Related

Struggling with positioning divs around page

I've been working on this for days and feel like I've tried everything. Not sure if it's just something small that I'm missing or if I'm completely off track. I need to position my divs on the page like in this image the code I've got so far is this.
HTML:
body {
margin: 0px;
padding: 0px;
width: 1024px;
height: 768px;
float: left;
}
.pagebanner {
height: 200px;
width: 1024px;
}
.header {
background-color: aqua;
height: 50px;
margin-top: 0px;
padding-left: 200px
}
.navbar {
background-color: brown;
float: left;
height: 768px;
}
.subheading {
background-color: chartreuse;
padding-left: 420px;
margin-top: 0px
}
.content {
background-color: crimson;
height:
}
.footer {
background-color: darkgreen;
padding: 20px;
margin-bottom: 0px
}
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>The Club Site</title>
</head>
<body>
<div wrapper="mainwrapper">
<div class="pagebanner"><img src="HTML Pract A/images/banner.jpg" alt="PageBanner" width="1024px" height="200px">
<div class="navbar">
<ul>
<li></li>
<li></li>
</ul>
</div>
<div class="header">
<h1 class="header">The Club Site</h1>
</div>
<div class="subheading">
<h2>Members Prices</h2>
</div>
<div class="content">
</div>
<div class="footer">
<p>blah blah blah</p>
</div>
</div>
</body>
</html>
Any help with this would be greatly appreciated. First time trying to use HTML and I'm not having much luck with it.
In this sample i try to introduction bootstrap framework to you, bootstrap can help you to make a lot of html templates with less time, try t read documentation of this framework and you will figure out how it's easy.
Good luck with it and always before you ask something search about it,
i'm sure you will get solved questions.
This sample based on bootstrap 4 framework
.nav {
background-color: #ccc;
min-height: 500px;
}
.header {
background-color: #eee;
}
.sub-header {
background-color: yellow;
margin-bottom: 15px;
}
.item {
border: solid 1px #ccc;
text-align: center;
height: 150px;
margin-bottom: 15px;
}
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>The Club Site</title>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col">
<h1>header</h1>
</div>
</div>
<div class="row">
<div class="col-4 nav">
<h3>nav</h3>
</div>
<div class="col-8">
<div class="row">
<div class="col header">
<h3>The Club Site</h3>
</div>
</div>
<div class="row">
<div class="col sub-header">
<h6>sub header</h6>
</div>
</div>
<div class="row">
<div class="col-4">
<div class="item">
<h4>item 1</h4>
</div>
</div>
<div class="col-4">
<div class="item">
<h4>item 2</h4>
</div>
</div>
<div class="col-4">
<div class="item">
<h4>item 3</h4>
</div>
</div>
<div class="col-4">
<div class="item">
<h4>item 4</h4>
</div>
</div>
<div class="col-4">
<div class="item">
<h4>item 5</h4>
</div>
</div>
<div class="col-4">
<div class="item">
<h4>item 6</h4>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
<header>Header</header>
<div id="main">
<article>
<div class="my-container">
<div class="image">
<img src="https://www.placebacon.net/400/300">
</div>
<div class="image">
<img src="https://www.placebacon.net/400/300">
</div>
<div class="image">
<img src="https://www.placebacon.net/400/300">
</div>
<div class="image">
<img src="https://www.placebacon.net/400/300">
</div>
<div class="image">
<img src="https://www.placebacon.net/400/300">
</div>
</div>
</article>
<nav>Nav</nav>
</div>
<footer>Footer</footer>
<style>
* {
box-sizing: border-box;
}
body {
display: flex;
min-height: 100vh;
flex-direction: column;
margin: 0;
}
#main {
display: flex;
flex: 1;
}
#main > article {
flex: 1;
order: 1;
}
#main > nav,
#main > aside {
flex: 0 0 20vw;
}
#main > nav {
background: #D7E8D4;
order: 3;
}
header, footer {
background: yellowgreen;
height: 20vh;
}
header, footer, article, nav, aside {
padding: 1em;
}
.my-container {
display: flex;
flex-flow: row wrap;
align-content: flex-start; /* pack wrapping lines to the top */
width: 100%;
height: 300px;
}
.image {
flex: 0 0 30%;
margin: 5px;
}
img {enter code here
max-width: 100%;
}
</style>
Note: try to learn instead copy & paste it, to start try to write codes again.
I change and also add some css class in your codes, so pay-attention to different between old version and new css and html files.
Description: for start modeling your style you need to separate all partsyou need; for example here we need:
Header
Header > image
main > nav
main > content
main > content > header
main > content > subheading
main > content > area
main > content > area > items
main > content > area > items > item
etc...
and then start to html them, insert your div or what you want, and last step is manage them with css.
body {
margin: 0px;
padding: 0px;
}
.mainwrapper {
width: 1024px;
margin: 0 auto;
}
.pagebanner {
height: 250px;
margin: 0;
}
.pagebanner img {
width: 100%;
height: 100%;
}
.main {
margin: 0;
}
.navbar {
background-color: brown;
min-height: 500px;
width: 20%;
float: left;
}
.navbar li {
list-style: none;
margin-bottom: 15px;
}
.navbar a {
color: #fff;
font-size: 20px;
}
.content {
width: 80%;
float: left;
padding: 0;
min-height: 500px;
}
.header {
background-color: #000;
text-align: center;
}
.header h1 {
color: #fff;
margin: 0;
}
.subheading {
background-color: #f8d631;
text-align: center;
}
.subheading h2 {
background-color: #f8d631;
margin: 0;
}
.area h3 {
margin: 0;
text-align: center;
}
.item {
width: 33.33333333333333%;
float: left;
text-align: center;
}
.item div {
padding: 0 15px;
}
.item img {
height: 150px;
width: 100%;
}
.footer {
background-color: darkgreen;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<div class="mainwrapper">
<div class="pagebanner">
<img src="https://cdn-images-1.medium.com/max/1400/1*278tqw9zNPe2WCAz29Wzdw.jpeg" alt="PageBanner">
</div>
<div class="main">
<div class="navbar">
<ul>
<li>
Information
</li>
<li>
Home
</li>
</ul>
</div>
<div class="content">
<div class="header">
<h1>The Club Site</h1>
</div>
<div class="subheading">
<h2>Members Prices</h2>
</div>
<div class="area">
<h3>discounted Items</h3>
<div class="items">
<div class="item">
<div>
<img src="https://storage.googleapis.com/material-design/publish/material_v_12/assets/0Bx4BSt6jniD7VG9DQVluOFJ4Tnc/materialdesign-principles-metaphor.png" />
<h4>name - %200</h4>
</div>
</div>
<div class="item">
<div>
<img src="https://storage.googleapis.com/material-design/publish/material_v_12/assets/0Bx4BSt6jniD7VG9DQVluOFJ4Tnc/materialdesign-principles-metaphor.png" />
<h4>name - %200</h4>
</div>
</div>
<div class="item">
<div>
<img src="https://storage.googleapis.com/material-design/publish/material_v_12/assets/0Bx4BSt6jniD7VG9DQVluOFJ4Tnc/materialdesign-principles-metaphor.png" />
<h4>name - %200</h4>
</div>
</div>
<div class="item">
<div>
<img src="https://storage.googleapis.com/material-design/publish/material_v_12/assets/0Bx4BSt6jniD7VG9DQVluOFJ4Tnc/materialdesign-principles-metaphor.png" />
<h4>name - %200</h4>
</div>
</div>
<div class="item">
<div>
<img src="https://storage.googleapis.com/material-design/publish/material_v_12/assets/0Bx4BSt6jniD7VG9DQVluOFJ4Tnc/materialdesign-principles-metaphor.png" />
<h4>name - %200</h4>
</div>
</div>
<div class="item">
<div>
<img src="https://storage.googleapis.com/material-design/publish/material_v_12/assets/0Bx4BSt6jniD7VG9DQVluOFJ4Tnc/materialdesign-principles-metaphor.png" />
<h4>name - %200</h4>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

Bootstrap Add Space between Columns

I have closely followed the most popular example of how to add space between columns, but it doesn't work. You can view it in action at
codepen.io
What I've done is put a col-sm-12 inside of a col-sm-4 for each column. According to the most popular answer here this should automatically render some space between the 2 divs.
HTML:
<div class="row blocks-grid">
<div class="col-xs-6 col-sm-4 item">
<div class="col-sm-12">
<img src="http://example.com/1MBVDF4">
<h2>This is me</h2>
</div>
</div>
<div class="col-xs-6 col-sm-4 item">
<div class="col-sm-12">
<img src="http://example.com/1MBVDF4">
<h2>This is me</h2>
</div>
</div>
<div class="col-xs-6 col-sm-4 item">
<div class="col-sm-12">
<img src="http://example.com/1MBVDF4">
<h2>This is me</h2>
</div>
</div>
</div>
CSS:
body {
background: #BEB7A4;
}
.blocks-grid {
max-width:75.0rem;
margin:0 auto;
.item {
cursor: pointer;
margin-bottom:1rem;
position:relative;
height:34.0rem;
padding-top:2.5rem;
background:#FFFFFC;
&:hover {
background:#FF0000;
color:white;
img {
display:none;
}
}
h2 {
font-size:2.0rem;
margin-top:1rem;
text-align: center;
}
img {
max-width: 100%;
margin:auto;
display:block;
}
}
}
Basically, I would think the result would look like the following photo, but it does not:
you can try this: Demo
Add your "item" class with "col-sm-12"
body {
background: #BEB7A4;
}
I made some changes on your code.
HTML
Note the subitem class added to col-sm-12 divs.
<div class="row blocks-grid">
<div class="col-sm-4 item">
<div class="col-sm-12 subitem">
<img src="image_url">
<h2>This is me</h2>
</div>
</div>
<div class="col-sm-4 item">
<div class="col-sm-12 subitem">
<img src="image_url">
<h2>This is me</h2>
</div>
</div>
<div class="col-sm-4 item">
<div class="col-sm-12 subitem">
<img src="image_url">
<h2>This is me</h2>
</div>
</div>
</div>
LESS
body {
background: #BEB7A4;
}
.blocks-grid {
max-width:75.0rem;
margin:0 auto;
.item {
cursor: pointer;
margin-bottom:1rem;
position:relative;
height:34.0rem;
padding-top:2.5rem;
.subitem {
background:#FFFFFC;
height: 100%;
padding-top: 50px;
&:hover {
background:#FF0000;
color:white;
img {
display:none;
}
}
h2 {
font-size:2.0rem;
margin-top:1rem;
text-align: center;
}
img {
max-width: 100%;
margin:auto;
display:block;
}
}
}
}
Take a look: http://codepen.io/anon/pen/KgzVRK
Hope it can helps you.
You can actually remove all the extra junk and let bootstrap do it for you... NEVER change margins / widths on the framework. This is all you need....
HTML
<div class="row">
<div class="col-xs-6 col-sm-4">
<img src="http://placehold.it/350x250">
<h2>This is me</h2>
</div>
<div class="col-xs-6 col-sm-4">
<img src="http://placehold.it/350x150">
<h2>This is me</h2>
</div>
<div class="col-xs-6 col-sm-4">
<img src="http://placehold.it/350x150">
<h2>This is me</h2>
</div>
</div>
CSS
img { width: 100%; }
You may try to move the class item from col-xs-6 to col-sm-12
The snippet:
body {
background: #BEB7A4;
}
.blocks-grid {
max-width: 75.0rem;
margin: 0 auto;
}
.blocks-grid .item {
cursor: pointer;
margin-bottom: 1rem;
position: relative;
height: 34.0rem;
padding-top: 2.5rem;
background: #FFFFFC;
}
.blocks-grid .item:hover {
background: #FF0000;
color: white;
}
.blocks-grid .item:hover img {
display: none;
}
.blocks-grid .item h2 {
font-size: 2.0rem;
margin-top: 1rem;
text-align: center;
}
.blocks-grid .item img {
max-width: 100%;
margin: auto;
display: block;
}
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css'>
<style>
body {
background: #BEB7A4;
}
.blocks-grid {
max-width: 75.0rem;
margin: 0 auto;
}
.blocks-grid .item {
cursor: pointer;
margin-bottom: 1rem;
position: relative;
height: 34.0rem;
padding-top: 2.5rem;
background: #FFFFFC;
}
.blocks-grid .item:hover {
background: #FF0000;
color: white;
}
.blocks-grid .item:hover img {
display: none;
}
.blocks-grid .item h2 {
font-size: 2.0rem;
margin-top: 1rem;
text-align: center;
}
.blocks-grid .item img {
max-width: 100%;
margin: auto;
display: block;
}
</style>
</head>
<body>
<div class="row blocks-grid">
<div class="col-xs-6 col-sm-4">
<div class="col-sm-12 item">
<img src="https://www.samhober.com/howtofoldpocketsquares/Flat1.jpg">
<h2>This is me</h2>
</div>
</div>
<div class="col-xs-6 col-sm-4">
<div class="col-sm-12 item">
<img src="https://www.samhober.com/howtofoldpocketsquares/Flat1.jpg">
<h2>This is me</h2>
</div>
</div>
<div class="col-xs-6 col-sm-4">
<div class="col-sm-12 item">
<img src="https://www.samhober.com/howtofoldpocketsquares/Flat1.jpg">
<h2>This is me</h2>
</div>
</div>
</div>
</body>

Bootstrap creates some sort of margin

When using bootstrap to build the base of a website it creates some weird black, the black color is the body's color, margin on the right side of the header.
HTML:
<section id="header">
<div class="row">
<div class="content-wrapper">
<div class="col-md-6">
<div class="left">
<img src="#" alt="">
</div>
</div>
<div class="col-md-6">
<div class="right">
<nav>
<ul>
<li>a</li>
<li>b</li>
<li>c</li>
</ul>
</nav>
</div>
</div>
</div>
</div>
</section>
<section id="featured">
<div class="row">
<div class="col-md-4 box yellow">
</div>
<div class="col-md-4 box blue">
</div>
<div class="col-md-4 box red">
</div>
</div>
<div class="row">
<div class="col-md-4 box green">
</div>
<div class="col-md-4 box gray">
</div>
<div class="col-md-4 box white">
</div>
</div>
</section>
CSS:
body {
background: #000;
}
.content-wrapper {
max-width: 1100px;
margin: 0 auto;
}
.left {
float: left;
}
.right {
float: right;
}
section#header {
background: white;
height: 150px;
}
nav ul li {
display: inline-block;
}
.yellow {
background: yellow;
}
.red {
background: red;
}
.blue {
background: blue;
}
.green {
background: green;
}
.gray {
background: gray;
}
.white {
background: white;
}
.box {
height: 250px;
}
Here's a jsfiddle: http://jsfiddle.net/awu2cp6a/
The black on the right side is the background color.
The reason you only see it there is, because .row has margin-left/right: 15px;. If you remove/overwrite this to 0px, the black disappears or you add the row class to the element with the image.
EDIT
So if you would have an image, it would be OVER the black area, but because there is no image that fits in the full size, it's not displaying. Have you tryed give your section the row class?

Centering images with text as menu

Im trying to put together some images together with an text under the images which will work as an menu, which should be centered horizontal under an header. The website is supposed to work as an responsive website. The HTML and CSS code is currently looking like this:
Edited
I want 5 images, each one of them shall have a text under them. And I want the my images together with the text to be centered.
HTML
<nav>
<div id="content">
<img src="ikoner/icon_90_2.png"/>
<div class="text">Utvecklingen sedan 90-talet</div>
</div>
<div id="content">
<img src="ikoner/icon_html5.png"/>
<div class="text">HTML5</div>
</div>
<div id="content">
<img src="ikoner/icon_html5video.png"/>
<div class="text">HTML5 Video</div>
</div>
<div id="content">
>img src="ikoner/icon_responsive.png"/>
<div class="text">Responsive Webdesign</div>
</div>
<div id="content">
<img src="ikoner/icon_heart.png"/>
<div class="text">Emotional Design</div>
</div>
</nav>
CSS
#content {
position: relative;
width: 15%;
display: inline-block;
text-align: center;
margin-left: auto;
margin-right: auto;
}
#content img {
padding-top: 370px;
width: 100px;
}
.text {
font-size: 12px;
font-family: 'ciclethin';
text-decoration: none;
}
You're not aligning your "Nav" div anywhere.
So, I've changed the id="content" to classes, because IDs should be unique to the page.
Set nav element to text-align:center. Here's a fiddle, and the relevant code:
http://jsfiddle.net/cw16tkdn/2/
<nav>
<div class="content">
<img src="http://placekitten.com/g/200/200" />
<div class="text">Utvecklingen sedan 90-talet
</div>
</div>
<div class="content">
<img src="http://placekitten.com/g/200/200" />
<div class="text">HTML5
</div>
</div>
<div class="content">
<img src="http://placekitten.com/g/200/200" />
<div class="text">HTML5 Video
</div>
</div>
<div class="content">
<img src="http://placekitten.com/g/200/200" />
<div class="text">Responsive Webdesign
</div>
</div>
<div class="content">
<img src="http://placekitten.com/g/200/200" />
<div class="text">Emotional Design
</div>
</div>
</nav>
and CSS:
nav {
text-align:center;
}
.content {
display: inline-block;
text-align: center;
}
.content img {
width: 100px;
}
.text {
font-size: 12px;
font-family:'ciclethin';
text-decoration: none;
}
maybe you want this: (i have changed id=content with class=content in html code!)
.content {
position: relative;
width: 100px;
display: inline-block;
height: 520px;
text-align: center;
vertical-align:bottom;
}
.content img {
padding-top: 370px;
width: 100px;
display:block;
margin: auto;
}
.text a {
font-size: 12px;
font-family: 'ciclethin';
text-decoration: none;
}
.text {
height: 3em;
}

Need help on css header float

When i do my web design, meet a problem when i need to do
[LEFT LOGO] then [TITLE(CENTER)] then [RIGHT LOGO]
The problem appear at RIGHT LOGO there, it doesn't align with LEFT LOGO.
The right logo is under the line of TITLE(CENTER)
here is my code sample, thanks:
<div class="navigation">
<div id="left">
<a title="Multimedia" href="#">
<img src="images/logo.png"/>
</a>
</div>
<div id="title">Tutor Program</div>
<div id="right">
<a href="#" title="Inspire and Innovate">
<img src="images/tagline_alt.png"/>
</a>
</div>
css:
.navigation{
height:auto;
background-color:#666;
width:85%;
margin:auto;
min-width:800px;
}
#title{
text-align:center;
margin: auto;
font-family:‘Arial Black’, Gadget, sans-serif;
font-size: 20px;
color: #FFF;
}
#left {
float: left;text-align:left;
margin: auto;
}
#right {
float: right;text-align:right;
margin: auto;
}
a img { border: 0; }
simply move the right container above the left container check below
<div class="navigation">
<div id="right">
<a href="#" title="Inspire and Innovate">
<img src="images/tagline_alt.png"/>
</a>
</div>
<div id="left">
<a title="Multimedia" href="#">
<img src="images/logo.png"/>
</a>
</div>
<div id="title">Tutor Program</div>
</div>
I thing its work an another way i have some changes in style width depends of logo width. if it is not set in center then change the width %.
#title{
text-align:center;
margin: auto;
font-family:'Arial Black', Gadget, sans-serif;
font-size: 20px;
color: #FFF;
width:59%;
float:left;
}
.clear {
clear:both;
margin:0px;
font-size:0px;
}
and add a div after the last div with class clear.
<div id="right"> .... </div>
<div class="clear"> </div>
You could also display your divs as a table and table-cells, like this:
HTML
<div class="navigation">
<div id="left">
left
</div>
<div id="title">
title
</div>
<div id="right">
right
</div>
</div>
CSS
.navigation {
width: 100%;
display: table;
table-layout: fixed;
}
.navigation > div {
display: table-cell;
}
.navigation div:nth-child(1) {
background: lightgray;
}
.navigation div:nth-child(2) {
background: gray;
text-align: center;
}
.navigation div:nth-child(3) {
background: lightgray;
text-align: right;
}
Also check the JSFiddle Demo