Here is the relevant HTML:
<div class="row">
<div class="arrow box">◄</div>Month Year<div class="dayMonth box"></div>►<div class="arrow box"></div>
</div>
Here is the css which the .html file that the above HTML is in links to:
*
{
margin: 0;
padding: 0;
}
body
{
font-family: "Times New Roman";
font-size: 12pt;
}
.dayMonth
{
width: 80%;
}
.arrow
{
width: 10%;
}
.row
{
width: 58em;
background-color: gray;
margin-right: auto;
margin-left: auto;
}
.box
{
float: left;
text-align: center;
}
This is the output:
The "row" is centering in the browser right but the stuff inside it (the two arrows and the Month Year) aren't doing what I want.
What I think this should be doing is, because there are two arrows and both of their widths is sent to 10% and then the dayMonth width is 80% that all the divs should take up the entire "row" (because they sum to 100%) and that the text "Month Year" should be centered within the "row" because the .dayMonth css class says it should be centered in its div and because its div should be the center 80% of the "row". This, obviously, isn't happening though.
I don't want a different solution (per se) I want to know why the code I've written doesn't express the idea that I want it to express, doesn't work the way I want it to.
I think I must be misunderstanding how %'s governs widths. http://www.w3schools.com/css/pr_dim_width.asp says that %'s "Defines the width in percent of the containing block" though and that looks like %'s should do what I intend them to do so I'm thoroughly confused.
Where have I gone wrong?
This works fine for me in Opera.
I did notice that you have "Month Year" outside of the <div>. Try putting it inside and see if that fixes it.
Edit
And again with the last arrow, it's outside its <div> tag as well.
Your HTML should be like this:
<div class="row">
<div class="arrow box">◄</div><div class="dayMonth box">Month Year</div><div class="arrow box">►</div>
</div>
Also, once you do this, the row <div> will not have a height so you might want to explicitly set a height (try 20px).
Once i fix your HTML, it works fine for me in FF. You have empty divs and the Month Year and left arrow are not in their respective divs.
I figured this out real quick when i used firebug. You should debug using firebug or chrome's developer tools.
<div class="row">
<div class="arrow box">◄</div><div class="dayMonth box">Month Year</div><div class="arrow box">►</div>
</div>
Try the code like this, with the content inside the divs. Worked for me in FF, IE7/8, and Chrome. You may want to use a hex value for the .row color, like #333333 - the color wasn't rendering for me in any browser but IE7.
First, your markup is wrong, that's why you're seeing issues. It has to do with the content not being in the divs, but outside of them, causing height issues with the floated elements.
Here's the work corrected:
http://jsbin.com/ezari4/edit
Related
Say I have a <span> that contains a very long sequence of numbers - long enough that it flows right off the right hand side of the page.
Most browsers would give me a scrollbar such that I can then scroll left and right.
How can I prevent the ability to horizontally scroll?
I've tried body { overflow-x: hidden; }, which works for desktop Chrome, but Chrome for Android retains the ability to horizontally scroll.
How can I absolutely guarantee no scrolling?
(I can adjust both HTML and CSS in this scenario, but I cannot use JS.)
Do you mind breaking the string of numbers? If not, you can try word-break:break-all. Here's the same HTML with and without word-break.
#break {
width: 300px;
word-break: break-all;
padding: 3px;
}
#noBreak {
width: 300px;
padding: 3px;
}
<div id="break">
<span>123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789
</span>
</div>
<div id="noBreak">
<span>123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789
</span>
</div>
I think applying overflow-x :hidden works.
But unless you share the part of your code its difficult to answer to your requirement.
The better approach i would suggest is to use the container class of bootstrap 4, which makes the div responsive and you can keep this span inside that, or keep it in the div.
<div class="wrapper container">
<div class="row">
...
</div>
</div>
The row class will always give -15px margins.
and container class gives padding of +15px.
Your question can get a clearer response if you can share the code snippet.
I'm trying to add 2 tabs in a wrapper div and am having trouble getting them to lie next to each other, taking up half the width each. I added the following css to each one:
width: 50%;
height: 100%;
display: inline-block;
For some reason they keep appearing beneath one another instead of next to one another.
I made a JsFiddle to show whats happening: http://jsfiddle.net/5zLoyc7q/1/
Can anybody please help me get them so they're lying to next eachother like normal tabs?
Why not float? Make sure your box-sizing is border-box. Next:
<div class="wrapper">
<div>Hello world</div>
<div>Guten Tag</div>
</div>
CSS:
.wrapper {
overflow:auto;
}
.wrapper > div {
float:left;
width: 50%;
}
display:inline-block adds 1px of whitespace to the right of the element. Also, if you're not displaying as border-box, you could run into issues with your box model in other words your 50% isn't what you think it is.
updated fiddle: http://jsfiddle.net/5zLoyc7q/2/
make sure to clear the floats.
I'm currently creating a website and I came across a strange thing: I have a content div that's 950 width and centered on the page. Inside that I have a header div, a menu div and some other content div. I would like the menu div and that other content div to be right next to each other so I thought about using float:left on both divs. However, when I use this float:left on the menu div, it's getting pushed to the right and I can't figure out why. I think some other element is pushing it to the right.
I'm using a custom Drupal theme, a subtheme of Zen to create the page by the way.
Here's the HTML I'm using to create the page (without the header):
<div id="root">
<div class="content">
<div class="left-menu">
<ul>
<li><p>Camera</p></li>
<li><p>Audio</p></li>
<li><p>Licht</p></li>
<li><p>Lenzen</p></li>
<li><p>Grip</p></li>
<li><p>Accessoires</p></li>
<li><p>Recorders</p></li>
<li><p>Transport</p></li>
<li><p>Edit suits</p></li>
<li><p>Crew</p></li>
</ul>
</div>
<div class="products-overview">
This is some other content that I want to the right of the menu.
</div>
</div>
And here are some CSS properties I've set on left-menu and products-overview:
.left-menu {
margin-top: 10px;
background-color: #BBB;
width: 150px;
float: left;
}
.products-overview {
background-color: #BBB;
float: left;
}
Could anyone please explain me why the left-menu is being pushed to the right?
Hmm, I believe this is a result of the normalize.css stylesheet you're using.
The problem stems actually from the .header element, which has a table within it. The normalizing stylesheet has a margin-bottom:1.5em applied to the table, which translates into a margin on the .header element (since it has no padding/border), which in turn sends the .left-menu to the right (since the margin causes there to be no space for it to fit on the left).
Adding to your current .header table definition can fix this, with a simple:
.header table{
margin-bottom: 0;
}
I hope this is what you were looking for! If not, let me know and I'll be happy to help further. Good luck!
I tried to replicate your problem. I did and found a solution that should work. Just set the products-overview class to float:none. See this fiddle. http://jsfiddle.net/shaansingh/yj4Uc/
In Mozilla Firefox it looks ok to me. From your code, I can only see that you need a width for the content div. and watch the dimensions, especially left/right padding and borders.
I've run into a strange problem in IE9, spent a lot of time tracking and reproducing it.
So we have the following markup:
<div class="container">
<div class="movable">
<div class="stuff">Stuff</div>
<div class="stuff special">Stuff Special</div>
<div class="stuff">Stuff</div>
<div class="stuff">Stuff</div>
</div>
</div>
This results in something like this:
We would like to move the yellow box up (out of the container) and make the .stuff elements clearing. We would like to float at least one .stuff element, let's choose .special, so we do this:
.movable { margin-top: -70px; }
.stuff { clear: both; }
.special { float: left; }
On the left, the results we get in Chrome and Firefox, on the right IE9:
As you can see, IE9 is somehow stuck applying the negative margin-top, and it will always get stuck at the element which has right or left float and clear: both; applied on it at the same time. The combination of these two properties is needed, only one of them will not trigger this behavior.
A jsFiddle that demonstrates the problem and can be played with
This problem has come up in a quite large application, for certain reasons I cannot use top instead of margin-top, positioning would break other stuff.
Anybody has any idea how to help IE9 correctly display this?
Clear the .movable element. I don't know how you're normally doing it, adding a clearfix class etc. If not, just add overflow:hidden to it for example. Floating it also fixes it, but that might not work for your real page.
.movable { margin-top: -70px; overflow:hidden; }
jsFiddle
I'm having a very hard time trying to come up with html/css for a layout to suite the following:
Where the left area is a static menu. The right area is dynamic content, generated using a call to ASP.Net's RenderBody method. You may not believe it, but I have been trying to figure this out for hours. I keep getting either the right section ending up underneath the left section taking 100% of the width or not displaying at all, with Chrome's object inspector saying its 0 pixels wide.
I feel like a complete idiot as this seems as if it should be easy as pie. Could I please get some help?
There's several ways to go about this. Here's one not particularly fancy but straight-up way to go about it:
<body>
<div id="menu">MENU</div>
<div id="content"> content <br /> content <br /> content </div>
</body>
CSS:
div { border: 2px solid black; } /* demo purposes */
#menu {
float: left;
width: 150px;
}
#content {
margin-left: 154px; /* menu width + (2 x menu.border-width) */
}
See this jsfiddle for a working sample.
This solution has the added benefit that your content region will take up exactly 100% of the remaining width of its parent:
<div class="parent">
<div class="content">blah...</div>
<div class="left-menu">blah...</div>
</div>
CSS:
.parent { padding-left:200px;width:100%; }
.content { position:relative;float:left;width:100%; }
.left-menu { position:relative;float:left;width:200px;right:200px;margin-left:-100%; }
Excellent tutorial on fluid layouts: http://www.alistapart.com/articles/holygrail
Works in IE7 and newer, Safari/Chrome/Opera/Firefox...
The best way to do this is by using the already considered safe to use box-sizing property.
Take a look at the tinkerbin -> http://tinkerbin.com/AcJjYk0r
It works as you want it to. Fixed width for the menu, percentage based width for the content area.
Then...
...if you want the background-colors to expand to the highest of the heights between the two boxes (remember, one times the menu can be higher than the content box, and vice-versa), then the only way to go about it (no javascript) is to use a background image and place it below the two boxes. With css3 gradients (safe to use too) it's pretty easy. Take a look:
http://tinkerbin.com/3ETH28Oq