I created a feature box on my WordPress development site. With some help I made the feature box responsive and it's almost finished. You can see this feature box displaying properly in the below screenshot
However, I have two issues:
1) When I reduce my browser window in size, the navbar turns expands onto two lines and covers my feature box (pictured). I want the feature box to move down as the navbar expands.
2) On my phone the red ribbon in my feature box expands beyond the width of the page and causes the navbar to display incorrectly (pictured). I don't want the red ribbon to expand beyond the width of my navbar.
I created the navbar using CSS and an image. Using CSS, I created a large red rectangle that expands beyond the margin of my feature box. I then used an image of a red triangle and positioned this beneath the red rectangle. You can see how I did this by looking at "#text-4" in my CSS.
My relevant CSS is
.featured-box {
border-radius: 20px;
background-color: #000;
color: #fff;
padding: 20px;
margin: 0 auto;
margin-top: 10px;
overflow: visible;
width: auto;
max-width: 1160px;
}
.featured-box h4 {
font-size: 20px;
color: #fff;
}
.myimage {
float:right;
}
.featured-box p {
padding: 0 0 20px;
}
.featured-box ul {
margin: 0 0 20px;
}
.featured-box ul li {
list-style-type: disc;
margin: 0 0 0 30px;
padding: 0;
align: right;
}
.featured-box .enews p {
padding: 10 10 10 10px;
color: #fff;
float: left;
width: 220 px;
margin: 10 10 10 10px;
}
.featured-box .enews #subscribe {
padding: 20 20 20 20px;;
}
.featured-box .enews #subbox {
background-color: #fff;
margin: 0;
width: 300px;
}
.featured-box .enews .myimage {
float: right;
margin-left: 10px;
margin-right: 50px;
width: auto;
}
section.enews-widget {
overflow: hidden;
}
.featured-box .enews input[type="submit"] {
background-color: #d60000;
padding: 10 10 10 10px;
width: 150px;
}
#media screen and (min-width: 1140px) {
div.featured-box {
margin-top: 10%;
}
}
#media only screen and (max-width: 767px) {
section.enews-widget {
clear: both;
}
.myimage {
float: none;
}
.myimage img {
display: block;
height: auto;
margin: 0 auto;
}
}
#text-4 > div:nth-child(1) > h4:nth-child(1) {
color: #fff;
font-size: 1.3em; font-weight: normal;
text-transform: uppercase;
background-color: #d60000;
position: relative;
margin: 0px -60px 20px -20px;
padding: 18px 0px 16px 20px;
}
#text-4 > div:nth-child(1) > h4:nth-child(1):after {
content: '';
display: block; height: 40px; width: 40px;
background: url(http://bryancollins.eu/wp/wp-content/uploads/2014/04/fold.png) no-repeat 0 0;
position: absolute; right: 0px; bottom: -40px;
}
.page p { line-height: 1.2em; }
.page a { color: #1badd2; text-decoration: none; }
.widget li {
margin: 0;
padding: 2px 0px 8px 35px;
display: inline; position: relative;
border-bottom: none;
}
.featured-box .widget li {
list-style: none;
background: url("http://bryancollins.eu/wp/wp-content/uploads/2014/04/arrow.png") no-repeat scroll 0 10px rgba(0, 0, 0, 0);
display: inline;
margin: 0 0 0 30px;
padding: 0 0 0 40px;
}
My HTML:
<div class="featured-box widget-area">
<section id="text-4" class="widget widget_text">
<div class="widget-wrap">
<h4 class="widget-title widgettitle">
Get this for free
</h4>
<div class="textwidget">
<div class="myimage">
<img src="http://bryancollins.eu/wp/wp-content/uploads/2014/04/Book-cover.png"></img>
</div>
</div>
</div>
</section>
<section id="enews-ext-3" class="widget enews-widget">
<div class="widget-wrap">
<div class="enews">
<h4 class="widget-title widgettitle">
33 Creative Strategies for your next writing proje…
</h4>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing…
</p>
<div class="arrows">
<ul>
<li>
List item 1
</li>
<li>
List item 2
</li>
<li>
List item 3
</li>
</ul>
</div>
<p>
Tuo vero id quidem, inquam, arbitratu. Illud mihi …
</p>
<form id="subscribe" name="33 Creative Strategies for your next writing project" onsubmit="if ( subbox1.value == 'First Name') { subbox1.value = ''; } if ( subbox2.value == 'Last Name') { subbox2.value = ''; }" target="_blank" method="post" action="<!-- Begin MailChimp Signup Form --> <div id="mc_embed_signu…s="button"></div> </form> </div> <!--End mc_embed_signup-->"></form>
</div>
</div>
</section>
Thanks for the help.
Fix for 1.) Needed to increase top margin between 1024px and 1140px can be more or less than 14% but looks ok at 14!
#media screen and (min-width: 1024px) and (max-width: 1140px) {
div.featured-box {
margin-top: 14%;
}
}
User fixed with margin-top 130px.
Fix for 2.)
Try adding 'overflow: hidden' to the same media query:
#media screen and (min-width: 1024px) {
div.featured-box {
margin-top: 130px;
overflow: hidden;
}
}
For your first issue, on "desktop size" your featured box has a margin-top of 10%, but then once you resize below 1040px, the featured box takes on the default CSS which has a margin-top of 10px and the navigation has fixed positioning meaning that the featured box margin top is from the top of the window, not from below the navigation.
To resolve this, you can change the default CSS to use a percentage for the top margin, however I would advise using relative positioning and using pixels to set the margin. Another option is to increase the breakpoint so that the "mobile" navigation replaces the default navigation as soon as it beings to wrap.
For your second issue you can either set "overflow:hidden;" on the containing div or you can set the maximum scale to 1 with a viewport meta tag(mobile), I'd advise doing both:
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
Related
Okay, I found a solution: with #media I'm accessing the image's width and the bar separately and it's working but is there any shorter way codewise?
I searched the internet for a solution but none of what I found helped me so far.
I'm trying to make my header to be responsive to the browser's width but it isn't working.
I tried to make just the image responsive or just the top bar but nothing works...
Any ideas?
<header class="header">
<div class="top-bar">
<div class="nav-container">
<ul class="navbar">
<li>החשבון שלי</li>
<li>המתכונים שלי</li>
<li>אודות</li>
<li class="last-btn">צרו קשר</li>
</ul>
</div>
</div>
<div class="banner">
<img src="Images\maadanot_winter_banners.jpg" alt="אפייה חורפית"/>
</div>
</header>
and this is the css:
body {
margin: 0;
}
.top-bar {
width: 100%;
background-color: #404040;
padding: 12px;
}
.nav-container {
width: 68%;
margin: auto;
}
.navbar {
margin: 0;
list-style-type: none;
background-color: #404040;
display: table;
font-family: Helvetica;
font-size: 14px;
}
.navbar li {
display: table-cell;
border-left: 1px solid white;
padding: 0px 10px;
overflow: hidden;
width: 85px;
text-align: center;
}
.navbar a {
color: white;
text-decoration: none;
}
.navbar a:hover {
font-weight: bold;
}
#media screen and (max-width:900px) {
.header {
width: 100%;
}
}
.banner {
margin-top: 33px;
width: 100%;
text-align: center;
}
Try to change it into:
#media screen and (max-width:900px) {
.header {
width: 100vw; /* viewport width */
}
}
device-width is not correct value for width.
Use : <
meta name="viewport" content="width=device-width, initial-scale=1">
The width property controls the size of the viewport. It can be set to a specific number of pixels like width=600 or to the special value device-width, which is the width of the screen in CSS pixels at a scale of 100%.
The initial-scale property controls the zoom level when the page is first loaded. The maximum-scale, minimum-scale, and user-scalable properties control how users are allowed to zoom the page in or out.
When you are working om Media Queries, You have to need change inherit property if you declare cascaded down.If you have set Backgruond images on the body, there is need a queries to cancel background images.
The keyword ‘only’ can also be used to hide style sheets from older user agents. User agents must process media queries starting with ‘only’ as if the ‘only’ keyword was not present.
It's not really clear what you want, but to get your image span the whole width in all sizes, you can add this rule:
.banner img {
width: 100%;
}
This will size the image within its container (which has 100% width, so eventually the image will span the width).
BTW: .banner is a DIV that will be 100% wide anyway, so you actually can erase the 100% width for .banner
body {
margin: 0;
}
.top-bar {
width: 100%;
background-color: #404040;
padding: 12px;
}
.nav-container {
width: 68%;
margin: auto;
}
.navbar {
margin: 0;
list-style-type: none;
background-color: #404040;
display: table;
font-family: Helvetica;
font-size: 14px;
}
.navbar li {
display: table-cell;
border-left: 1px solid white;
padding: 0px 10px;
overflow: hidden;
width: 85px;
text-align: center;
}
.navbar a {
color: white;
text-decoration: none;
}
.navbar a:hover {
font-weight: bold;
}
#media screen and (max-width:900px) {
.header {
width: 100%;
}
}
.banner {
margin-top: 33px;
}
.banner img {
width: 100%;
}
<header class="header">
<div class="top-bar">
<div class="nav-container">
<ul class="navbar">
<li>החשבון שלי</li>
<li>המתכונים שלי</li>
<li>אודות</li>
<li class="last-btn">צרו קשר</li>
</ul>
</div>
</div>
<div class="banner">
<img src="http://placehold.it/1200x90/fa0" alt="אפייה חורפית" />
</div>
</header>
I have a "current" class which highlights the current page. And it works as far as highlighting the current page. With the padding I've added the highlighted area covers the a-element and go towards the top of the page which is what I want it to do. But each highlighted area is the width of the a-element and since each a-element has a different number of characters within, the widths are inconsistent.
To correct this I gave the a-element a display: block. This correction did give a consistent width, but now the highlighted area goes down towards the page as opposed to towards the top of the page as I wanted it.
How can I get a consistent width of highlighted area to go up towards the top of the page?
nav {
margin: 100px auto;
}
.top-nav {
width: 785px;
color: dimgrey;
text-align: center;
margin: 0 auto;
}
.top-nav li {
width: 150px;
float: left;
margin: 0 3px;
}
.top-nav a {
color: dimgrey;
width: 150px;
}
.current {
padding: 150px 0px 5px 0px;
background-color: #fab938;
color: white;
}
span.fa-bath {
font-size: 50px;
margin-top: -45px;
margin-bottom: 10px;
border-radius: 100%;
padding: 20px;
background-color: #fab938;
}
<nav>
<ul class="top-nav">
<li>Quem Somos</li>
<li>O Que Fazemos?</li>
<li><span class="fa fa-bath"></span></li>
<li>Donations</li>
<li>Contact</li>
</ul>
</nav>
I would change the way you build you nav.
Instead of using a float use a inline-block on the LI.
Next to that you can use vertical-align: middle; to align the items from the middle or use top/bottom.
also your nav container is not fitting the size of the 5 Li you are using.
https://jsfiddle.net/wyrscn48/1/
nav {
margin: 100px auto; }
.top-nav {
width: 935px;
color: dimgrey;
text-align: center;
margin: 0 auto;
}
.top-nav li {
width: 150px;
margin: 0 3px;
display: inline-block;
vertical-align: top;
}
.top-nav a {
color: dimgrey;
width: 150px; }
.current {
background-color: #fab938;
color: white; }
span.fa-bath {
font-size: 50px;
margin-bottom: 10px;
border-radius: 100%;
padding: 20px;
background-color: #fab938;
}
I'm struggling with this project I'm doing for practice. I'm having trouble with the innovation cloud project. Please explain me how to fix this.
I can't manage to get the "Learn More" button to be below the paragraph in the header section.
I can't manage to get the image in the main section to float left of the Header and paragraph.
I also can't manage the jumbotron DIV to appear below main. The image fuses with main, it doesn't appear below it where it should be.
Here is the pen for a visual: http://codepen.io/alejoj/pen/xGBbwv
Thanks for your help.
html, body {
margin: 0;
padding: 0;
}
body {
font-family: 'Roboto', sans-serif;
font-weight: 100;
}
.container {
margin: 0 auto;
max-width: 940px;
padding: 0 10px;
}
/* Header */
.header {
height: 800px;
text-align: center;
background-image: url('https://s3.amazonaws.com/codecademy-content/projects/innovation-cloud/bg.jpg');
background-size: cover;
}
.header .container {
position: relative;
top: 200px;
}
.header h1 {
font-size: 80px;
line-height: 100px;
margin-top: 0;
margin-bottom: 80px;
color: white;
}
#media (min-width:850px) {
.header h1 {
font-size: 120px;
}
}
.header p {
font-weight: 500;
letter-spacing: 8px;
margin-bottom: 40px;
margin-top: 0;
color: white;
}
.btn{
width: 30%;
height: 40px;
border: none;
margin: 25px auto 0 auto;
font-family: 'Roboto', sans-serif;
font-size: 15px;
background-color: black;
color: white;
}
.btn:hover {
background: #117bff;
cursor: pointer;
transition: background .5s;
}
/* Nav */
.nav{
background-color: black;
}
.nav ul {
display: table;
list-style: none;
margin: 0 auto;
padding: 30px 0;
text-align: center;
}
.nav li{
display: cell;
vertical-align: middle;
float: left;
padding-left: 10px;
color: white;
font-family: 'Roboto', sans-serif;
}
/* Main */
.main .container {
margin: 80px auto;
}
.main h2, p{
display: inline-block;
float: left;
}
.main img{
height: 150px;
width: 35%%;
margin: 50px -5px 50px 0px;
display: inline-block;
float: left;
}
/* Jumbotron */
.jumbotron {
margin: 10px 0;
height: 600px;
text-align: right;
background-image:url('https://s3.amazonaws.com/codecademy-content/projects/innovation-cloud/jumbotron_bg.jpg');
}
.jumbotron .container {
position: relative;
top: 220px;
}
/* Footer */
.footer {
font-size: 14px;
}
/* Media Queries */
#media (max-width: 500px) {
.header h1 {
font-size: 50px;
line-height: 64px;
}
.clearfix{
clear: both;
}
.main, .jumbotron {
padding: 0 30px;
}
.main img {
width: 100%;
}
}
<!DOCTYPE html>
<html>
<head>
<link href='https://fonts.googleapis.com/css?family=Roboto:400,300,500,100' rel='stylesheet' type='text/css'>
<link rel='stylesheet' href='style.css'/>
</head>
<body>
<div class="header">
<div class="container">
<h1> INNOVATION CLOUD </h1>
<p>CONNECT YOUR IDEAS GLOBALLY</p>
<input class="btn" type="button" value="Learn More">
</div>
</div>
<div class="nav">
<div class="container">
<ul>
<li>Register</li>
<li>Schedule</li>
<li>Sponsors</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</div>
<div class="main">
<div class="container">
<img id="mainImage" src="https://s3.amazonaws.com/codecademy-content/projects/innovation-cloud/cloud.svg" />
<h2>The Innovation Cloud Conference</h2>
<p>Connect with the best minds across a wide range of industries to share ideas and brainstorm new solutions to challenging problems.</p>
<p>Hear industry leaders talk about what worked (and what didn't) so that you can save time on your most challenging projects.</p>
<p>Learn about the latest research and technologies that you can use immediately to invent the future.</p>
</div>
</div>
<div class="clreafix"></div>
<div class="jumbotron">
<div class="container">
</div>
</div>
</body>
</html>
Not entirely sure about your desired outcome, but it seems that this css was throwing off a lot of what you want to fix:
.main h2, p {
display: inline-block;
float: left;
}
If you remove that and change the right margin on your image from -5 to 50 it looks pretty good like this: http://codepen.io/anon/pen/BNbyEP
Floating elements can really throw off your layout if you don't "clear" the floats. Sometimes I add a br style="clear:both" after floated elements to keep the flow looking as expected (in the case of not seeing your jumbotron image where it should be)
You have your p set to inline-block. Remove this:
.main h2, p {
display: inline-block;
float: left;
}
You have negative right margin on your image. Change this:
margin: 50px -5px 50px 0px;
to:
margin: 50px 50px 50px 0px;
Not sure what you mean.
if you go and reduce the width of the window to view the screen as if it were a mobile device you can see that the orange "badges" may not be entered (especially when only one badge fits per line) I want it to fit more badges in if possible whilst always keeping the badge, or group of badges on that line entered horizontally. The class is badge that isn't being centered Thank you in advance!! :)
jsfiddle: http://jsfiddle.net/avg24wrk/
This is the HTML
<div class="container">
<div class="sidebar">
<div class="sidebar-inner">
<p class="badge"><span class="vertical-align">Book a Free Consultation!</span></p>
<p class="badge"><span class="vertical-align">Second Point</span></p>
<p class="badge"><span class="vertical-align">Third Point</span></p>
</div>
</div>
and this is the CSS
* {
border: 0;
margin: 0;
padding: 0;
}
.sidebar {
float: left;
width: 25%;
color: #505050;
}
.sidebar-inner {
margin: 0 30px 0 35px;
}
.badge {
margin: 10px auto;
font-size: 24px;
text-align: center;
border-radius: 7px;
padding: 20px 20px;
background-color: #ed9727;
cursor: pointer;
}
#media screen and (max-width: 490px) {
.sidebar {
width: 100%;
}
.sidebar-inner {
padding-bottom: 20px;
border-bottom: 2px solid #505050;
margin: 0 30px;
overflow: hidden;
}
.badge {
float: left;
margin: 15px 10px;
max-width: 150px;
min-height: 50px;
display: table;
}
}
have you tried adding text-align: center; to class you want to center
since i you didn't mention which class you want to center so i will give you a simple rule try this
please mention class you want to center
Here is my relevant css (just the phone version. the difference from the computer version is the "(max-width : 1223px)" turns into "(min-width : 1224px)"):
* {
margin: 0;
padding: 0;
}
body {
background: #f5f5f5;
font-family: 'Open Sans', sans-serif;
height: 100%;
margin: 0 0 100px; /* bottom = footer height */
}
html {
position: relative;
min-height: 100%;
}
a {
text-decoration: none;
color: #444;
}
a:hover {
color: blue;
}
section {
background: #fff;
box-shadow: 0px 2px 2px #ebebeb;
}
header {
width: 100%;
margin: 0 auto;
text-align: center;
position: relative;
}
nav li {
display: inline-block;
/*padding: 40px 30px 37px 30px;*/
padding-top: 3%;
padding-right: 2%;
padding-bottom: 3%;
padding-left: 2%;
}
/* Smartphones (portrait and landscape) ----------- */
#media only screen and (max-width : 1223px) {
.logo {
/*background: url(logo.png) 50% 0 no-repeat;*/
background: url(http://i48.tinypic.com/2mob6nb.png);
background-size: 140px 59px;
width: 140px;
height: 59px;
position: absolute;
top: 2%;
/* left: 405px; */
left: 38%;
}
nav li:nth-child(2) {
padding-right: 10%;
}
nav li:nth-child(3) {
padding-left: 10%;
}
}
/* Desktops and laptops ----------- */
#media only screen and (min-width : 1224px) {
.logo {
/*background: url(logo.png) 50% 0 no-repeat;*/
background: url(http://i48.tinypic.com/2mob6nb.png);
background-size: 140px 59px;
width: 140px;
height: 59px;
position: absolute;
top: 20%;
/* left: 405px; */
left: 44%;
}
nav li:nth-child(2) {
padding-right: 10%;
}
nav li:nth-child(3) {
padding-left: 10%;
}
}
#sectionLeft {
width: 48%;
float: left;
padding: 5px;
}
#section {
width: 48%;
float: right;
padding: 5px;
}
#sectionLeft h2, #section h2 {
text-align: center;
}
#wrap {
width: 100%;
margin: 0 auto;
}
#newsSection {
background: #fff;
box-shadow: 0px 2px 2px #ebebeb;
text-align: center;
margin: 0px 0px 10px 0px;
}
#newsText {
font-size: 12px;
}
footer {
position: absolute;
left: 0;
bottom: 0;
height: 2.5%;
width: 100%;
text-align: center;
background-color: #fff;
-webkit-box-shadow: 0px -2px 2px 0px #ebebeb;
-moz-box-shadow: 0px -2px 2px 0px #ebebeb;
box-shadow: 0px -2px 2px 0px #ebebeb;
bottom: 0;
}
#footerText {
font-size: 10px;
}
and the html:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Aversion Gaming</title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans'
rel='stylesheet' type='text/css'>
<link href='css/style.css' rel='stylesheet' type='text/css'>
</head>
<body>
<section>
<header>
<nav>
<ul>
<li>Home</li>
<li>Teams</li>
<li>Contact</li>
<li>Sponsors</li>
</ul>
</nav>
<div class="logo"></div>
</header>
</section>
<div id="wrap">
<div id="sectionLeft">
<h2>News</h2>
<section id="newsSection">
<h3>Test news post</h3>
<p id="newsText">This is just a test news post.</p>
<a style="font-size: 12px;" href="#">Read More...</a>
</section>
<section id="newsSection">
<h3>Finally, a website!</h3>
<p id="newsText">We have finally created a website thanks to
#AversionRastro!</p>
<a style="font-size: 12px;" href="#">Read More...</a>
</section>
</div>
<div id="section">
<h2>About</h2>
<section id="newsSection">
<p id="newsText">
<b>Aversion Gaming</b> is a newly founded gaming organization.
</p>
</section>
</div>
</div>
<footer>
<p id="footerText">Copyright 2014 Aversion Gaming. Designed and
coded by Robert Trainor.</p>
</footer>
</body>
</html>
When I load the page on my Windows 7 laptop, it shows the logo (got it from another post, so its just an example) and all of the formatting code in the #media works.
When I pin the browser to a side on the same computer, the code for the smaller window size doesn't kick in.
The logo never shows and the formatting for the 2nd and 3rd list items don't get their padding.
If there is something I'm missing or doing wrong here, please tell me.
I have checked your code and on my macbook with safari it works just fine (meaning in my browser the source code kicks in correctly by scaling down/up).
Have you checked if the code kicks in (so does it show up in your source code), or does it only not look as you wish?
You want to add the padding to the navigation to add additional white space next to the logo I guess, so that it looks a little bit more tidied up? If so my suggestions:
Currently your logo is not centered in mobile version. Thats the first point to make a little adjustment:
.logo {
background: url(http://i48.tinypic.com/2mob6nb.png);
background-size: 140px 59px;
width: 140px;
height: 59px;
position: absolute;
top: 2%;
left: 50%; /* center the left side of the logo */
margin-left: -70px; /* go half of the logos width backwards, so that the logos center is centered */
}
Then your <li>s receive the additional padding, but they are centered as text, not as "blocks". You can't the same amount of white space on the left and on the right side. To achieve this the next adjustment would be to add a widthto your <li>s like so:
nav li {
display: inline-block;
padding: 3% 2%;
width: 50px; /* change this to whatever you want in px or % */
}
The difference looks like this (first before, then after):
Does this fix your problem? If not feel free to correct my understanding of your question or let me know, if you need further information.
Best regards,
Marian.