How do I align these 3 divs and a span? - html

You can see the implementation here: http://jsfiddle.net/kqKfK/
I am trying to get everything in one line - with the span "2-up" at the far right. It would also be nice if each of the internal divs are equally spaced amongst themselves.
Edit: This is how I want it to look:
Edit 2: This is how it looks after the implementation of Kyle's suggestion. I would like for it to be aligned properly:
Edit 3: This is how it looks after Kyle's second implementation.

Float them left:
#viewbar div
{
float: left;
}
Example.
#viewbar div
{
float: left;
width: 25%;
border-right: 1px solid #000;
}
Updated example. Changed a few things in your original code too.
After your comment, try this:
#viewbar div
{
float: left;
width: 25%;
border-right: 1px solid #000;
background-image: url(path/to/file.png);
background-position: center;
}
Another example.
After you provided the full example, I came up with this, looks very much like the screenshot you posted.
Click here to see my example. I changed a lot of things, including equal heights on each div, adding margins and padding :)

Try this:
.compv-navbar {
font-weight: bold;
background: #f9f4c0;
height: 23px;
width: 220px;
border: 1px solid #c97d7d;
word-spacing: 0px;
letter-spacing: 2px;
margin: 0 auto 5px; /* top, right, bottom, left */
padding: 5px 0px 7px 0px; /* top, right, bottom, left */
text-align: center;
}
#two-up-icon {
width: 40px;
height: 17px;
float: left;
}
#two-up-icon:hover {
color: #ddd;
cursor: pointer;
}
#three-up-icon {
width: 40px;
height: 15px;
float: left;
}
#three-up-icon:hover {
color: #ddd;
cursor: pointer;
}
#four-up-icon {
width: 40px;
height: 15px;
float: left;
}
#four-up-icon:hover {
color: #ddd;
cursor: pointer;
}
.view_name {
font-family: "Helvetica", serif;
color: #f9f4c0;
font-style: normal;
font-weight: bold;
font-size: 11px;
word-spacing: 0px;
letter-spacing: 0px;
background: #1a1a1a;
padding: 1px 3px 1px 3px; /* top, right, bottom, left */
border-radius: 5px;
-moz-border-radius: 5px;
-khtml-border-radius: 5px;
-webkit-border-radius: 5px;
float: right;
margin-right: 3px;
}
http://jsfiddle.net/kqKfK/10/

just add one more style:
.compv-navbar div { float: left; top: 0; }

One line of CSS:
#viewbar div, #viewbar span { width: 25%; float: left; }
Updated jsFiddle: http://jsfiddle.net/yahavbr/kqKfK/2/
Edit: By the way, alt is only for images, other elements should use the title attribute instead.
Edit II: if you have anything after that div, put such thing before to clear the "floatness":
<div style="clear: both;"></div>

Related

Border bottom and the header move together

In my nav, I am separating my section with some text and a horizontal line. For each section this repeats. I am doing this as shown below:
.navSectionHeader {
font-size: 1em;
color: #fff;
margin-left: 5px;
margin-bottom: 10px;
font-family: "Roboto";
font-weight: 700 !important;
border-bottom: 2px solid #6c6c6c;
}
/*.navSectionHeader::after {
content: ' ';
display: block;
border: 2px solid;
border-color: #6c6c6c;
margin-left: 0px !important;
}*/
The issue is, my text is now pretty much stuck to the left of the parent div. It should be with some margin to the left while keeping the bottom border start from 0px to the left. When I try to move it with margin-left: 5px; it ends up moving the border-bottom as well. I tried this with ::after as shown in the commented bit, adding !important to the end but nothing changes. Am I doing this the wrong way? Sorry, I'm a front-end noob!
Edit: The section header is in a <span> if it makes a difference.
Use padding instead of margin.
.navSectionHeader {
padding-left: 5px;
}
An example to see difference,
div {
display: inline-block;
width: 100px;
height: 20px;
border-bottom: 1px solid black;
background: red;
color: white;
}
.padding {
padding-left: 5px;
}
.margin {
margin-left: 5px;
}
<div class="margin">margin</div><br>
<div class="padding">padding</div>

Why is my floated image being moved out of my div when I float other div's?

Why is the floated image being moved next to a paragraph inside of a div move outside of that div when I float other div elements?
For example, I have a div class with a paragraph in it and that when I float the image inside of that class it wraps around it the way I want?
.container {
margin:0px auto;
width: 1400px;
background-image: url(back.png);
padding-top:10px;
height: 2000px;
}
.main {
background-color: #f7f4f4;
margin-right: 600px;
box-shadow: 10px 10px 10px #705656;
border-radius: 10px;
border: 2px solid red;}
.green {
border: 2px solid blue;
width: 400px;
margin-right: 40px;
background-color: #8bed8f;
float: right;}
.aside {
background-color: #f47575;
width: 400px;
margin-right: 40px;
border-radius: 4px;
float: right;
clear: right;}
.trac input[type=button] {
background-color: #9b878b;
font: weight: bold;
font-size:15px;
color: white;
border-radius: 6px;
border: none;
padding: 20px 10px;
margin-left: 300px;
margin-top: 5px;}
.tmac {
float: left; }
If I understanded your problem (the question you asked is a bit messy), you have to consider that floating HTML elements wraps to the closest position relative container.
If you want to stick a float to a specific container, you just have to add to the CSS class of that container the rule position: relative

Why inner div container overflows?

From below code,
.shoppingform {
width: 400px;
height: 800px;
background: #7CB9E8;
/* url(some img)*/
padding-left: 15px;
padding-top: 10px;
color: white;
font-size: 12px;
font-weight: bold;
border-radius: 5px;
}
.customercardtype {
border: 1px solid white;
color: black;
font-weight: normal;
padding: 10px 2px 5px 5px;
background: #B284BE;
width: 90%;
border-radius: 5px;
position: relative;
height: 8%;
margin-top: 5px;
}
.customercardtype .formlabel {
display: block;
height: 20%
}
.customercardtype .cardtypecontainer {
position: absolute;
width: 100%; /* Any problem here? */
top: 40%;
height: 50%;
border: 1px solid red;
}
<form class="shoppingform" action="someaction.php" method="get" enctype="multipart/form-data">
Step3: Card details
<div class="customercardtype">
<label class="formlabel">Cardtype:</label>
<div class="cardtypecontainer">
</div>
</div>
</form>
I would like to understand,
Why inner div container overflows?
This is because the width of an element is actually width + left padding + right padding + left border + right border.
As your width is 100% and additional to this will push it over 100%, making it overflow its parent.
If you use box-sizing: border-box, that will fix this issue.
That's a quick summary, lots more in depth info here: https://css-tricks.com/box-sizing.
The reason it overflows is because position absolute visually speaking, positions your element outside the normal flow of the site. This is intentional and powerful if you use it correctly. However in your case, the parent container of cardtypecontainer was not taking control of the absolute positioned element, therefore it overflowed outside its container.
Then, I changed cardtypecontainer to have relative position, which will work as you intended it to, because relative position does not change the intended layout of the element. For your case it means, cardtypecontainer will stay within the bounds of its parent container.
.shoppingform {
width: 400px;
height: 800px;
background: #7CB9E8;
/* url(some img)*/
padding-left: 15px;
padding-top: 10px;
color: white;
font-size: 12px;
font-weight: bold;
border-radius: 5px;
}
.customercardtype {
border: 1px solid white;
color: black;
font-weight: normal;
padding: 10px 2px 5px 5px;
background: #B284BE;
width: 90%;
border-radius: 5px;
position: relative;
height: 8%;
margin-top: 5px;
}
.customercardtype .formlabel {
display: block;
height: 20%
}
.customercardtype .cardtypecontainer {
position: relative;
margin-top: 10px;
width: 100%;
height: 50%;
border: 1px solid red;
}
<form class="shoppingform" action="someaction.php" method="get" enctype="multipart/form-data">
Step3: Card details
<div class="customercardtype">
<label class="formlabel">Cardtype:</label>
<div class="cardtypecontainer">
</div>
</div>
</form>

My footer in CSS does not pay attention to my right and left content, only to the middle content

Ok this is my problem:
The left float and right float are somehow not put into my container and the footer only pays attention to the middle content part. What am I doing wrong?
I could show it with a picture but I cannot add one because I don't have 10 rep.
It must be a simple fix, I have read about clear:both etc but that all does not work unfortunately.
#container
{
position: relative;
width: 58.5%;
background: #FFFFFF;
margin: 0 auto;
border: 1px solid #336600;
text-align: left;
}
#header
{
height: 160px;
background-image:url(images/bannerboven.jpg);
}
#sideleft
{
position: absolute;
top: 160px;
left: 0;
float: left;
width: 22%;
background: #CCFFFF;
padding: 15px 10px 15px 20px;
}
#sideright
{
position: absolute;
top: 160px;
right: 0;
float:right;
width: 23%;
background: #CCFFFF;
font-size: 0.8em;
padding: 15px 10px 15px 20px;
}
#mainContent
{
margin: 0 26% 0 26%;
padding: 0 10px;
background: #0F0;
}
#footer
{
padding: 0 10px 0 20px;
background: #DDDDDD;
text-align: center;
font-weight: bold;
}
I'm not sure what you are trying to achieve without knowing your html structure, but the problem stems from the fact that you have absolute positioning on your left and right containers as well as a floted positioning.
The default positioning for a html element is static, so you either float everything or absolute position everything. Here's something to help you understand positioning better, it's very easy and you'll be on your way in 5 minutes: http://www.barelyfitz.com/screencast/html-training/css/positioning/
Also, you should post a jsfiddle link with the html included so we'll understand better what you are trying to achieve if you need further help. My guess is that Rohit Azad's solution is correct, you just have trouble understanding positioning.
Hi i check to your code i think you want to this
HTML
<div id="container">
<div id="header">Header</div>
<div id="mainContent">
<div id="sideleft">Left</div>
<div id="sideright">Right</div>
</div>
<div id="footer">Footer</div>
</div>
Css
#container
{
width: 58.5%;
background: #FFFFFF;
margin: 0 auto;
border: 1px solid #336600;
}
#header
{
height: 160px;
background:red;
background-image:url(images/bannerboven.jpg);
}
#sideleft
{
float:left; width: 22%;
background: #CCFFFF;
padding: 15px 10px 15px 20px;
}
#sideright
{
float:right;
width: 23%;
background: #CCFFFF;
font-size: 0.8em;
padding: 15px 10px 15px 20px;
}
#mainContent
{
padding: 20px 10px;
background: green;
overflow:hidden;
}
#footer
{
padding: 0 10px 0 20px;
background: #DDDDDD;
text-align: center;
font-weight: bold;
}
Live demo

How to make this HTML object in a middle and one line?

Here you can see the problem: http://jsfiddle.net/kAQrX/1/
I want the magnifier, search text and search box (input) to display in one line, and in a middle of the #search div.
I'm out of ideas now.
Use the css background-image property and a left padding, instead of an image tag! :)
E.g.
.search_content {
background: url('http://www.iconeasy.com/icon/thumbnails/System/WebGloss%203D/Magnifier%20Icon.jpg') no-repeat;
padding-left: 55px;
}
JSFiddle
Try This :
.magnifier {
width: 35px;
height: 35px;
margin: 3px;
float:left; //<----
}
See Feedle http://jsfiddle.net/kAQrX/2/
You can display it inline, or as inline-block. See this fiddle
there you go:
HTML:
<div id="search">
<div class="search_content">
<span class="search_text">SEARCH:</span>
<input type="text" name="query" class="search_box">
<img src="http://www.iconeasy.com/icon/thumbnails/System/WebGloss%203D/Magnifier%20Icon.jpg" class="magnifier">
</div>
</div>
CSS:
#search {
background: url("images/search.png") no-repeat;
width: 382px;
height: 41px;
margin-right: 10px;
float: right;
}
.magnifier {
width: 35px;
height: 35px;
margin: 3px;
vertical-align:middle;
}
.search_text {
margin-left: 3px;
text-shadow: 0px 0 black, 0 1px black, 1px 0 black, 0 1px black;
color: #FFF;
font-weight: bold;
}
.search_box {
width: 162px;
height: 33px;
padding: 0px 12px 2px 10px;
}
.searchbox_content {
margin-top: 10px;
}
You can add the following:
.searchbox_content {
display: inline;
}
to get the 3 elements in one line.
To get them into the center of #search you can add the text-align-Attribute:
#search {
text-align:center;
}