HTML/CSS css boxes and positioning - html

I have a CSS greybox: (When I say greybox, I mean the CSS box I have created that I have made with the color grey as you can see down below.)
.navigation-div
{
margin-top: 14px;
box-shadow: 0px 0px 10px rgba(0,0,0,0.47);
padding: 0;
color: #E3E3E3;
background-color: #333;
}
This greybox is inside of my header and since this greybox is bigger than it appears, it goes past the header image but doesn't appear.
With this:
<div class="navigation-bar">
<a class="navigation-div-blur">
<div class="navigation-div">
<nav class="navigation">
<img id="mailpicture" src="images/gmail.png">
<h1 id="mailtext">Mail Us</h1>
<h1 id="nava">test</h1>
</nav>
</div>
</a>
</div>
The picture and Mail Us show in the correct position not exposing the box. The test however, when I put it in exposes the box.
Here is the CSS I have behind this
#mailtext
{
margin-top: 20px;
display: inline-block;
margin-left: 1230px;
font-size: 20px;
color: white;
font-style: italic;
}
#mailpicture
{
display: inline-block;
margin-top: 16px;
float: right;
}
#nava
{
font-size: 20px;
color: white;
font-weight: bold;
font-style: italic;
margin-top: 20px;
display: inline-block;
margin-left: 500px;
}
You already saw the box for CSS.
I would like to accomplish either one of two things: Make the CSS box smaller and lower it, or have the CSS correctly position the test along with more elements to stay in the same line as the Mail Us.
NOTE: I have tried for the test margin-top:-pixels, this does not go up high enough and stops going up after a while.
This is what it looks like with the test:
This is what it looks like without the test:
As you can notice the first one has a larger box that drops down beneath the header picture. The one without the test has stayed in the header's picture.

There are a few problems with your code.
First, you should not nest anchors (<a>) in other anchor elements.
Using margin to position elements is not a good idea, you are already trying to use inline-block to change default block display of headers and at the same time you are floating one of your inline-block elements to the right.
Adding big margin to the element makes the element use more space and moves next inline element to the new line if it cannot fit in one line with other elements.
If you want to position all your menu items to the right you can use text- align:right on your inline-block elements to stick them to the right.
If you want your mail element be on the right you may stick to using float:right on it, but it would also be easier to just place mail element as the last one in the nav
You can nest anchors <a> inside headers <h1> to create links inside headers
<h1 id="mailtext">Mail Us <img id="mailpicture" src="images/gmail.png"></h1>
http://jsbin.com/kazocekoba/1/
.navigation-div
{
margin-top: 14px;
box-shadow: 0px 0px 10px rgba(0,0,0,0.47);
padding: 0;
color: #E3E3E3;
background-color: #333;
text-align: right;
}
#mailtext
{
margin-top: 20px;
display: inline-block;
/* margin-left: 1230px;*/
font-size: 20px;
color: white;
font-style: italic;
}
#mailpicture
{
display: inline-block;
margin-top: 16px;
float: right;
}
#nava
{
font-size: 20px;
color: white;
font-weight: bold;
font-style: italic;
margin-top: 20px;
display: inline-block;
/*margin-left: 500px;*/
}
/* use padding to separate your navigation elements */
.navigation > * {
padding-left: 2em;
}
<div class="navigation-bar">
<a class="navigation-div-blur">
<div class="navigation-div">
<nav class="navigation">
<!-- --><img id="mailpicture" src="images/gmail.png">
<h1 id="mailtext">Mail Us</h1>
<h1 id="nava">test</h1>
</nav>
</div>
</a>
</div>
A bit better solution http://jsbin.com/xunokaviju/1/
.navigation-div
{
margin-top: 14px;
box-shadow: 0px 0px 10px rgba(0,0,0,0.47);
padding: 0;
color: #E3E3E3;
background-color: #333;
text-align: right;
}
#mailtext
{
margin-top: 20px;
display: inline-block;
/* margin-left: 1230px;*/
font-size: 20px;
color: white;
font-style: italic;
}
#mailpicture
{
display: inline-block;
margin-top: 16px;
/*float: right;*/
}
#nava
{
font-size: 20px;
color: white;
font-weight: bold;
font-style: italic;
margin-top: 20px;
display: inline-block;
/*margin-left: 500px;*/
}
/* use padding to pad elements */
.navigation > * {
padding-left: 1em;
}
<div class="navigation-bar">
<a class="navigation-div-blur">
<div class="navigation-div">
<nav class="navigation">
<!-- -->
<h1 id="nava">test</h1>
<h1 id="mailtext">Mail Us <img id="mailpicture" src="images/gmail.png"> </h1>
</nav>
</div>
</a>
</div>

In #mailtext the margin-left:1230 is the problem. Keeping your code just as it is the only change you'll have to make looks like this:
#mailtext
{
float: right;
font-size: 20px;
color: white;
font-style: italic;
}

change your
#mailtext
{
margin-top: 20px;
display: inline-block;
margin-left: 1230px;
font-size: 20px;
color: white;
font-style: italic;
}
to
#mailtext
{
margin-top: 20px;
display: inline-block;
float:right;
font-size: 20px;
color: white;
font-style: italic;
}
Hope it solves your problem

Related

How to make mobile responsive height of a div with variable list items?

I have created an HTML widget that I intent to publish on all posts on my WordPress blog.
The widget is looking fine on the browser, But it is looking a little shaky on the mobile screen.
<div class="top-box">
<h3 id="box-heading">Our Verdict</h3>
<p id="box-text">Considering its price point and the features it offers, the Sennheiser GSP 300 is absolutely a great choice. It might not serve
like the top-notch gaming headsets (which are really expensive too), it will not leave you disappointed for sure. <br /><br />The headset is
comfortable, sounds great, good-built, and is compatible with most platforms. With little cons like a non-detachable mic and no surround sound,
it still beats some other beasts of a bit higher price points. The light-featured Sennheiser gaming headset is just right for action-packed
gaming without burning a hole in your pocket.</p>
<div class="Sub-box">
<div class="sub-box-left"><span class="dashicons dashicons-yes-alt"> For</span>
<ul id="sub-box-text">
<li>Lightweight & comfortable</li>
<li>Crystal clear mic</li>
<li>Great noise-cancelation</li>
<li>Large volume dial</li>
</ul>
</div>
<div class="sub-box-right"><span class="dashicons dashicons-dismiss"> Against</span>
<ul id="sub-box-text">
<li>Non-detachable microphone</li>
<li>No surround-sound</li>
<li>No chat-game audio balancer</li>
<li>Cable can be a mess for console players</li>
</ul>
</div>
</div>
<div class="review-amazon">
<div class="top-star">
<p id="rating-text">Not On Top Rating</p>
[yasr_overall_rating size="medium"]
</div>
<div class="check-price">
<p class="price-check">Check Price</p>
<a class="amazon-button" href="#">Check Price on Amazon</a>
</div>
</div>
</div>
css
.top-box {
background-color: #ededed;
padding-right: 20px;
padding-left: 20px;
padding-bottom: 25px;
overflow: auto;
}
#box-heading {
font-weight: 600;
font-size: 16px;
line-height: 20px;
text-transform: uppercase;
vertical-align: middle;
}
#box-text {
font-size: 14px;
line-height: 1.5em;
margin-bottom: 10px;
color: #333;
}
.sub-box-left {
float: left;
width: 50%;
padding-left: 15px;
border-right: 1px #fff dotted;
}
.sub-box-right {
float: right;
width: 50%;
padding-left: 15px;
}
#sub-box-text {
line-height: 1.5;
list-style: none;
margin-bottom: 1rem;
margin: 0;
padding: 0;
padding-top: 25px;
border: 0;
font: inherit;
font-size: 15px;
padding-bottom: 20px;
}
.dashicons.dashicons-yes-alt,
.dashicons.dashicons-dismiss {
width: 100%;
text-align: left;
color: black;
font-weight: 500;
font-size: 17px;
line-height: 40px;
text-transform: uppercase;
vertical-align: middle;
}
p:empty:before {
display: none;
}
#yasr-custom-text-before-overall {
display: none;
}
.top-star {
float: left;
width: 50%;
}
.check-price {
color: black;
width: 50%;
float: right;
text-align: center;
}
.price-check {
text-align: center;
}
#rating-text {
text-align: left;
}
a.amazon-button {
background-color: #5eaf16;
padding: 7px;
color: white;
white-space: nowrap;
}
.review-amazon {
padding-top: 20px;
}
.sub-box {
padding-bottom: 10px;
}
https://notontop.com/review/headphone/sennheiser-gsp-300/
This is the sample URL where I have added the code.
[yasr_overall_rating size="medium"] is a shortcode for showing star rating for every product.
Please open the window and try changing the screen size.
You'll have to add a media query within the css and make the items, full width / no float on mobile.
Something Like:
#media only screen and (max-width: 600px) {
.check-price, .top-star {
width: 100%;
float: none;
clear: both;
margin-bottom: 20px;
}
.top-star div, #rating-text {
text-align: center;
}
}
I am not sure how this will work in Wordpress but for a responsive webpage created with HTML5 and CSS, you will need a meta tag at the head of the HTML document: This is used along with Media Queries in the CSS which will make your page responsive to any device and size screen from the mobile, laptop and desktop. This is done with #media then the size screen of the device you need.

<footer> is in a middle of the page between two <div>s

I've created a website and the footer on the main page is alright on the bottom of the page. But the footer on other pages is in the middle of the page. On this page are actually two divs aligned next to each other and it looks like the footer is between them. I've tried everything I found on other questions like this (I mean position: absolute, relative, fixed) and nothing could move the footer on the bottom of the page. I'm very beginner in HTML and CSS, so I'm sorry if there are more problems in my code.
Here is my html code:
<div class="kontaktujte_nas">
<form class="kontaktni_formular" action="kontaktni_formular.php" method="POST">
<label for="jmeno">Celé jméno</label>
<input type="text" id="jmeno" name="jmeno" placeholder="Jan Novák">
<label for="email">Váš Email</label>
<input type="email" id="mail" name="mail" placeholder="jan.novak#email.cz">
<label for="predmet">Předmět</label>
<input type="text" id="predmet" name="predmet">
<label for="zprava">Zpráva</label>
<textarea id="zprava" name="zprava"></textarea>
<button type="submit" name="odeslat">ODESLAT</button>
</form>
<div class="kontaktni_informace" style="background-image: url(assets/icons/adresa.png);">
<span class="k_informace">Horní Domaslavice 293, 73951</span>
</div>
<div class="kontaktni_informace" style="background-image: url(assets/icons/mail.png);">
<span class="k_informace">info#bohmen.cz</span>
</div>
</div>
And my css:
body {
background-color: #212121;
}
.kontaktni_informace {
width: 40%;
float: right;
background-color: black;
background-repeat: no-repeat;
display: block;
margin-top: 40px;
}
.k_informace {
font-family: CovesLight;
font-size: 18px;
font-weight: bold;
padding: 8px 0px 8px 45px;
display: block;
color: #888888;
}
.kontaktujte_nas {
width: 50%;
margin: 0px auto;
padding-top: 40px;
display: block;
}
.kontaktni_formular {
font-family: TeXGyreAdventorRegular;
float: left;
width: 40%;
margin-top: 0px;
}
.kontaktni_formular input, textarea {
display: block;
width: 100%;
font-size: 16px;
padding: 7.5px;
border: 4px solid #888888;
}
.kontaktni_formular label {
display: block;
padding: 15px 0px 2.5px;
text-transform: uppercase;
font-size: 16px;
color: #ffffff;
}
.kontaktni_formular button {
font-family: TeXGyreAdventorRegular;
font-size: 18px;
margin-top: 15px;
padding: 5px 10px;
cursor: pointer;
margin-right: auto;
margin-left: auto;
display: block;
float: right;
}
.page_title {
margin-top: 0px;
text-align: center;
}
.title span {
font-size: 48px;
font-family: TeXGyreAdventorRegular;
color: #ffffff;
letter-spacing: 5px;
background: rgba(0, 0, 0, 0.5);
padding: 10px;
}
footer {
font-family: TeXGyreAdventorRegular;
text-align: center;
background-color: #111111;
padding: 5px;
color: #ffffff;
width: 100%;
}
.copyright {
font-weight: bold;
text-decoration: none;
color: #ffffff;
}
Try adding overflow: auto; to .kontaktujte_nas
You probably want something like this: https://www.freecodecamp.org/news/how-to-keep-your-footer-where-it-belongs-59c6aa05c59c/
Found by googling "footer at the bottom of the page" ;)
I believe your problem has been resolved.
But a quick review of your website which I think might help you now and forever:
Try following a semantic structure e.g let the header tag do the job of a heading just as you have the footer and let the main tag handle the remaining content e.g aside and so on.
So basically, i see you have some navigation elements but they are not inside a form of header=>nav=>ul, let that navigation elements at the topest of your page go into the header tag and let the lis go into the ul tag and let the ul go into the nav tag eg:
<header>
<nav>
<ul>
<li>
<a href=".../home">
Home
</a>
</li>
</ul>
</nav>
</header>
The reason why following a standard structure is because they abide by a rule that is been considered when building accessibility tools e.g screen-reader for disable people. And if you dont follow this standard, you will drain yourself either not doing it or doing it imperatively.
So in summary a body holds the header,the main and the footer.
Happy coding, cheers 😉🍺

Horizontal li - align element vertically

I'm using a <ul> with css display: inline; set to use as a toolbar/menu at the top of my page like this:
As you can see, the text vertically aligns perfectly, however the img on the left is too high, and the input box on the right is slightly low. I'm struggling to move them so they are perfectly vertically aligned.
Below is my CSS:
.mynav {
font-weight: 300;
border: 1px solid #ccc;
border-width: 1px 0;
list-style: none;
margin: 0;
padding: 0;
text-align: center;
background-color: #0067b1;
}
.mynav li {
display: inline;
align-items: center;
vertical-align:middle;
line-height:35px;
}
.mynav a {
color: white;
display: inline-block;
padding: 15px;
font-size: 14pt;
text-decoration: none;
}
.mynav input {
margin-left: 25px;
font-family: 'Open Sans', sans-serif;
font-weight: 300;
font-style: italic;
-moz-border-radius: 10px;
border-radius: 10px;
border: none;
padding: 5px;
width: 200px;
height: 25px;
margin-top: 0px;
}
.mynav i
{
font-weight: 300;
color: white;
font-size: 24px;
margin-left: 15px;
}
And my HTML (if needed):
<ul class="mynav">
<li><img src="http://www.advancegroupholdings.com.au/my_logo_nav.png" style="width: 100px; height:25px; padding-right:25px;" /></li>
<li>My Jobs</li>
<li>Obtain a Quote</li>
<li>Submit New Instruction</li>
<li>Settings</li>
<li>Help</li>
<li><input type="text" placeholder="Enter Your Ref or Job Number"/><i class="fa fa-search"></i></li>
</ul>
As for the input box, it has a padding of 5 which I have tried to remove with no luck. I have also set margin-top: 0px on the input, still no luck.
As for the logo, I'm also quite stumped. I've tried adding margin-top: 5px, but it's not working.
I also have found both these questions on StackOverflow:
<ul> horizontal nav bar... vertically-align element
css - verticaly align horizontal li
The first had no effect and the second wanted to change the CSS to display: flex, which for me gets rid of the horizontal bar, doesn't it?
Can anyone help me get the logo and the input box (and the magnifying glass) vertically centered? Thank you in advance!
Plunker here
I created a small bootstrap example for what you require. Different to what you have but give the required output more or less. Hopefully you can continue from here if this solution works for you.
HTML
<div class="col-md-2"><img src="http://www.advancegroupholdings.com.au/my_logo_nav.png" /></div>
<div class="col-md-1">My Jobs</div>
<div class="col-md-2">Obtain a Quote</div>
<div class="col-md-2">Submit a New Instruction</div>
<div class="col-md-1">Settings</div>
<div class="col-md-1">Help</div>
<div class="col-md-3"><input class="inputHeight" type="text" placeholder="Enter Your Ref or Job Number"/><i class="fa fa-search"></i></div>
</div>
</div>
CSS
.navbar {
width:80%;
font-weight: 300;
border: 1px solid #ccc;
border-width: 1px 0;
margin: 0;
padding: 0;
text-align: center;
background-color: #0067b1;
vertical-align:middle;
line-height:50px;
}
.inputHeight {
margin-left: 25px;
font-family: 'Open Sans', sans-serif;
font-weight: 300;
font-style: italic;
-moz-border-radius: 10px;
border-radius: 10px;
border: none;
padding: 5px;
width: 200px;
height: 25px;
margin-top: 0px;
}
Plunker Example
Adding next two rules to your image will center it correctly.
display: inline-block;
vertical-align: sub; /* or text-bottom */
As for the input , it looks correctly centered to me.
In your specific example it's enough to add vertical-align:middle; to <img> and to <a>, <i> elements! Also I'd recommend to have <li> elements as inline-block, not inline for more flexibility.
In general case, to align vertically the image height must be equal as
other element's line-height in the line and vertical-align:middle has to be set.
If image height is 25px then set:
.mynav li, .mynav i {
vertical-align:middle;
line-height:25px;
}
img {
vertical-align:middle;
height: 25px;
line-height:25px;
}
Here you go: https://plnkr.co/edit/Xf3uvvjuqykQMjnhVxes?p=preview

How can my button's position be centered without any kind of "margin cheat"?

How can I place my button in the center without any kind of "margin cheat" (for example setting margin-left: 525px;)?
HTML
<div id="banner">
<div id="bannerContainer">
<h1>H1 tag</h1>
Products
</div>
</div>
CSS
.bannerButton {
border: 2px solid #fff;
color: #fff;
font-weight: 300;
font-family: 'Raleway';
font-size: 20px;
display: inline-block;
background-color: rgb(63, 127, 191);
padding: 18px 60px 18px 50px;
margin-bottom: 50px;
margin-top: 50px;
position: relative;
margin-left: 525px;
}
.bannerButton:hover {
text-decoration: none;
background: #eaf;
color: #fff;
}
I've tried making it sit in the center but it didn't work out so well without me setting margin-left; 525px;, which in my case, centers the button under the text, please help me remove this "margin cheat" and do it in the right way.
The a act like text it means when you give text-align:center; to its parent, it will be placed in center of its parent.
You don't need to give margin to the a element. You can use text-align:center;.
#bannerContainer
{
text-align:center;
}
.bannerButton {
border: 2px solid #fff;
color: #fff;
font-weight: 300;
font-family: 'Raleway';
font-size: 20px;
display: inline-block;
background-color: rgb(63, 127, 191);
padding: 18px 60px 18px 50px;
margin-bottom: 50px;
margin-top: 50px;
position: relative;
}
.bannerButton:hover {
text-decoration: none;
background: #eaf;
color: #fff;
}
<div id="banner">
<div id="bannerContainer">
<h1>H1 tag</h1>
Products
</div>
</div>
If you set the position of the button to absolute, give it a set width, and add this it should center:
left: 50%; right: 50%;
Have you try this:
<center>Products</center>
I am not sure whether it is helpful to you..

How do you align text vertically inside a container regardless of # of links inside them?

I need some assistance and I've tried almost everything I know. What I am trying to do (and it doesn't matter if I have to use tables on order to achieve this)
http:// img602.imageshack.us/img602/8769/verticalcentering .jpg
I've looked online and tried out several examples but they all seem to blow up or not align properly in IE.
What I need (if its possible, I don't even know anymore) is to have text links that will align vertically within the container its in regardless of whether there is only one link present, or four.
What's been happening is that when I set the margin to 50% it centers fine if there is only one link there, but the remainder will fall below it no longer centering the links within the container.
The actual thing I am working on is this:
I have a header title above that stretches across the container. The next row I have an image on the left that is 150px by 150px - and next to that I have another container that has a height of 150px as well as this is the maximum height of this container - inside this container is where I would like my links to hang out vertically centered.
Is this even possible? or is it a pipe dream to think it will work in IE and is cross browser compliant?
It doesn't matter anymore if I have to resort to tables and css to achieve this... I just need some assistance with it as I have never had to vertically center anything depending on its content before and I just can't wrap my head around how to achieve this effect.
Any help would be greatly appreciated :) Thanks in advance!
HERE IS THE CSS AND HTML BELOW
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Link Module</title>
<style type="text/css">
<!--
.wrapper { height: 210px; width: 538px; background-color: #FFCCFF; }
.header { height: 47px; border-bottom: thin dotted #666; }
.txt-style {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-style: normal;
line-height: normal;
font-weight: bold;
color: #666666;
text-decoration: none;
text-align: left;
vertical-align: middle;
white-space: normal;
display: block;
}
.cos-sl-txt-cntr-two {
height: 150px;
}
.cos-sl-txt-cntr-two ul {
height: 150px;
margin-top: auto;
margin-bottom: auto;
}
.cos-sl-txt-cntr-two li {
margin-top: 50%;
margin-bottom: auto;
}
cos-sl-img-two {
width: 150px;
height: 150px;
background-color: #FF0033;
}
.learn-txt, .leader-txt {
color: #FF6666;
font-family: "Arial", Helvetica, sans-serif;
text-transform: uppercase;
font-size: 12px;
margin: 0;
padding-top: 2px;
padding-left: 10px;
letter-spacing: .75px;
}
.leader-txt {
color: #fff;
font-size: 23px;
font-weight: bold;
padding-top: 0px;
line-height: 24px;
letter-spacing: -0.25px;
}
.img-ctnr, .img-ctnr-two {
width: 150px;
height: 150px;
float: left;
padding-left: 12px;
}
/* IMAGE LOCATION */
.img-two {
width: 150px;
height: 150px;
display: block;
background-color: #FF99CC;
border: solid 3px #CCC;
}
.txt-cntr, .txt-cntr-two {
width: 406px;
height: 126px;
float: left;
}
.txt-cntr-two {
width: 250px;
height: 150px;
padding-left: 50px;
background-color:#CC99CC;
}
.txt-pos {
float: left;
width: 100px;
height: 50px;
padding-left: 20px;
}
/* NAME TEXT/TITLE TEXT */
.name-txt, .info-txt, .name-txt-title, .info-txt-link {
font-family: "Arial", Helvetica, sans-serif;
font-size: 13px;
color: #003466;
margin: 0;
padding-top: 18px;
padding-left: 13px;
}
.sl-name-txt-title {
color: #666;
font-size: 10px;
font-weight: bold;
}
/* INFO TEXT/TEXT LINK OVER-RIDE */
.info-txt, .info-txt-link {
padding-top: 0;
color: #333;
font-size: 12px;
line-height: 1.1;
}
.info-txt-link a {
color: #003466;
text-decoration: none;
}
/* Hover State for the web links */
.info-txt-link a:hover {
color: #ED1B24;
text-decoration: none;
}
-->
</style>
</head>
<body>
<div class="wrapper">
<!--CONTAINER HOLDING THE HEADER ELEMENTS-->
<div class="header">
<p class="learn-txt">Title</p>
<p class="leader-txt">Subtitle</p>
</div>
<div class="img-ctnr-two">
<div class="img-two">
</div>
</div>
<div class="txt-pos">
<p class="name-txt-title">Canada</p>
<p class="info-txt-link">www.mylinkhere.com</p>
</div>
</div>
</body>
</html>
.outer {
border: 1px solid red;
line-height: 5em;
}
.outer .inner {
display: inline-block;
vertical-align: middle;
line-height: 1.2em;
}
<div class="outer">
<div class="inner">
ABC
</div>
</div>
<div class="outer">
<div class="inner">
ABC<br>ABC
</div>
</div>
<div class="outer">
<div class="inner">
ABC<br>ABC<br>ABC
</div>
</div>