Text-indent bug in safari, or expected behavior? - css

I've put a little demo of the problem I'm trying to debug here: http://jsfiddle.net/bvDBb/7/.
The text-indent works as expected (or at least the way I expect it to) in Chrome, Firefox and Opera - it indents the first line of the text and then performs the wrapping again to keep the padding correct.
However, when viewed in Safari (5.1.7 on OS X 10.7.4) instead of wrapping the text, it creates a horizontal scrollbar and just moves the first line to the right - and with a large enough indentation, part of the line gets hidden and you have to scroll to see it.
Is that a bug in Safari, or am I just lucky that the rest of the browsers support it?
EDIT:
As Keith's idea of adding a <p></p> around the text fixes the layout (at least on Safari, haven't tried FF on Win), the question remains more like: what is the correct behavior and why?

try adding overflow-x:hidden; under overflow-y:auto; in .content

You should be using the actual CSS property text-indent for a text-indent like this. Such as:
<div class="contentWrapper">
<div class="content" style="text-indent: 100px;">
<img src="image.jpg" alt="some image" />
<p class="indent-me">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec porta mattis lectus, in fringilla magna posuere vitae.</p>
</div>
</div>​
p.indent-me {
text-indent:30px;
}

use 'em' instead of 'px'
text-indent:30em;

You can try the following, it works perfect both on desktop and mobile Safari.
input::-webkit-input-placeholder, textarea::-webkit-input-placeholder {
text-indent: 30px;
}

Related

Why is the background image not showing?

Background image is not showing for the banner, but I'm pretty sure my code is correct.
I'm trying to put a background image as a banner on my index page, which will have text over the top. I'm following a tutorial on YouTube (I know, I'm sorry) and I'm pretty sure that I've followed the example code perfectly (I will change it eventually but I just wanted a reference).
<main>
<section class="index-banner">
<h2>FILM. MODELING.<br>DESIGN.</h2>
<h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tellus velit, blandit ut nisi in.</h1>
</section>
</main>
.index-banner {
width: 100%;
height: 100vh;
background-image: url('img/tom.jpg');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
I should be getting a background image behind my <h1> and <h2> tags, but I'm not seeing anything. I tried removing the formatting but that's still not sorting it.
I found the problem was actually in a meta tag. Where I had...
<meta name="viewport" content="width=device-width, initial-scale=1.0 ">
...there was a space after the 1.0 still within the "". This obviously created the image issue.

Bootstrap 3 - Button height match panel (CSS3)

EDIT
For those of you stumbling over this post, I have found that there is a "new" standard called Flexbox. This allows you do what I want to do: Flexbox demos
I am trying to get the following effect:
However, I get this:
See jsFiddle: http://jsfiddle.net/abehnaz/8sPn7/3/
I tried height: 100% in CSS, but I had no luck. I think this might have to do with the fact that either the button style takes precedence over the height setting, or that the panel takes a dynamic height based on its contents (in this case, the image).
Is there a cross-browser/pure CSS way to make the button height match the panel height (with appropriate padding and fitting of content?)
Thanks!
HTML:
<div class="panel panel-default">
<div class="panel-body">
<div class="media">
<div class="media-object pull-left">
<button class="btn btn-info option-button">A</button>
<img src="holder.js/200x100" />
</div>
<div class="media-body">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
</div>
</div>
</div>
CSS:
.option-button {
height:100%;
}
**EDIT: ** To get to a solution that was acceptable, I ended up using the button in a media object. It does not automatically fit the entire height, but it does the job. It helped to apply the .btn-lg class.
In order for the browser to understand what 100% actually represents, you must give the containing div, in this case your media-object div, a height or have all parent divs have height 100%.
Think of it this way, the browser needs some number to start 100%, and when all parent divs have height: 100%; it uses the viewport (window size) for this number. If you have ever tried to do a sticky footer you have probably run into similar problems.
Here is a jsfiddle with a specified height:
http://jsfiddle.net/8sPn7/5/
Here is another jsfiddle with everything height 100% (a quick a dirty way to show you the 100% rule):
http://jsfiddle.net/8sPn7/6/
Bootstrap 4 :
add these classes d-flex align-items-stretch in the parent div.
Depending on your exact goal, this may not help, but adding height:100px to the containing div makes your height:100% work as expected. It looks like when the div expands to hold the image, that expansion isn't being carried through to the button like you'd expect.
Another thing that fixes the height is setting the button to position:absolute... but that's silly and unhelpful, unless it happens to be a fixed-width button and you can add a margin-left or something to space the rest of the content around it.

Google Chrome and IE7 Unordered List problem

I'm in the process of designing an online resumé, but am having problems in google chrome, and ie7 with an unordered list. While they render fine in the sidebar, for some reason in the content section, the first bullet point, floats to the far right of its container, with the text displaying fine, and all other bullet points and text positioning themselves fine. This bug doesn't happen in any other major browsers.
Here is the code, and a screen shot of what's happening.
<h2>Education</h2>
<div class="education">
<h3>Institution Name</h3>
<p class="date">Date 1000<br />~ Date 2000</p>
<p class="description">Vel augue ac a adipiscing? Facilisis. Dictumst vut rhoncus ut scelerisque, duis mid! Amet ultricies parturient cursus amet? Cum, diam sed platea ultrices in, phasellus augue amet.</p>
<ul>
<li><span>Masters of Design</span></li>
<li><span>fagjfjfhdgsdf</span></li>
<li><span>Random blabble text</span></li>
</ul>
</div>
.education ul{margin-left:120px;}
#sidebar{}
.education ul li,
#sidebar ul li{list-style:square; font-size:18px; line-height:18px;}
.education ul li span,
#sidebar ul li span{font-size:13px; color:#3C3225;}
ul{color:#11c9c7;}
Bug Images in IE7, and Google Chrome
Weirdly it works in IE6 and IE8, so I'm rather confused as I've coded no differently than I normally would, and the sidebar ul's using the same code as shown render fine. Does anyone know what could be causing this?
Add this to your stylesheet:
ul { clear: left; }
It seems your (what I assume are p tags) paragraphs have a float: left and an explicit width specified. However, the ul is still attempting to keep the paragraph to its left, and producing that strange result.

CSS word-wrapping in div

I have a div with a width of 250px. When the innertext is wider than that i want it to break down. The div is float: left and now has an overflow. I want the scrollbar to go away by using word-wrapping. How can i achieve this?
<div id="Treeview">
<div id="HandboekBox">
<div id="HandboekTitel">
<asp:Label ID="lblManual" runat="server"></asp:Label>
</div>
<div id="HandboekClose">
<asp:ImageButton ID="btnCloseManual" runat="server"
ImageUrl="Graphics/close.png" onclick="btnCloseManual_Click"
BorderWidth="0" ToolTip="Sluit handboek" />
</div>
</div>
<asp:TreeView ID="tvManual" runat="server" RootNodeStyle-CssClass="RootNode">
<Nodes>
</Nodes>
</asp:TreeView>
</div>
CSS:
#Treeview
{
padding-right: 5px;
width: 250px;
height: 100%;
float: left;
border-right: solid 1px black;
overflow-x: scroll;
}
As Andrew said, your text should be doing just that.
There is one instance that I can think of that will behave in the manner you suggest, and that is if you have the whitespace property set.
See if you don't have the following in your CSS somewhere:
white-space: nowrap
That will cause text to continue on the same line until interrupted by a line break.
OK, my apologies, not sure if edited or added the mark-up afterwards (didn't see it at first).
The overflow-x property is what's causing the scroll bar to appear. Remove that and the div will adjust to as high as it needs to be to contain all your text.
Or simply use
word-wrap: break-word;
supported in IE 5.5+, Firefox 3.5+, and WebKit browsers such as Chrome and Safari.
try white-space:normal; This will override inheriting white-space:nowrap;
It's pretty hard to say definitively without seeing what the rendered html looks like and what styles are being applied to the elements within the treeview div, but the thing that jumps out at me right away is the
overflow-x: scroll;
What happens if you remove that?
you can use:
overflow-x: auto;
If you set 'auto' in overflow-x, scroll will appear only when inner size is biggest that DIV area
I'm a little surprised it doesn't just do that. Could there another element inside the div that has a width set to something greater than 250?
Setting just the width and float css properties would get a wrapping panel.
The folowing example work just fine:
<div style="float:left; width: 250px">
Pellentesque feugiat tempor elit. Ut mollis lacinia quam.
Sed pharetra, augue aliquam ornare vestibulum, metus massa
laoreet tellus, eget iaculis lacus ipsum et diam.
</div>
Maybe there are other styles in place that modify the appearance?
I found that word-wrap: anywhere worked (as opposed to word-wrap: break-word mentioned in another answer).
See also:
What does "anywhere" mean in "word-wrap" css property?

Making a row of divs all be the same height using CSS

I have a row of divs that must all be the same height, but I have no way of knowing what that height might be ahead of time (the content comes from an external source). I initially tried placing the divs in an enclosing div and floated them left. I then set their height to be "100%", but this had no perceptible effect. By setting the height on the enclosing div to a fixed-height I could then get the floated divs to expand, but only up to the fixed height of the container. When the content in one of the divs exceeded the fixed height, it spilled over; the floated divs refused to expand.
I Googled this floated-divs-of-the-same-height problem and apparently there's no way to do it using CSS. So now I am trying to use a combination of relative and absolute positioning instead of floats. This is the CSS:
<style type="text/css">
div.container {
background: #ccc;
position: relative;
min-height: 10em;
}
div.a {
background-color: #aaa;
position: absolute;
top: 0px;
left: 0px;
bottom: 0px;
width: 40%;
}
div.b {
background-color: #bbb;
position: absolute;
top: 0px;
left: 41%;
bottom: 0px;
width: 40%;
}
</style>
This is a simplified version of the HTML:
<div class="container">
<div class="a">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer pretium dui sit amet felis. Integer sit amet diam. Phasellus ultrices viverra velit.</div>
<div class="b">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer pretium dui sit amet felis. Integer sit amet diam. Phasellus ultrices viverra velit. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer pretium dui sit amet felis. Integer sit amet diam. Phasellus ultrices viverra velit.</div>
</div>
This works, unless you change the min-height to something like 5em (demonstranting what happens when the content exceeds the minimum height), and you can see that while the text doesn't get cutoff, the divs still refuse to expand. Now I am at a lose. Is there any way to do this using CSS?
Here is one of those moments where you can get stuck between being idealistic or realistic. I understand that there is no semantic value to placing non-tabular data in a table strictly for formatting reasons but I don't want to see you bending over backwards to create a non-tabular solution to this problem simply for its own sake.
I am the first to shoot down non-semantic designs, trust me, but sometimes you need to face the fact that CSS + semantic markup does not work for all design scenarios. I don't know the accessibility needs of this site but I would recommend that you look to a more practical solution to this problem.
Cheers to you for approaching this the right way and looking for the proper way to solve it! Unfortunately this is one of the dark corners of CSS (along with vertical positioning within a block) that is just plain impossible to do without faux columns, javascript, or table cells.
Whichever you choose, please don't adhere to a standard for its own sake.
Making them exactly the same height can be a tricky thing, but if they just have to appear to be the same height, you may want to look at the faux columns technique.
I have tried a few other methods, but this is the most reliable way I have found of getting the effect, apart from using tables of course.
OK, the table thing turned out to be a little trickier than I thought it would be. It turns out the Javascript solution is actually the simplest (for my situation), since my app is an AJAX app and the framework uses Prototype.js. All it takes is a few lines of JS:
$$('div.container').each(function (element) {
var longest = 0;
element.descendants().each(function (child) {
if (child.getHeight() > longest)
longest = child.getHeight();
});
element.descendants().each(function (child) {
child.style.height = longest + 'px';
});
});
Thanks again for the help.
You can use JavaScript, but of course it will break without JavaScript enabled. Then there's tables, but this ruins the point of CSS. Perhaps seanb's answer could work, place a background image that creates the illusion that all columns go to the bottom. This is known as the faux background technique.
Or sit tight and wait for display: table-cell to be supported for all/most browsers.
Thanks for the answers, guys. I don't think the background image will work because the widths of the columns can also vary depending on how many columns there are (the user can change it). I guess I'll use tables :(
if your looking for a purely css option, and you can seperate the background of the block from the content then the answer is two have two bits of code for each block, one for the content, one for the background. this is how it's done:
<div id="wrapper">
<div class="content" id='one>
<div class="content" id="two>
<div class="content" id="three>
<div class="background" id="back-one">
<div class="background" id="back-two">
<div class="background" id="back-three">
</div>
Position the content divs using floats. Then position the backgrounds using absolute positioning (and a z-index to put them behind)
This works because the floats can set the height, and the absolutely positioned elements can have 100% height. It's a little bit messy, but does the job.

Resources