css box 'skips' on second line [closed] - html

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Within a WordPress plugin (own creation) I want to position some WooCommerce category images... but there something strange happens.
Each category box is defined more or less in the following way :
<div class="edu-cat-item">
<img src="some-image.jpg>
Title of the cat
</div>
In the CSS the boxes are made to float to the left...
.edu-cat-item {
box-sizing:border-box;
width: 175px;
float: left;
padding:10px;
}
edu-cat-item img {
border-width:2px;
border-style:solid;
}
.edu-cat-item a {
text-align:center;
margin-left:auto;
margin-right:auto;
}
And -not really a surprise- it works... HOWEVER!
The customer wants the selected category to have an orange border.
So in the PHP code an extra class is added to one specific item... The HTML becomes :
<div class="edu-cat-item edu-sub-select">
<img src="some-image.jpg>
Title of the cat
</div>
And the CSS gets an additional :
.edu-sub-select img {
border-color: #ff9900!important;
border-style: solid;
border-width: 2px;
}
And now strange things happen... when it is more than one row, the second row 'indents' one position behind the selected cat... Would love to post images but I need 'reputation 10' to do so...
However willing to share them by mail.

You are missing a quotation mark:
<img src="some-image.jpg>
Maybe that's just an error in posting the question though. Could you create a jsfiddle showing the problem, it's hard to understand what you mean by "indent"
By the way, you might want to try getting rid of float:left; and replacing with display:inline-block;. I avoid the unpredictable behavior of float wherever possible.
Was curious so I made a simplified fiddle myself: http://jsfiddle.net/bca1m1n2/
What's happening is that the border causes the height of the orange element to be taller than the rest. When a floated element goes to the next line, it positions itself against the orange element because the orange element is taller. Behavior seems strange, but is correct - so don't use floats for alignment :)
So if you give .edu-cat-item a fixed height, that also solves the problem
.edu-cat-item {
width: 175px;
height:100px;
float:left;
}
Cool question OP

Alternatively to what Kurt Serge wrote, you could use an outline instead of a border. This way your "border" (outline) does not affect the flow of items.
Here's a little definition of CSS outlines from MDN / W3C (they write the same thing):
Outlines do not take up space
MDN adds the following detail:
they are drawn above the content.
So your css would look like this:
.edu-sub-select img {
outline-color: #ff9900!important;
outline-style: solid;
outline-width: 2px;
}

Related

Show only small portion of an image [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Recently when I right clicked on the cross icon and saw the background image in the Tags section of Ask Question page I saw that it consisted of multiple icons other than the cross. I searched it on google and came to know that its done using html and css. The search results didn't help.
I am new to html and after searching I am introduced to this new language css. This may be a simple question to answer for experts like you but headache for beginners like me. Please I really want to know how its done.
Thanks in advance.
1. Its done using background-image,background-position for an element with set width and height.
See this fiddle(It contains a Facebook Image instead) :
http://jsfiddle.net/axF59/
2. These CSS queries can be solved urself by using Inspect Element. Like you saw the background image by Right Click > View Background Image , in similar way you can see CSS of web page by Right Click > Inspect Element in browsers like Mozilla ,Chrome ...
It's called a spritesheet. You'll find vast of amounts of info, tips and tutorials if you search the internet for spritesheet + js/css
This is done using the CSS background-position and background-image property. It allows all of the sprites to be loaded using a single image.
The background-position CSS property sets the initial position [...] for each defined background image.
Source: https://developer.mozilla.org/en-US/docs/Web/CSS/background-position
The CSS background-image property sets one or several background images for an element. The images are drawn on successive stacking context layers, with the first specified being drawn as if it is the closest to the user. The borders of the element are then drawn on top of them, and the background-color is drawn beneath them.
Source: https://developer.mozilla.org/en-US/docs/Web/CSS/background-image
Example
HTML
<span class="sprite sprite1"></span>
<span class="sprite sprite2"></span>
<span class="sprite sprite3"></span>
CSS
.sprite {
display: inline-block;
/* Replace this with a live image. */
background-image: url("http://www.example.com/example.jpg");
height: 16px;
width: 16px;
}
.sprite1 {
/* This doesn't actually need to be here, because this is default. */
background-position: 0 0;
}
.sprite2 {
/* Move 16 pixels to the left. */
background-position: -16px 0;
}
.sprite3 {
/* Move 16 pixels up. */
background-position: 0 -16px;
}

Embedded overflow:hidden only partially working

Problem: In one type of embedded styling "overflow:hidden" is working fine, and in another type of embedded styling it does not.
Here is the CSSDesk code (jsfiddle is not working as of this writing).
Background: In my project I have to use HUGE tables to show variables coming from a db - up to 75 variables per page. I tried my best using divs alone, but I wasted 20 hours and ultimately, I went back to tables (For you CSS purists, I apologize).
In some of my td's the data is a bit long, and needs to be "hidden" (it doesn't matter in this particular case because the data is just a "preview"). I've searched the web, and did an experiment in which the only styling element that could use "hidden" is a div (I tried tds and spans in an experiment and they don't work).
In one td, I'd like to put one variable on the left, and another on the right - most of the time, both will fit into the td, but on a very long variable it's OK to chop off part of the right variable. So, I write the CSS and html, and style the divs so that they meet my criteria - those are the upper two tds on the CSSDesk page noted above. Everything works fine.
BUT! Over the last few months I've learned that it's possible to "mix" multiple styles in the "class" part of the element identifier (e.g. <td class="redcolor blueunderline">) and I've found that on many occasions it is VERY convenient to use "little additions" on an element that is the only one on a page, and you'd have to rewrite/add a whole embedded style or change the style sheet (e.g. Name, address, phone number, zip and you only want to "bold" the name - class="identifers" vs class="identifiers bold") - I wonder if you experts ever do something like that?
So I played a bit and got most of it working EXCEPT for the "overflow:hidden".
For the upper left div in the CSSDesk example I use this CSS and html (it works great):
.leftdivclass {
float:left;
background-color:green;
color:black;
border:2px solid yellow;
overflow:hidden;
white-space:nowrap;
width:25%;}
<td><div class="leftdivclass" >Upper Left 123456789</div>
For the upper right div in the CSSDesk example I use this CSS and html (it works great):
.rightdivclass {
float:right;
background-color:red;
color:black;
border:2px solid yellow;
overflow:hidden;
white-space:nowrap;
width:25%;}
<div class="rightdivclass" >Upper Right 123456789</div></td>
For the lower left div in the CSSDesk example I use this CSS and html (everything works but the "hidden" - note the numbers sticking out)
.floatleft {
float:left;}
.bgblue {
background-color:blue;}
.bgred {
background-color:red;}
.lcwhite {
color:white;}
.lcblack {
color:black;}
.border2y {
border:2px solid yellow;}
overflowhidden {
overflow:hidden;}
.wsnowrap {
white-space:nowrap;}
.width25pc {
width:25%;}
<td><div class="floatleft bgblue lcblack border2y overflowhidden wsnowrap width25pc">Lower Left 123456789</div>
But if I use the same html and add "style="overflow:hidden" everything works fine, like in the lower right example of the CSSDesk example.
<div class="floatright bgred lcblack border2y overflowhidden wsnowrap width25pc" style="overflow:hidden;">Lower Right 123456789</div></td>
Questions:
Why would a single embedded css style containing "overflow:hidden" work, yet when it is parsed out to a single addition to a class command it doesn't work? And why would it work if I added "style="overflow:hidden" - inline?
Do you experts ever use little "class snippets" like this?
Again, I thank you in advance.
You can mix and match these classes. If it saves redundancy, great. If it confuses classes and container classes (i.e. the parents they are inside of) then it gets kind of hard to debug your problem.
Most likely it's not working because either its parent or another class is conflicted with the overflow property. Inline styles like style="overflow:hidden;" almost always get prioritized the highest, but remember that overflow has a default property of visible.
If you call 2 classes, one having overflow:hidden; and the other overflow:visible;, then there's a chance that you won't get your desired effect.
Keep in mind, too, that a selector like this
#divid .divclass
will always win over
.divclass
and will be treated with greater priority.
Also, have you tried
overflow:hidden !important;
which tends to take precedence over everything. Hope that helps.

Photoshop to CSS [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Is it possible to convert Elements I created with Photoshop.
f.e. If I created a "skin" for a button in Photoshop without any Text in it. Could I convert it to CSS so that I can add a Text and adjust the Button's height/width later when adding the button to the HTML?
If it is possible, how?
Thanks in advance!
there are a lot of tutorials that will teach you to slice photoshop to html & css
http://net.tutsplus.com/tutorials/site-builds/from-psd-to-html-building-a-set-of-website-designs-step-by-step/
http://net.tutsplus.com/articles/news/photoshop-to-html-upcoming-ebook-from-nettuts-and-rockable/
but to answer your question. It all depends the button you designed. But for the standards wone you will have to copy the background of your button into a new document and save as a png or jpg (make sure to slice a 1 or 3px image that can be repeated)
and then with some css3 magic you can style your button and make sure it fits the content of your button.
eg:
input[type="text"]
{
/*add rounded corners*/
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
background:#000 url('../images/button-background.jpg') repeat-x top left;
paddng:3px 6px;
margin:2px 0;
}
the url to the background should point to the image and best add a matching background color when the button is to big
What you're trying to do has many, many different solutions. Here are just a couple:
1. You could create the button using css3 only
warning: this solution will not work on older browsers without javascript plugins
html
Hello World
css
.button {
border:solid 2px white;
-moz-border-radius:5px;
border-radius:5px;
-moz-box-shadow:5px 5px 5px black;
box-shadow:5px 5px 5px black;
padding:20px;
background:lightgray;
color:darkgray;
}
2. You could create the button using 2 images
photoshop:
create the image of the left side of the button.
make sure it's much longer than it needs to be.
the right end doesn't matter:
___________________________
/
| button1.png ...
\___________________________
now create the right side of the button.
make sure it's very short, like below:
_____
\
... button2.png |
_____/
html
<a href="http:/my.url.com/" class="button">
<span>Hello World</span>
</a>
css
.button {
background: url(path/to/button1.png);
}
.button span{
height: (height-of-button2.png);
line-height: (height-of-button2.png);
padding: 0 20px;
background: url(path/to/button2.png) no-repeat right top;
}
These are just a couple variations.
EDIT: apologies. the above code was wrong. i fixed it just now.
No, it's not possible to convert directly from Photoshop Elements to a HTML and CSS version that scales. You need to either export the whole button as one big image (and use a separate image for each button), or construct the button yourself with CSS.
Sexybuttons - http://www.oscaralexander.com/tutorials/how-to-make-sexy-buttons-with-css.html would let to create a button in Photoshop and once you have built it in CSS it would adjust its width to whatever text you put in it, as for height...not sure.
It's not a good idea to use Photoshop for creating code. It creates god awful looking code. It's best to just slice and name your slices, save them to images and then write code by hand. Unfortunately it's a very manual process and bridging the gap between design and code isn't something humans have done well yet!

Could someone explain collapsing margins? I find them extremely annoying

I have a div that contains a link:
<div id="like_bar"></div>
With some CSS:
#like_bar{
width:140px;
height:26px;
background:url('bar.jpg');
}
#like{
display:block;
width:20px;
height:20px;
margin:3px 36px;
background:url('mini_img.png');
}
The link is placed at the top of the bar and the margins on the link are applied to the bar. This is annoying. Could someone explain these collapsing margins, how to avoid them and what they're used for.
There are many ways to "fix this".
Perhaps the easiest for you would be this:
#like_bar {
overflow: hidden
}
Other ways include:
Add some padding
Add a border (even border: 1px solid transparent is enough)
float the element
position: absolute
And, like in the snippet above, set overflow to a value other than the default of visible.
You also asked:
what they're used for
A common use case is the <p> tag.
See: http://jsfiddle.net/thirtydot/tPaTY/
Without margin collapsing, certain things would become annoying.
Because I'm lazy I'm just going to link to a few resources:
My answer here explains why the box model is the way it is, which is related to margin-collapsing being included.
The w3c css spec defines the behavior of margin collapsing. It's an expected behavior for convenience given the box model. You don't need to worry about double margins between blocks of content with it. What it sounds like you actually want is some padding around #like, rather than margins.
Think of CSS as a content-centric inside→out approach to styling, rather than a programmed outside→in approach.

I am trying to align two divs side by side [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 months ago.
Improve this question
I am having problems messing with some css to get it to look the way I want.
Here is the page:
https://diggardensnursery.com/shop/house-home/
I would like catalog the image to be on the left, with the description to the right and the attributes and add to cart below.
I have tried to float the divs to the left and the right. I'm not sure if I have to stick the image in a div and float it left separately. I'm not too versed with PHP so I've been trying to mess with just the CSS to get it to work.
In your site you've got a ton of stuff floating. This is not the best way to do it. Float isn't the same as position, so I think all the things you have set to "float-right" aren't doing what you think. You don't want to float stuff all over the place, just one thing.
In this case the only thing you should be floating is the image, you just need to float that one object left and use it's margins and paddings to line up everything else.
This is a good reference that should help you to get more control over floats.
As for fixing your page:
First, you need to make the image float left. Put sufficient padding to the right, and if necessary put a lot of padding above/below to make things not wrap underneath the image.
div.product_grid_display div.product_grid_item img {
border:medium none !important;
>>> float:left;
>>> padding:0 20px 35px 0; /*this padding worked for me */
}
Second turn off this float left and add a clear:both property;
div.product_grid_item {
>>> float:left; /*DELETE THIS LINE*/
height:auto !important;
margin:4px 8px 8px 0;
position:relative;
clear:both;
}
Turn off the float on div.grid_product_info, div.product_text, and input.wpsc_buy_button as well, and I would add "margin:10px 0 0 28px;" to input.wpsc_buy_button.
You don't need the divs called "div.grid_view_newline" if you add a "clear:both" to div.product_grid_display, so I'd get rid of that.
That should take care of it.
use "float:left;" example: http://www.citiport.net/Sandbox/Jeff/pictureBorder.html
If I understand your question then you need to use spans inside of divs.
<div>
<span>image</span>
<span>description</span>
</div>
<div>
<span>buttons</span>
</div>