Position h1 with border in center of picture - html

I am making a banner with Bootstrap 3, and the end result should look like this, and have a height off 350px;
A demoversion off the code I have until now can be seen here.
I am not sure how I can make the h1 and p tag align in the middle? At the moment they are at the top, and I cannot figure out how to position them.
When I look on < 768px the picture is way to big. Is that because of the cover in the header tag? How can I make that picture get smaller on < 768px?
header {
height:100vh;
background-image:url('https://img2.picload.org/image/daapipii/header-2.jpg');
background-size:cover;
background-position:center center;
background-attachment:fixed;
}
#media (max-width:767px) {
header {
/*height:100%;*/
background-attachment:inherit;
height:100vh;
}
}
header h1 {
/*background-color:rgba(255,255,255,0.36);*/
padding:10px;
text-align:center;
border:5px solid rgba(108,111,119,0.19);
/*box-shadow:0px 0px 1px #333;*/
}
header h1 {
font-family:'Aladin';
font-size:71px;
color:#fff;
text-shadow:1px 1px 1px #333;
}
#media (max-width:767px) {
header h1 {
font-size:41px;
}
}
header p {
text-align:center;
padding-top:20px;
font-size:26px;
font-weight:600;
font-family:'Source Sans Pro';
/*letter-spacing:2px;*/
color:#f5f5f5;
text-shadow:1px 1px 1px #111;
padding-bottom:20px;
}
#media (max-width:767px) {
header p {
font-size:17px;
}
}
header .row.no-space p {
text-align:right;
}
/* Social Media Position */
header .row.no-space {
margin-top:initial;
bottom:0px;
position:fixed;
right:20px;
}
header .fa {
color:#fff;
text-shadow:1px 1px 1px #333;
padding:7px;
}
<header>
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1 text-bg">
<h1>Welcome on free feelings</h1></div>
<div class="col-md-12">
<p>Animated header with scroll engine </p>
</div>
</div>
<div class="row hidden-xs no-space">
<div class="col-md-12">
<p>
<i class="fa fa-instagram"></i>
<i class="fa fa-facebook-official"></i>
<i class="fa fa-pinterest-square"></i>
</p>
</div>
</div>
</div>
</header>

To vertically center the content on the page, I would use CSS flexbox on your <header> element like this:
header {
display: flex;
align-items: center;
}
Regarding the size of the image, would it be acceptable to align the text to the top of the page on mobile?
If so, then I would suggest removing the height: 100vh and flexbox from the header on mobile. Instead you need a responsive image in relation to the screen width but since you are using a background image you can do this:
header {
background-image: url(...);
background-size: cover;
height: 0; /* Use padding-bottom to define height */
padding-bottom: 62%; /*Aspect ratio of image (h/w*100)*/
}

Add this at the bottom of your CSS:
body {
margin: 0
}
h1 {
position: absolute;
}
.text-bg {
display: flex;
justify-content: center;
}
.wrapper {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}

Doing this old school you can use the display: table approach (which is not what is recomended these days):
header {
height:100vh;
background-image:url('https://img2.picload.org/image/daapipii/header-2.jpg');
background-size:cover;
background-position:center center;
background-attachment:fixed;
display: table;
width: 100%;
}
.container {
display: table-cell;
vertical-align: middle;
}
The current recommended way usually is with Flex which is cleaner and nicer. If you want to keep all as is then you just change your header CSS to:
header {
height:100vh;
background-image:url('https://img2.picload.org/image/daapipii/header-2.jpg');
background-size:cover;
background-position:center center;
background-attachment:fixed;
display: flex;
align-items: center;
}

Related

How I can change my organization with flexbox only mobile version

In desktop version i have 3 divs side by side but in mobile version i would like to have 1 div on top and 2 div side by side how can i go about this with current code? do I have to make a hidden div in desktop version and display in mobile version?
I have drawn an example just below to explain what I want.
thank youu.
body,
html,
main {
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
color: white;
text-align: center;
font-family: Arial;
}
.main-content {
background: url('assets/img/pain.jpg') no-repeat center center;
background-size: cover;
}
.middle-content {
display: flex;
justify-content: space-around;
justify-content: center center;
width: 900px;
margin: 100px auto;
border-right: 2px solid white;
border-left: 2px solid white;
}
div.logo-image-content img {
width: 500px;
}
div.logo-image-content {
padding-top: 55px;
margin: auto;
}
.middle-content-paragraph {
font-size: 20px;
}
#media only screen and (min-device-width: 320px) and (max-device-width: 480px) {
div.logo-image-content img {
width: 850px;
}
.middle-content-paragraph {
font-size: 25px;
}
.middle-content {
border: none;
}
.middle-content-title {
font-size: 45px;
}
}
<main class="main-content">
<div class="logo-image-content">
<img src="assets/img/logo.png" alt="logo">
</div>
<div class="middle-content">
<div class="middle-content-text">
<h2 class="middle-content-title">Adresse</h2>
<p class="middle-content-paragraph">bla bla road <br> 75000 Paris</p>
</div>
<div class="middle-content-text">
<h2 class="middle-content-title">Horaires</h2>
<p class="middle-content-paragraph">Lundi au Dimanche 7h - 20h30 <br> Fermeture Mecredi</p>
</div>
<div class="middle-content-text">
<h2 class="middle-content-title">Téléphone</h2>
<p class="middle-content-paragraph">XX XX XX XX XX</p>
</div>
</div>
<div class="bottom-content">
<h2 class="bottom-content-title">
Ici il y aura bientot un text ...
</h2>
</div>
</main>
Use media queries to limit CSS instructions only to some smaller screen devices. You can use the screen width like this.
#media screen and (max-width:780px) {
.middle-content-text {
width:45%;
margin:0 2.5%!important;
}
.middle-content-text:nth-child(1) {
width:95%!important;
}
.middle-content {
display:flex;
align-items:center;
justify-content:center;
width:80%;
flex-wrap:wrap;
}
.middle-content-text {
width:45%;
margin:0 2.5%!important;
}
.middle-content-text:nth-child(1) {
width:95%!important;
}
}
Use flex direction column in mobile using media query. First one set width 100% and last two div set 50% width each one. If you need gap between last two div then set 48% or whatever you need then set margin left and right auto.

How to fix alignment of text not image in div?

Is it possible to align my text to the vertical middle. I've used valign, text-align and padding but will doesn't work. Also, I don't want any image to align with text.
Solution needs to be HTML only.
body {
background-color: #6B6B6B;
margin: 50px;
<div style="background:#2f2f2f;height:42px;width:250px;"><i><b style="padding-top:10px;text-align:middle">Text</a></div>
Just add to the div.
display: flex;
align-items: center;
body {
background-color: #6B6B6B;
margin: 50px;
<div style="background:#2f2f2f;height:42px;width:250px;display: flex;
align-items: center;"><i><b style="padding-top:10px;text-align:middle">Text</a></div>
Also, the html format is not valid, a better code would be something like this:
body {
background-color: #6B6B6B;
margin: 50px;
}
.container {
background: #2f2f2f;
height: 42px;
width: 250px;
display: flex;
align-items: center;
}
<div class="container">
<span>Text</span>
</div>
Your HTML has some syntax errors, and you need to use negative margins in this case to align to the bottom center.
body {
background-color: #6B6B6B;
}
.bottomcenter {
position:absolute;
width:300px;
height:300px;
bottom:0px;
right:25%;
left:50%;
margin-left:-150px;
color:white;
}
<div style="background:#2f2f2f;height:42px; text-align:center;" class="bottomcenter"><i><a style="padding-top:10px;">Text</a></i></div>
I think it's this one. If you want to make the text go to the center you just write this code:
text-align: center;

Cannot center img horizontally

I'm trying to center image horizontally in this sample http://jsfiddle.net/3k3CC/1545/ , but I'm unsuccessfull. It only works when container is wider than image, but what I need is for the image to be centered even if the container is thinner than the image itself.
Sample CSS:
#artiststhumbnail {
width:100px;
height:308px;
overflow:hidden;
border-color:#DADADA;
border-style:solid;
border-width:thin;
background-color:pink;
}
#artiststhumbnail:hover {left:50px }
#genre {
font-size:12px;
font-weight:bold;
color:#2A2A2A
}
#artiststhumbnail a img {
display : block;
margin : auto;
}
Sample HTML:
<div id="artiststhumbnail">
<a href="#">
<!--image here-->
<img src="http://goo.gl/QrKCc" height="100%" alt="artist" border="1" />
</a>
</div>
You should add text-align: center; to #thumbnailwrapper and set display: inline-block; to #artiststhumbnail.
DEMO
EDIT:
I'm sorry I don't unsderstand your question at the beggining. Use this simple CSS:
#artiststhumbnail a img {
position: relative;
left: 50%;
transform: translateX(-50%);
}
DEMO2
you can add to the #artiststhumbnail this code,
width: 100%;
padding: 15px;
http://codepen.io/jrey/pen/waXgBO updated code :)
try this CSS.. comment your css and try this please...
#artiststhumbnail {
width:100px;
height:308px;
overflow:hidden;
border-color:#DADADA;
border-style:solid;
border-width:thin;
background-color:pink;
width: 100%;
padding: 15px;
display: inline-flex;
flex-flow: row wrap;
justify-content: center;
}
#artiststhumbnail:hover {left:50px }
#genre {
font-size:12px;
font-weight:bold;
color:#2A2A2A
}
#artiststhumbnail a {
display: flex;
justify-content: center;
}
#artiststhumbnail a img {
display : block;
margin : 15px;
width: 200px;
height: auto;
}
DEMO
CSS
#thumbnailwrapper {
color:#2A2A2A;
margin-right:5px;
border-radius:0.2em;
margin-bottom:5px;
background-color:#E9F7FE;
padding:5px;
border-color:#DADADA;
border-style:solid;
border-width:thin;
font-size:15px;
/* The following rules make this a flexbox container */
display: flex;
display: -webkit-flex;
-webkit-flex-direction: row;
flex-direction: row;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
}
#thumbnailwrapper:hover {
box-shadow:0 0 5px 5px #DDDDDD
}
#artiststhumbnail {
width:100px;
height:308px;
overflow:visible; // Changed from hidden to visible
border-color:#DADADA;
border-style:solid;
border-width:thin;
background-color:pink;
}
#artiststhumbnail:hover {
/*left:50px*/
}
/* No position: fixed. absolute, or relative; left: 50px has no effect on a static element */
#genre {
font-size:12px;
font-weight:bold;
color:#2A2A2A
}
#artiststhumbnail a img {
/* display: block;
margin: auto; */
}
/* Removed margin and block display to demonstrate that flexbox container and it's children elements are not easily influenced by other element properties and attributes */
HTML
<div id="thumbnailwrapper">
<div id="artiststhumbnail"> <a href="#">
<!--image here-->
<img src="http://goo.gl/QrKCc" height="100%" alt="artist" border="1" />
</a>
</div>
</div>
you could try your image width to 100%
#artiststhumbnail a img {
display : block;
margin : auto;
width:100%;
}
Not sure exactly what you mean by center but here it goes. If you want the image itself to center, use background-size: cover and background-position: center to accomplish this.
<div id="thumbnailwrapper">
<div id="artiststhumbnail">
<a href="#">
<!--image here-->
<div></div>
</a>
</div>
</div>
#artiststhumbnail a div {
display : block;
margin : auto;
height: 100%;
width: 100px;
background-image: url('http://goo.gl/QrKCc');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
JSFiddle
EDIT: sorry, had the wrong jsfiddle link attached

CSS Center nav bar links

Having trouble centering some text links on my nav bar, margin left and right auto aren't working and i've tried setting display types to block/inline-block to no avail. The solution is probably staring me in the face I know but I really can't find it.
CSS:
.navmenu {
background-color: #1e1e1e;
background-image: url("../images/NavBar.gif");
background-position: top;
border-top: 1px solid #383838;
margin-bottom: 5px;
z-index:105;
}
.navlink {
margin-left:auto;
margin-right: auto;
width: 100%;
font-size: 28px;
text-transform: uppercase;
}
HTML:
<div class="navmenu">
<div class="navlink">
Home
Twitch
YouTube
Twitter
Facebook
Teamspeak
Forum
</div>
</div>
Use flex to it get more flexible:
.navmenu { margin: 0 auto }
.navlink { display: flex; justify-content: center }
Looks like you are setting .navlink width to 100%. Reduce it to the width of the rest of your content. I tried 800px and it worked well.
.nav-menu{ width: 100%; text-align: center; }
This worked for me.
You following CSS on .navlink
.navlink {
display: flex;
justify-content: center;
}
.navmenu {
background-color: #1e1e1e;
border-top: 1px solid #383838;
margin-bottom: 5px;
z-index:105;
}
.navlink {
font-size: 14px;
text-transform: uppercase;
display: flex;
justify-content: center;
}
.navlink a {
color: #fff;
}
<div class="navmenu">
<div class="navlink">
Home
Twitch
YouTube
Twitter
Facebook
Teamspeak
Forum
</div>
</div>
i have a another very good solution for you
<div id="nav">
<span>Twitter</span>
<span>Facebook</span>
<span>YouTube</span>
</div>
<!--Css style sheet for above code-->
#nav{
width:100%;
text-align:center;
}
#nav span a{
text-decoration:none;
padding:10px;
}
Try:
.navlink { text-align:center }
The top logo is centered because it has a fixed width. The nav bar is not centered because it is 100% of the screen width. If you make this a lower percent or use the same fixed width as the logo image, then it will work be centered.
.navlink {
margin-left:auto;
margin-right: auto;
width: 1024px;
font-size: 28px;
text-transform: uppercase;
}
Add text-align:center; to your nav-link class
.nav-link
{
text-align:center;
}

2 faux columns, liquid in the middle & a sticky footer without a bg on the html/body?

I am working on a 2 faux side-columns, liquid in the middle and a footer layout and managed and managed to get it working with sacrifice:
http://jsfiddle.net/8F2my/
HTML
<body>
<div class="wrapper">
<div class="main">
<div id="header">
</div>
</div>
</div>
<div class="footer">
<span>Copyright © 2011-2014 FDNA Inc., All rights reserved.</span>
</div>
</body>
CSS
* {margin:0;padding:0;}
html, body {height: 100%;}
html {
/* I don't like doing this */
background: url('http://i.stack.imgur.com/4VEIy.png') repeat-y left;
}
body {
/* I don't like doing this */
background: url('http://i.stack.imgur.com/4VEIy.png') repeat-y right;
font-family: "Helvetica", "Arial", "FreeSans", sans-serif;
min-width: 1000px;
}
.wrapper {min-height: 100%; }
.main {
overflow:auto;
padding-bottom: 40px;
} /* must be same height as the footer */
/* Head area */
#header {
height: 50px;
width: 100%;
background-color: #3498db;
}
.footer {
background-color: #3498db;
position: relative;
margin-top: -40px; /* negative value of footer height */
height: 40px;
clear:both;
}
.footer span {
margin: 10px 0 0 13px;
display: inline-block;
font-weight: normal;
}
As you can see the faux column background is assigned to the body and the html. Is there any way I could achieve the same thing in a clean way without assigning a background to the html and body?
This is how it looks if you don't want to click the link:
The white part is liquidy and the gray is of a fixed size.
I am using this faux:
This is not a javascript/jQuery question.
Sure!
One way is to make use of a CSS table for your 'columns' (I assume you mean sidebars) and absolute positioning to get the layout correct.
Demo Fiddle
HTML
<header></header>
<div class='content'>
<div class='columns'>
<div class='column'></div>
<div class='column'></div>
<div class='column'></div>
</div>
</div>
<footer></footer>
CSS
html, body {
height:100%;
width:100%;
margin:0;
padding:0;
}
header, footer {
background-color: #3498db;
height: 40px;
position:absolute;
width:100%;
}
footer {
bottom:0;
}
.content{
position:absolute;
top:40px;
bottom:40px;
}
.columns {
display:table;
width:100%;
table-layout:fixed;
height:100%;
}
.column {
display:table-cell;
}
.column:first-child, .column:last-child {
background:#c0c0c0;
width:305px;
}