I have a page where I'm trying to use a lot of CSS.
I have a main wrapper class with background and everything and then a content class within that. Within the content class I then have IDs for various articles.
Within some of these articles I'd like images aligned to the right, but I don't seem to be able to do this.
From what I know
<div class="article">
In 1904, Sunderland's management was embroiled in a payment scandaat he would repay the money after his benthe money, claiming it had been a gift. An investigation conducted by the as part of a "re-signing/win/draw bonus", which violated the Association's rules. Sunderland were fined £250 (£20 thousand today), and six directors were suspended for two and a half years for not showing a true record of the club's
<div class="picha">
<img src="image/test.png">
</div>
</a>
</div>
should apply picha (i.e. align right, set a border) to the image...but it doesn't.
How is this handled?
Or better yet is there a way to set rules for images within a ID that isn't specifically for images? i.e. text is handled one way but all images posted in that id get special treatment.
edit- so updated attempt:
css has:
div.article {
border: solid;
background-color:red;
}
div.article img{
border: 10px solid #f1f1f1;
float: right;
}
and page has:
<div class="article">
<a name="article1">
random text
<img src="image/test.png">
</a>
</div>
The image shows and alligns right but is below the text and outside the text's box, I'd like it quite neatly inside the article box but to the right.
If I add float left to the text then the article box stretches but the image remains below the text.
edit2- and I'm a stupid newbie. Had to have the image before the text. Done!
If you want to access this nested div, you can either do as #Aquillo said.
Or do this:
.article .picha
{
/*Your css*/
}
and
.article .picha img
{
/*Your img css*/
}
Why don't you use?:
div.article {
// This applies to all content
}
div.article img {
// This applies to the image
}
div.article span {
// This applies to everything inside a span
}
You could write your text inside a span like this:
<div class='article'>
<img src='' />
<span>My text</span>
</div>
This way you don't need a wrapping div for you image.
Related
I wrote simple CSS to align text using the w3schools example with:
text-align:center
When I add an underline in the same format, the underline works.
Here's the snippet:
.CenterIt {
text-align:center;
}
.UnderlineIt {
text-decoration:underline;
}
<span class="UnderlineIt">
<span class="CenterIt">Registration Form</span>
</span>
Here's the w3schools page (the align text section):
https://www.w3schools.com/css/css_align.asp
In my full code I have the text I want to center inside another box. I've tried it both inside that box and outside any boxes. It doesn't center.
.CenterIt {
text-align:center;
display:block;
}
.UnderlineIt {
text-decoration:underline;
}
<span class="UnderlineIt">
<span class="CenterIt">Registration Form</span>
</span>
The display property of span by default is inline. i.e.,
display:inline;
Therefore, <span> will take only the width of its content. In contrast, block elements like <div>, by default, take the full line (and thereby the full width of the page) for its content.
To make the text-align work for <span>, you need to change it into a block element.
Set
display: block;
for the span with .CenterIt class. This will make .CenterIt take the full line (and thereby the full width of the page), and then the text-align: center; will centralize the content.
Try this. You need to wrap it with a container unit of <div>
<div class="UnderlineIt">
<div class="CenterIt">Registration Form</div>
</div>
Following will work as well
<span class="UnderlineIt">
<div class="CenterIt">Registration Form</div>
</span>
It might work better if you run “display: flex;” on the container span and “justify-content: center;” on the child span. Flexbox is a little easier to use when placing items within a container.
Because your html, is in wrong format. You cant have a span child of a span.
try like this:
<div class="CenterIt">
<span class="UnderlineIt">Registration Form</span>
</div>
to have the span centered , without a parent div you would need to put the display, as block.
so you could have on your html and css like this:
span{display:block;}
.CenterIt {
text-align:center;
}
.UnderlineIt {
text-decoration:underline;
}
html:
<span class="UnderlineIt CenterIt">Registration Form</span>
TL;DR : Before you read anything, the desired end-result is illustrated in the image below, otherwise refer to the JSFiddle. Preferably, I would like to only use CSS and not modify the DOM structure.
The icons must be aligned completely to the right (hence the .pull-right), but the icons must be stacked vertically (Sometimes some icons must not appear, so they are .hidden, like the .fa-undo icon in the second row).
(When I say 'the icons' i mean the <i> tags and the <img> tag)
The icons must not make the textarea go down (no margin on top of the textarea).
Hopefully, the WIDTH of the textarea would be dynamic and not statically put to width: 90%; for example. It should take as much width as possible, without interfering with the vertical icon stack.
Here is the end result that I want (in a perfect world this would be done using CSS and the same HTML DOM I provided)
In general, images that are UI elements, and not content, should be CSS backgrounds, not inline images. You then use class names to control the image content.
You should be doing this, or something similar:
td.fr {
background-image:url(/images/fr.gif);
background-repeat:no-repeat;
background-position: top right;
}
The same should go for your buttons. Use <button> and style the background.
Not exactly what you wanted I'm afraid, but this is how I'd achieve that result:
fiddle
<div class="pull-right icons">
<img src="http://www.convertnsftopst.net/images/gb.gif" class="pull-right" />
<i class="fa fa-reply"></i>
</div>
td .icons{
width:20px;
text-align:center;
}
Here is the end result that I want (in a perfect world this would be done using CSS and the same HTML DOM I provided)
I was unable to do it without adding another pull-right container, I fear that doing it with only CSS would end up being an odd hack
Fixed here : http://jsfiddle.net/QTXxp/2/
What was lacking when I asked this question was the clear:right; and the use of <div> (or display: block;)
Here is the CSS (if you're too lazy to open the JSFiddle) with the addition of the boostrap class pull-right on the div.icons
textarea.hover-edit {
width: 90% !important;
}
div.icons {
width: 10% !important;
}
div.icons > div > i.fa {
margin-top: 4px;
margin-right: 4px;
}
div.icons > div.action-icon-right {
float:right;
clear:right;
}
I'm trying to create a sort-of table of clips on my webpage. The idea is that it's basically (in my mind) a table with a thumbnail in the left column, and then a right column would house a title, where the story appeared, a date, and a description. I have no trouble doing this using HTML <table> but I'm trying very hard to get better at CSS.
I've combed this (very helpful) site and am far ahead of where I was this morning. However, I'm having trouble with setting the "height." I don't want to set a firm height. I want the "row" to adjust to the height of an image or block of text, and for the height to be the same for both "columns."
Right now I have this.
HTML:
<p class="imageclass">thumbnail</p>
<p class="textclass">all sorts of text, separated by line breaks</p>
CSS:
.container {
width:620px;
}
.imageclass {
float:left;
width:120px;
}
.textclass {
float:left;
width:500px;
}
Have you tried applying overflow: hidden to .container?
If this is really going to be a "row", why not wrap all of the content in a div? This div will scale to be the height of its tallest child. Then if you need to manipulate the rows you can just use CSS selectors for the row class:
<div class="row">
<p style="height:200px; background: black;" class="imageclass">thumbnail</p>
<p class="textclass">all sorts of text, separated by line breaks</p>
</div>
Using a method I've done before but having issues. Not sure if it's a sprite or what.. Basically you have two versions of an image saved into one file with them stacked on top of each other and use CSS to adjust the margins when hovering. Here's an example of it working successfully: http://minimalpluscreative.com
Trying to do the same thing here, but running into issues with overflow:hidden; not working. Instead, the the full (double) image is shown. Here's what it looks like: http://cl.ly/023p1I1D1W0W3a1T1q1R It should be just the top half of the image with overflow:hidden; preventing the other half from showing.
Help? Some kind of syntax error I'm sure...
HTML:
<div id="work" class="sub">
<h3>MUSIC VIDEOS</h3>
<img id="show_fire" class="thumbnail sprite" src="images/daniel_gomes_soundoffire_sprite.png" />
</div>
CSS:
.sprite {
width:140px;
height:61px;
overflow:hidden;
}
.sprite:hover {
margin-top:-61px;
}
I've never seen this done before except with background images, but I don't see why not… it just seems like you need a lot of extra css, and extra html to get it to work as opposed to a background image.
As was said earlier, it's hard to see the problem without seeing your actual code in context, but based on what I see, there could be a few potential things wrong:
You need to wrap the image in a containing element, and assign the width, height and overflow to that. Hidden overflow will hide what's outside of the boundaries that div contains. The image element is the image, it doesn't contain the image, so setting it to overflow:hidden isn't going to hide andything, and assigning it a width will just resize it, not "crop" it (which is the effect you're going for). So you'd need something like:
<div id="work" class="sub">
<h3>MUSIC VIDEOS</h3>
<a class="sprite" href="#">
<img id="show_fire" class="thumbnail" src="images/daniel_gomes_soundoffire_sprite.png" />
</a>
</div>
with this css:
.sprite {
width:140px;
height:61px;
overflow:hidden;
}
.sprite img {
margin-top: 0;
}
.sprite:hover img {
margin-top: -61px;
}
I suggest you use 'a' as the containing element, as not all browsers will recognize the hover pseudo-class on tags other than anchor tags.
I know you think using an image instead of a background image is simpler, but using background images, you can accomplish all this with only one element and less css.
In the example site you refer to, the overflow:hidden property is set on the outer 'div#a'
'div#work' in your code should have it's overflow set to hidden.
Thus when you change the margin on your image it will move within the frame of your outer div.
Additionally I had to add a tag name to the hover declaration.
<html>
<head>
<style>
#work{
position:relative;
overflow:hidden;
width:140px;
height:61px;
}
div.sprite {
margin-top:0;
}
div.sprite:hover {
margin-top:-61px;
}
/* instead of an image */
.sprite div{
height:61px;
}
.red {background:red}
.blue {background:blue}
</style>
</head>
<body>
<div id="work">
<div class="sprite">
<div class="red">a</div>
<div class="blue">b</div>
</div>
</div>
</body>
Basically, what I'm trying to create is a page of div tags, each has an image inside them and I'm trying to use CSS3's nth-child to alternate the float of that specific image.
But for the life of me, I can't get the nth-child to locate those images. Here is my code so far...
CSS
.featureBlock img:nth-of-type(even) {
float: left;
}
.featureBlock img:nth-of-type(odd) {
float: right;
}
This is the HTML of one of those div tags....
<div class="featureBlock">
<h1>Multisize Players</h1>
<div class="featureHelpBlock">More help with this</div>
<img src="http://office2.vzaar.com/images/features/ft_multisize_players.png">
<span class="featureContent">
<p>A variety of player sizes is important as we recognise the fact that no two videos or websites are ever the same and you will want something that suits your site’s look. So if you record your video in 4x3 (not widescreen) or 16x9 (widescreen) we have the range of player sizes to suit your exact needs.</p>
<p>We encode the video at the time of uploading in the size that you choose so that the picture and sound quality is retained throughout. Users can choose from the following sizes:</p>
</span>
<br style="clear:both">
</div>
Hope this makes sense.
Assuming you have several elements with the class featureBlock inside the same parent element, you would want to do this instead:
.featureBlock:nth-of-type(even) img {
float: left;
}
.featureBlock:nth-of-type(odd) img {
float: right;
}
See it in action on jsFiddle: http://jsfiddle.net/PZWd6/
The SitePoint CSS reference says of nth-of-type:
This pseudo-class matches elements on
the basis of their positions within a
parent element’s list of child
elements of the same type.
You can read more about it at the sitepoint reference page:
http://reference.sitepoint.com/css/pseudoclass-nthoftype