Hello guys I'm doing a CSS/HTML course at the moment and I have to assign a border to images on my website.
1. I gave the images a class:
<a href="https://de.wikipedia.org/wiki/Elefanten"
target="_blank"
class="images>
<img src="elefant.jpg" alt="Elefant">
In my CSS file I used following code to assign the border:
.images
{
border-left: 10px solid red;
border-top: 10px solid red;
border-bottom: 10px solid red;
border-right: 10px solid red;
}
Should be very easy code but the in Chrome it doesnt really seem to work correctly. Here a screenshot :
https://snipboard.io/VAipY8.jpg
This is probably a very beginner thing but I hope someone can help me :)
If you are trying to make the image a clickable link you should wrap it in between the <a> tag
<img src = " ">
And to add border to the image you should give class to the <img> tag not to the <a> tag.
Currently you are applying border to the link inside the <a> tag.
You're missing the closing / tag in the img tag. and the closing " in the class attribute. and the closing tag for the anchor tag. Write your code like this:
<a href="https://de.wikipedia.org/wiki/Elefanten"
target="_blank"
class="images" >
<img src="elefant.jpg" alt="Elefant" class="elephantImg" />
</a>
Change the css as follows:
img {
border-left: 10px solid red;
border-top: 10px solid red;
border-bottom: 10px solid red;
border-right: 10px solid red;
}
You can use this if you decide not to use the class attribute on the elephant image otherwise, if you decide to use the elephantImg class attribute use this css:
.elephantImg{
border-left: 10px solid red;
border-top: 10px solid red;
border-bottom: 10px solid red;
border-right: 10px solid red;
}
Related
I added a couple of tags in HTML(already linked to CSS):
<img src="../html/img/image1.jpg">
<img src="../html/img/image2.jpg">
and had my CSS coded like:
img[src^="../html/img/"]{
border: 10px solid black;
}
However, it didn't apply to both tags in HTML no matter how many times I refreshed the web page.
Would you please tell me why my css attribute selector doesn't work? Thank you!
If you want to apply it to both img tags you could just do
img {
border: 10px solid black;
}
How about this selector?
img[src*="/html/img/"]{
border: 10px solid black;
}
Try this ... you just select the img not src or other code....
img{
border: 10px solid black
};
Your question is based on the fact that your code doesn't work, but it does:
img[src^="../html/img/"]{
border: 10px solid black;
}
<img src="../html/img/image1.jpg">
<img src="../html/img/image2.jpg">
<img src="not-bordered.jpg">
I suggest your look somewhere else for the problem.
I have some code to make an arrow and im trying to add a title attribute to it. Here is the arrow code:
#arrow-right {
width: 0;
height: 0;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 10px solid white;
}
#arrow-right:hover {
border-left: 10px solid gray;
}
<div id="arrow-right" title="text here"></div>
Before I added the 'title' attribute, it worked fine, changing to color to grey on hover, but after I added the 'title' attribute, the css color changing stopped working but the title started working. Is there any way to have both of these work at the same time?
replace
<div id="arrow-right" ; title="text here"></div>
with
<div id="arrow-right" title="text here"></div>
I found the problem. I had some js declaring the style in the element like:
<div id="arrow-right" title="text here" style="border-right: 10px solid white;"></div>
Along with the style declared in the stylesheet and that broke it. I just had to remove the style declared in thr div and that fixed it
I have a problem with the chrome browser. When I make custom "hr" tag with a "div" and top and bottom border, there is a white 1px line between the borders ...
IE and Firefox do well.
.nav_links_container_line {
border-top: 1px solid #096ebd;
border-bottom: 1px solid lightgrey;
}
<br><br><br><br>
<div class="nav_links_container_line"></div>
I try different thing (overflow, height 0px) but with no success.
My Chrome Browser is up to date (Version 62.0.3202.94)
Thank you
Simon
Actually that is not a white space, you used light-grey color to bottom and both border top and bottom attached and it's illusion like there is white space. If you want shadow for bottom of your custom hr then you can use following css for it -
.nav_links_container_line {
border-top: 1px solid #096ebd;
box-shadow: 0px 2px 10px #000;
}
What about using a real <hr/>? With that, I don't have the rendering issue you encountered, and it actually makes more sense to use hr in its own role.
.nav_links_container_line {
border-top: 1px solid #096ebd;
border-bottom: 1px solid lightgrey;
border-left: none;
border-right: none;
}
<br><br><br><br>
<div class="nav_links_container_line"></div>
<hr class="nav_links_container_line"/>
I have below code in html page:
<img id="image_java" alt="image_not" src="images/java-icon.png">
in css page the below code:
#image_java: focus {
outline: 2px solid blue;
}
I have also tried:
img:focus{
outline: 2px solid blue;
}
but non of them seem to work, they are suppose to display a blue margin around the image when focus.
Does any one know how to do that? thank you!!!
Actually you CAN focus an <img> - with the help of tabindex:
img:focus {
outline: 2px solid blue;
}
<img src="http://www.w3schools.com/images/w3logotest2.png" tabindex="0">
You can't "focus" an image unless you have an interactive element or navigate to it using tab. Try adding an interactive element on a wrapper div like so:
Html
<a class="imageAnchor" href="#">
<img id="image_java" alt="image_not" src="http://www.w3schools.com/images/w3logotest2.png" />
</a>
CSS
.imageAnchor:focus img{
border: 2px solid blue;
}
http://jsfiddle.net/4x7wg7sb/1/
If its an anchor tag you can also use
A:focus img{border: 2px solid blue;}
Try using the border property instead of the outline property. It should look like:
img:hover {
border: 2px solid blue;
}
Edit: Use hover instead of focus
So, I am doing my mothers small business website to save her money and learning quite a bit of CSS in the process. I'm having a small problem though, I am making a Gallery page that link to 2 different pages, I want the text at http://area25dallas.com/s/gallery.htm that is sitting next to each image (showroom and staging) (also I know the images are the same, waiting on more from the momma). I want these to be on top but when I add an a{} to the following CSS controlling the image rollover effect it screws up all my other links on the website.
.imagedropshadow {
margin:30px;
padding: 10px;
border: solid 1px #EFEFEF;
}
a:hover img.imagedropshadow {
border: solid 1px #CCC;
-moz-box-shadow: 1px 1px 10px #999;
-webkit-box-shadow: 1px 1px 10px #999;
box-shadow: 1px 1px 10px #999;
}
Is there a way I can make an a{} and a:hover{} specific to these links and images without messing the whole CSS of the site up? Thanks
To create CSS for a specific element there are several approaches you can take:
Create a specific class for the element. <a class="image-link"></a>
a.image-link{
//styles go here
}
You can refer to the unique context of the link. For example if it is located inside a div with ID content. <div id="content"><a></a></div>
#content a{
//styles go here
}
or if it is the only a that can be directly inside a p element <p><a></a></p>
p > a{
//styles go here
}
When adding styles to your html it is often good to consider the scope of the CSS. Note that you can declare styles multiple times for a element. So you can could make CSS for every a element inside your HTML and CSS for a elements within a specific scope.
More on CSS Selectors:
Sitepoint
Quirksmode
Net Tuts
Smashing Magazine
Have you tried this code?
img.imagedropshadow:hover {
border: solid 1px #CCC;
-moz-box-shadow: 1px 1px 10px #999;
-webkit-box-shadow: 1px 1px 10px #999;
box-shadow: 1px 1px 10px #999;
}
#content .imagedropshadow {
margin:30px;
padding: 10px;
border: solid 1px #EFEFEF;
}
#content a{
}
#content a:hover img.imagedropshadow {
border: solid 1px #CCC;
-moz-box-shadow: 1px 1px 10px #999;
-webkit-box-shadow: 1px 1px 10px #999;
box-shadow: 1px 1px 10px #999;
}
Ideally you should put a div around your images with a class or ID and use that ID/class value to select the anchor (a{}) tags you need. I just picked the ID of the container DIV
Remember, When you are making your selectors really specific, such as #Content .myDiv a.link instead of #Content a.link, the more specific overrules the less-specific.
Just a tip