Header not aligning to the center - html

I have a text in the header that I would like to center on smaller screens but I have tried various options and it's not working. Could someone point me in the right direction? Thanks in advance for your help.
Edit: added more code. If I add "width:70%" to .name, it aligns it to the center on some iphones but not others.
body {
margin: 0;
background-color: #e9e9f3;
}
/* Header */
.header .name {
position: absolute;
top: 0.5em;
left: 1em;
margin-left: 4%;
color: white;
font-size: 2em;
font-family: 'Archivo', sans-serif;
}
.social-icon-header {
position: absolute;
top: 3em;
right: 2em;
height: auto;
}
/* Tablets and under */
#media (max-width: 768px) {
* {
box-sizing: border-box;
}
body {
margin: 0;
text-align: center;
}
/* Header */
.social-icon-header {
display: none;
}
.name {
display: flex;
text-align: center !important;
justify-content: center !important;
width: 70%;
}
<div class="hero">
<!--Header-->
<div class="header">
<h2 class="name">Name</h2>
<a class="social-icon-header" href="https://www.tiktok.com" target="_blank">
<i class="fab fa-tiktok fa-2x"></i>
</a>
</div>
</div>

Try to add width: 100% to the name class, so it would take 100% width of the parent container.
.name {
text-align: center !important;
justify-content: center !important;
width: 100%;
}

You have to change the positioning of .name in the media query and set text-align: center for .header. In this way you can change the whole layout for screens with a different size (like in your example a maximum of 768px).
Just make sure that you reset other values that you set before (outside the media query, like top, left and margin-left for .name) that you don't need for other screen sizes. You also forgot to close media query tag.
Also beware of the fact that it's good practice to design css mobile first and then use media queries for bigger screens. https://www.browserstack.com/guide/how-to-implement-mobile-first-design
If you replace you css with the following it'll work:
body {
margin: 0;
background-color: #e9e9f3;
}
/* Header */
.header .name {
position: absolute;
top: 0.5em;
left: 1em;
margin-left: 4%;
color: white;
font-size: 2em;
font-family: 'Archivo', sans-serif;
}
.social-icon-header {
position: absolute;
top: 3em;
right: 2em;
height: auto;
}
/* Tablets and under */
#media (max-width: 768px) {
.social-icon-header {
display: none;
}
.header {
text-align: center;
}
.header .name {
position: relative;
left: auto;
top: auto;
margin: 0;
}
}

Related

All new HTML appears behind an image?

I have been working on a responsive web design, after adding CSS to make a link stay centered on a an image the webpage now displays any new html behind the image. I want to be able to add more things on my webpage but any new html I write disappears.
Link to JSFIDDLEhttps://jsfiddle.net/R4bbit2k17/7yuL4y1p/1/#&togetherjs=MEzytpw3kf`
Because your .banner-inner is using position: absolute in conjunction with taking up 100% of the width and height, you'll need to set a position other than static for your text element(s), along with giving them a z-index greater than the default of 0:
p {
background: red; /* Purely to highlight the text */
position: relative;
z-index: 1;
}
This causes your text to appear on top of your image, and can be seen in the following:
body {
font-family: helvetica;
font-size: 15px;
line-height: 1.5;
padding: 0;
margin: 0;
background-color: #f4f4f4;
}
header {
background: black;
color: white;
padding-top: 20px;
min-height: 45px;
}
header a {
color: white;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
header ul {
margin: 0;
padding: 0;
}
header li {
float: left;
display: inline;
padding: 0 20px 0 20px;
}
header nav {
float: right;
margin-top: 5px;
}
#media only screen and (max-width:1000px) {
.centered {
font-size: 12pt!important;
}
}
#media only screen and (max-width:800px) {
.centered {
font-size: 11pt!important;
}
}
#media only screen and (max-width:600px) {
.centered {
font-size: 10pt!important;
}
}
#media only screen and (max-width:400px) {
.centered {
font-size: 9pt!important;
}
}
#media only screen and (max-width:200px) {
.centered {
font-size: 8pt!important;
}
}
.banner-inner {
width: 100%;
height: 100%;
position: absolute;
text-align: center;
color: white;
}
.centered {
position: absolute;
margin-left: auto;
margin-right: auto;
width: 100%;
height: auto;
margin-top: 20%;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
font-size: 12pt;
}
.img {
width: 100%;
height: auto;
float: left;
}
p {
background: red;
position: relative;
z-index: 1;
}
<body>
<header>
<div id="header-inner">
<nav>
<ul>
<li>Home</li>
<li>Courses</li>
<li>About</li>
</ul>
</nav>
</div>
</header>
<section class="section-1">
<div class="banner-inner">
<img class="img" alt="" src="https://d2mt0dng9y3p4j.cloudfront.net/newandimproved/wp-content/uploads/2016/12/shop-with-a-sheriff-mockup.jpg">
<div class="centered">Start Learning</div>
</div>
</section>
<p>ANY HTML ADDED APPEARS BEHIND THE IMAGE AND I CANNOT FIGURE OUT HOW TO CHANGE IT TO APPEAR BENEATH THE IMAGE AS IT WOULD WITH A FRESH HTML PAGE</p>
</body>
Hope this helps!

Elements from same div overlapping on resize

I got problem with 2 elements from my header since 3 days,and cannot fix it.The problem is there that my "Search-trigger" which is my search icon and "tablet-icon" which is icon which is showing only on given browser width,are overlapping.Even search icon is going beyond tablet icon when browser is really tiny width.I tried with Float:right,leftand position:absolue,relative on both elements ,overflow:auto on site header,margin:left,righton elements and display properties on both elements display:block ,display:inline-block; Nothing works... i don't know where is the problem..
/***********************************************
Header Style
************************************************/
.admin-bar .site-header {
top: 32px;
}
.admin-bar .site-header.is-fixed {
top: -47px;
}
#media screen and (min-width:640px) and (max-width:790px){
.admin-bar .site-header.is-fixed{
top :-44px;
}
}
#media screen and (min-width:413px) and (max-width:783px){
.admin-bar .site-header{
top: 35px;
}
}
.site-header {
position: absolute;
top: 0;
left: 0;
right:0;
height: 80px;
z-index: 4;
border-bottom: 1px solid #eee;
}
/***********************************************
Search menu style
************************************************/
.search-trigger {
position: absolute;
right:0.5em;
top: 30px;
width: 40px;
text-align: center;
cursor:pointer;
cursor:hand;
display:inline-block;
}
#media screen and (min-width: 40em) {
.search-trigger {
right: 0.8em;
}
}
#media screen and (min-width:783px){
.search-trigger{
top:26px;
}
}
.search-trigger:before {
width: 100%;
display: block;
font-family: "ElegantIcons";
font-weight: normal;
text-align: center;
content: "\55";
/***********************************************
Icon Style
************************************************/
.tablet-icon{
position: absolute;
display:inline-block;
left:90%;
top: 23px;
width: 40px;
float:right;
}
.tablet-icon:before{
width: 100%;
font-size:1.6em;
font-family: "ElegantIcons";
font-weight: bold;
text-align: center;
content: "\61";
}
<header id="masthead" class="site-header" role="banner">
<span class="tablet-icon"></span>
<a id="search-trigger" class="search-trigger"></a>
</header>
That happens when you use position:fixed, position:absolut, and z-index. You have to change this in your media queries for each resolution.
When I have resizing issues I replace as many px sizings as I can with %. That way when the screen resizes, the elements resize proportionately. i.e. Change out things at 50px with 5%
Well i make the positions on my elements INSIDE the "" element to relative and float:right; and left my position of<header>to absolute,and it worked like a magic.

Responsive fixed-width image showcase without JS

I'd like to create simple responsive website containing a showcase of pictures. By myself, but if there's a template, no problem. But I want to learn it anyway.
Requirements:
images with one width no matter the browser width
images always in the middle of the page (0 auto)
number of columns - images changing with the browser width
no height limitation of the image. only fixed width (+ keep aspect ratio).
perfect example: www.kristianhammerstad.com - try to resize the window, I'd like to achieve exactly this. Works also on mobile browser (shows image after image)
I'd prefer without JS, only media queries - possible?
Here's what I have so far:
* { margin: 0; padding: 0; -webkit-font-smoothing: antialiased; font-smoothing: antialiased; }
body { font: normal 14px Helvetica, Arial, sans-serif; line-height: 30px; color: #333; }
.left { float: left; }
.right { float: right; }
.clearfix:before,
.clearfix:after { content: " "; /* 1 */ display: table; /* 2 */ }
.clearfix:after { clear: both; }
hr {
margin: 0;
border: 0;
width: auto;
border-top: 1px solid #aaaaaa;
opacity: .25;
margin: 0 auto;
}
h1 {
letter-spacing: 2px;
font-weight: 300;
text-align: center;
font-size: 2em;
line-height: 1.3em;
color: #333;
}
h2 {
letter-spacing: 1px;
font-weight: 300;
text-align: center;
font-size: 1em;
margin-bottom: 60px;
color: #666;
text-transform: uppercase;
}
/* ---------------------------------------------------------- */
.wrapper {
width: 950px; margin: 0 auto;
}
#name {
margin-top: 50px;
}
/* ---------------------------------------------------------- */
#works {
margin-top: 50px;
}
#works h2 {
font-family: Helvetica, Arial, sans-serif;
letter-spacing: 1px;
font-weight: 300;
text-align: left;
font-size: 1.3em;
margin-bottom: 10px;
color: #666;
text-transform: none;
}
#work-one {
display: block;
width: 460px;
height: 500px;
margin-right: 30px;
margin-bottom: 30px;
}
#work-two {
display: block;
width: 460px;
height: 300px;
}
#work-three {
display: block;
width: 460px;
height: 700px;
margin-bottom: 30px;
}
#work-four {
display: block;
width: 460px;
height: 200px;
}
/* ---------------------------------------------------------- */
#media (min-width: 768px) and (max-width: 1024px) {
/* I am not sure about break points */
}
#media only screen and (min-width: 320px) and (max-width: 767px) {
/* I am not sure about content here */
}
<div class="wrapper">
<div id="name">
<h1>IMAGES</h1>
<h2>showcase</h2>
</div>
<div id="works">
<div class="left">
<a id="work-one" href="#"><img src="http://placehold.it/460x500?text=Placeholder" ></a>
<a id="work-two" href="#"><img src="http://placehold.it/460x300?text=Placeholder" ></a>
</div>
<div class="right">
<a id="work-three" href="#"><img src="http://placehold.it/460x700?text=Placeholder" ></a>
<a id="work-four" href="#"><img src="http://placehold.it/460x200?text=Placeholder" ></a>
</div>
</div><div class="clearfix"></div>
</div>
First of all it would recommend using a grid system. One common known and used would be bootstrap.
With it you can easily set your wanted layout.
Second, to achieve this "repositioning" effect, you would need a JS library called masonry. It hooks itself in the resize event as well as initially on initialization of the dom.
There it calculates the width of the container wrapping all images and the width of the images, calculates the new positions using complex algorithms, and reposition them using the animation effect you see.
Maybe this tutorial (with source) will help you further: http://creative-punch.net/2014/01/full-screen-image-gallery-using-css-masonry/

How to center vertical inside header?

I am creating a responsive header. I got two columns and want the button in the right column to be vertical centered.
I know I can center items using top: 50%; margin-top: -xy px, and my button although got a fixed height: 40px.
To use this method I wrapped my button inside a div {position: relative}. This does not work, as the div does not stretch its own height.
How can I solve this with css? First I thought about Flexbox, but it has quite some lack of browser compatibility.
JSFIDDLE DEMO
You can greatly simplify your code - remove floats, (use display: inline-block instead), remove the .relative div, etc.
Working Fiddle
html, body {
margin: 0;
padding: 0;
font-size: 16px;
}
header {
background: red;
color: #fff;
padding: 0.5em;
}
header h1 {
font-size: 2em;
margin: 0 0 0.2em;
}
header p {
margin: 0;
}
header button {
height: 40px;
width: 70px;
}
.column-left {
display:inline-block;
width: 70%;
vertical-align: middle;
}
.column-right {
width: 29%;
text-align: right;
display: inline-block;
vertical-align: middle;
height: 100%;
}
/* responsive */
#media (min-width: 200px) {
header {
padding: 1em;
}
}
#media (min-width: 300px) {
header {
padding: 1.5em;
}
}
#media (min-width: 400px) {
header {
padding: 2em;
}
}
#media (min-width: 500px) {
header {
padding: 2.5em;
}
}
#media (min-width: 600px) {
header {
padding: 3em;
}
}
/* helpers */
.clearfix:after {
content: ".";
clear: both;
display: block;
visibility: hidden;
height: 0px;
}
Remove this div with position: relative and add position: relative to your header tag. You can even delete your column-right div.
Another solution:
header button {
top: 50%;
transform: translateY(-50%); // instead of negative margin-top (it is useful when your button has dynamic height, supports IE9+ with -ms- prefix)
}
JSFIDDLE

Bootstrap Responsive Carousel doesn't resize properly

I'm using Bootstrap and I have a carousel under my navbar.
It works OK on normal computers, check this link.
However, I'm having trouble on smaller screens, e.g. iPhone. Just resize your browser screen to see what I mean.
I'm figuring maybe it isn't necessary the responsive CSS but something else I' doing wrong. Maybe their are better ways to get the carousel image with resized on every screen.
Also, I would like the carousel to have a 100% height of the screen, so the carousel spans the entire screen, and the rest of the content shows only when you scroll.
CSS I'm using:
/* CUSTOMIZE THE CAROUSEL
-------------------------------------------------- */
/* Carousel base class */
.carousel {
margin-top: -80px;
position: fixed;
width: 100%;
}
.carousel .container {
position:relative;
z-index: 9;
}
.carousel-control {
height: 80px;
margin-top: 0;
font-size: 120px;
text-shadow: 0 1px 1px rgba(0,0,0,.4);
background-color: transparent;
border: 0;
z-index: 10;
}
.carousel .item {
min-height: 800px;
}
.carousel img {
position: absolute;
top: 0;
left: 0;
min-width: 100%;
height: auto;
margin-top: -200px;
}
.carousel-caption {
background-color: transparent;
position: static;
max-width: 550px;
padding: 0 20px;
margin-top: 200px;
}
.carousel-caption2 {
background-color: transparent;
position: static;
max-width: 380px;
padding: 200px 20px;
}
.carousel-caption h1,
.carousel-caption .lead,
.carousel-caption2 h1,
.carousel-caption2 .lead {
margin: 0;
line-height: 1.25;
color: #fff;
text-shadow: 0 1px 1px rgba(0,0,0,.4);
}
.carousel-caption .btn,
.carousel-caption2 .btn {
margin-top: 10px;
}
#wrapper-container {
margin-bottom: -80px;
padding-bottom: 80px;
position: relative;
background: inherit;
top: 60%;
}
/* Featurettes
------------------------- */
.featurette-divider {
margin: 80px 0; /* Space out the Bootstrap <hr> more */
}
.featurette {
padding-top: 120px; /* Vertically center images part 1: add padding above and below text. */
overflow: hidden; /* Vertically center images part 2: clear their floats. */
}
.featurette-image {
margin-top: -120px; /* Vertically center images part 3: negative margin up the image the same amount of the padding to center it. */
}
/* Give some space on the sides of the floated elements so text doesn't run right into it. */
.featurette-image.pull-left {
margin-right: 40px;
}
.featurette-image.pull-right {
margin-left: 40px;
}
/* Thin out the marketing headings */
.featurette-heading {
font-size: 50px;
font-weight: 300;
line-height: 1;
letter-spacing: -1px;
}
/* RESPONSIVE CSS
-------------------------------------------------- */
#media (max-width: 979px) {
.container.navbar-wrapper {
margin-bottom: 0;
width: auto;
}
.navbar-inner {
border-radius: 0;
}
.carousel .item {
min-height: 500px;
}
.carousel img {
min-width: 100%;
height: auto;
}
.featurette {
height: auto;
padding: 0;
}
.featurette-image.pull-left,
.featurette-image.pull-right {
display: block;
float: none;
max-width: 40%;
margin: 0 auto 20px;
}
}
#media (max-width: 767px) {
.navbar-inner {
margin: -20px;
}
.carousel {
margin-left: -20px;
margin-right: -20px;
}
.carousel .container {
}
.carousel .item {
height: 300px;
}
.carousel img {
height: 300px;
}
.carousel-caption {
width: 65%;
padding: 0 70px;
margin-top: 100px;
}
.carousel-caption h1 {
font-size: 30px;
}
.carousel-caption .lead,
.carousel-caption .btn {
font-size: 18px;
}
.marketing .span4 + .span4 {
margin-top: 40px;
}
.featurette-heading {
font-size: 30px;
}
.featurette .lead {
font-size: 18px;
line-height: 1.5;
}
}
There's a lot you would need to do to clean it up... The following will get you started, but there would definitely be a bit more tweaking to do.
I didn't look at the CSS to fill the screen with an image as per your last request. I think you will have to look at adding a different carousel with other cropped images with a portrait aspect ratio if you want that, so you show the specific part of the image you want.
Firstly under #media (max-width: 767px), remove:
.navbar-inner {
margin: -20px;
}
It's causing your menu bar at the top to shift up out of sight.
From #media... .carousel, remove:
margin-left: -20px;
margin-right: -20px;
This is messy, and is there because of the padding added to body (see below).
Add the following to #media (max-width... .carousel:
position: relative;
margin-top: 0px;
Because you want the carousel to sit neatly under the navbar.
Remove the following from #media... body
padding-right: 20px;
padding-left: 20px;
This is causing problems for the carousel, and you can add this padding for specific divs like wrapper-container if you want.
From .carousel img, remove:
margin-top: -200px;
Next, you have to fix the fact that the text under the carousel is moved way down:
Add the following to #media... #wrapper-container
top: 0;
Remove the following from #media (max-width: 979px)
.carousel .item {
min-height: 500px;
}
and the following from #media (max-width: 767px)
.carousel img {
height: 300px;
}
because the carousel is nowhere near that height at smartphone sizes.
You will also have to play around with the positioning of the caption text in the #media CSS. You may want to decide to lose some caption text as the carousel shrinks.
This will get you started, and you can go from there...
For starters, get rid of the margin-top: -200px; on your .corousel img style.
With a small screen, your image height is less than 200px and this causes it to go off of the screen.