A inside figure or figure inside a? - html

Go down to the HTML part of the code snippet. The first box has a figure that wraps an a with an img tag. The second box has an a that wraps a figure with an img tag.
Which of the boxes is the most correct one?
Should figure wrap a or should a wrap figure?
* {
padding: 0;
margin: 0;
}
body,
html {
height: 100%;
}
body {
display: flex;
justify-content: center;
align-items: center;
}
.box {
border: 1px solid #ccc;
max-width: 200px;
margin: .5rem;
}
img {
vertical-align: top;
width: 100%;
}
.text {
padding: 2rem;
}
<!-- A inside figure -->
<div class="box">
<figure>
<a href="#">
<img src="http://placekitten.com/g/500/500">
</a>
</figure>
<div class="text">Text</div>
</div>
<!-- Figure inside a -->
<div class="box">
<a href="#">
<figure>
<img src="http://placekitten.com/g/500/500">
</figure>
</a>
<div class="text">Text</div>
</div>

I have checked and reviewed shared HTML. also, debugged/analyzed in firebug (Firefox add-ons) Box-Model. a properly wrapped to figure.
The second box is correct. a completely properly wrapped to figure.
<!-- Figure inside a -->
<div class="box">
<a href="#">
<figure>
<img src="http://placekitten.com/g/500/500">
</figure>
</a>
<div class="text">Text</div>
</div>
Thanks

I'd argue that both your variations are semantically correct, and they both validate within the HTML5 standards.
Both the <a> and <figure> tags are flow content, and permitted content inside the very same tags is also flow content according to MDN. So wrapping either one of them inside the other would make perfect sense.
If you want to link the figure contents including <img>, <figcaption> or any flow content, I'd wrap everything inside the <a> tag.
If you want to link just the <img> or any other specific element, I'd wrap everything inside the <figure> tag and then the anchor inside.
I'm not sure about accessibility concerns in this case, but I think it depends™ on the content.

Related

Text-align: center wont's apply to a link after an image

I found the way to make a link to align, if I do the break between img and the link.
<section id="home" style="background-image: url(https://images.unsplash.com/photo-1526374965328-7f61d4dc18c5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1500&q=80);">
<h1>It's my super wooper page</h1>
<img class="profile-picture" src="assets/img/My_Picture.JPG" alt="picture of myself">
<br>
<a class="btn-cv" href="#">Download CV</a>
</section>
The question is WHY the link won't just align, as it is a text-element. And what is even more "weird", the margin won't work for the link, so it keeps sticking to the image. I know, I could give the image some margin-bottom, but I's really like to understand, what is happening in the backgrond.
If you want to align the link in the center. You should put text-align: center; on the parent element and not on the <a>. It's because the <a> is an inline element.
Can you please check the below code? Hope it will work for you. <a> is an inline element. if you are applying a margin to <a> tag then you need to give display:inline-block property to <a>
Please refer to this link: https://jsfiddle.net/yudizsolutions/pt68qczy/
.text-center {
text-align: center;
}
.btn-cv {
margin: 10px 0px;
display: inline-block;
}
<section id="home" style="background-image: url(https://images.unsplash.com/photo-1526374965328-7f61d4dc18c5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1500&q=80);">
<h1>It's my super wooper page</h1>
<img class="profile-picture" src="assets/img/My_Picture.JPG" alt="picture of myself">
<br>
<div class="text-center">
<a class="btn-cv" href="#">Download CV</a>
</div>
</section>

<a> links simply not working/not clickable

I have some images in the footer, wrapped in tags. For some reason they are not working whatsoever... I am totally lost.
website is HERE
any help would be great (footer is on every single page on the site)
relevant html:
<div class="socialLinks">
<div class="footerTitle">Follow Us At</div>
<div class="iconsContainer">
<a href="https://www.facebook.com/NewWaveAcademyMMA/">
<img class="socialicon" src="../images/fb.svg">
</a>
<a href="https://twitter.com/NewWaveMMA?ref_src=twsrc%5Egoogle%7Ctwcamp%5Eserp%7Ctwgr%5Eauthor">
<img class="socialicon" src="../images/twit.svg">
</a>
<a href="https://www.instagram.com/newwaveacademymma/">
<img class="socialicon" src="../images/insta.svg"></a>
</div>
</div>
Your .footercopyright div is overlapping the rest of your footer.
Since you're using floats to align the .affiliations and .sociallinks divs, you should wrap them in a clearfix. This will clear your floats and prevent your copyright div from expanding to fill the space.
<div class="footerbox">
<div class="clearfix">
<div class="affiliations"></div>
<div class="socialLinks"></div>
</div>
<div class="footercopyright"></div>
<div>
.clearfix:after {
content: "";
display: table;
clear: both;
}
The links on your webpage are working. You are unable to click on the links because you have placed a div over your links. Actually, you are clicking this div, not the links. This is the div (look it up in the browser console):
<div class="footercopyright">Copyright, All Rights Reserved NWA 2018</div>
You may resolve this by either removing this div, or by setting a higher z-index for the links container.
you can add clear in below class and work.
Also, noticed small dotted below links::
You use display:inline-block; on <a> to remove this
`.footercopyright {
position: relative;
color: #232528;
max-width: 100%;
font-size: 10pt;
text-align: center;
padding: 5px 0px;
clear: both;
}`

How to align a picture beside <h1> HTML

I'm trying to create a logo picture next to my title on my website.
Problems:
Works with Span
Span is too small
Doesn't work with H1 - H6
Could anyone help me?
Here is my code.
.title img {
vertical-align:middle;
}
<div class="title">
<h1><b>Ex</b><i>Creations</i></h1>
<img src="http://placehold.it/100x100" alt="ExCreations logo." width="100px" height="100px">
</div>
<div class="wrapper">
<div class="nav">
<b>Ex</b><i>Creations</i>
<i>Current Projects</i>
Site <b>Map</b>
<i>Have any questions?</i>
</div>
</div>
But it doesn't work. Although it does with span. Could anyone fix this but keep the h1?
h1 is a block-level element (therefore the img wraps into a "new line").
Instead place your <img> tag inside the <h1>
<div class="title">
<h1>
<b>Ex</b><i>Creations</i>
<img src="http://s8.postimg.org/9znb8gixh/logo.png" alt="ExCreations logo." width="100px" height="100px">
</h1>
</div>
than you can use any vertical-align value for the Logo using
.title h1 img{
vertical-align: middle; /*https://developer.mozilla.org/en/docs/Web/CSS/vertical-align*/
}
SEO-wise it's also nice to have an image with alt "Logo" inside the primary H1
This is because h1 has 100% width, add the following CSS code:
.title h1 {
display: inline-block;
}

Center div vertically when img tag is not displayed

I have div which includes:
<div class="field-content">
<a href="http://url.com">
<img width="320" height="194" src="http://img.jpg"></img>
<div class="tile_content">
<div class="tile_title">content</div>
<div class="tile_body">content</div>
</div>
</a>
</div>
In some cases this field-content has not img-tag at all. Then I want tile_content to be vertically centered to field-content.
When img-tag exists then image is positioned at top of field-content and tile_content is under image.
This demonstrates those two situations. In first one there is image and under image tile_content. In second one there is only tile_content - no img at all.
Any ideas/tips how to make this work?
My CSS:
.field-content {
margin: 0px 0px 15px;
height: 365px;
width: 320px;
display: block;
overflow: hidden;
float: left;
background-color: #FFF;
.tile_content {
}
The only Thing you Need to know is vertical centering of div. This Problem is already solved here:
How to vertically center a div for all browsers?
You can add class has-image to .field-content do you can define own Styles for block with Image and without it. For example:
<div class="field-content has-image">
<a href="http://url.com">
<img width="320" height="194" src="http://img.jpg"></img>
<div class="tile_content">
<div class="tile_title">content</div>
<div class="tile_body">content</div>
</div>
</a>
</div>
So your CSS Looks like
.field-content.has-image {
}
If I got your question correct, then simply,
Put that img tag inside a div, give that div the same height as that you have given for image, so, it won't matter if the image is inside that div or not. it will always appear as a block, so won't collapse
OK, first time, I took it other way, I thought there are 3 divs, Sorry for that.
Here is the fiddle link:
enter code here
http://jsfiddle.net/happy2deepak/6U3kw/1/

How to have images in line with text in css

I'm creating the footer of my website using html and css.
I want to have the two facebook and twitter images in line with the text so that everything in the footer is in line with eachother
At the moment my footer code is
HTML -
<div class="footer content">
<img src="Images/facebook.png">
<img src="Images/twitter.png">
<p> Address line 1
Address line 2
Address line 3
</p>
</div> <!--end of footer-->
Can anyone help please?
<p> tags are block-level elements. Use an inline element such as <span>:
<div class="footer content">
<img src="Images/facebook.png" />
<img src="Images/twitter.png">
<span>
Address line 1
Address line 2
Address line 3
</span>
</div>
Alternatively, if you're able to use CSS, you can define both elements as inline-block:
.footer.content > img,
.footer.content > p {
display: inline-block;
}
Example 1 jsFiddle
Example 2 jsFiddle
EDIT: It might also be wise for semantics to use <address>, rather than <span>. For example:
<div class="footer content">
<img src="Images/facebook.png" />
<img src="Images/twitter.png">
<address>
Address line 1
Address line 2
Address line 3
</address>
</div>
Since <address> is also a block-level element, you'll need to include the correct CSS as follows:
.footer.content > img,
.footer.content > address {
display: inline-block;
}
Final jsFiddle example
.content img, .content p {
float:left
}
float: left/right - depending where you want it to be
The simplest way is to use <span> instead of <p>. <p> makes a new paragraph which is quit "independent".
Check out this working example here.
.channels li {
float: left;
margin-left: 0.625em;
}
If you want to use new tags specific for footer and address this is my example:
<footer id="footer">
<span><img src="Images/facebook.png" alt="some text" /></span>
<span> <img src="Images/twitter.png" alt="some text"/></span>
<span>
<address>
Address line 1
Address line 2
Address line 3
</address>
</span>
</footer>
#footer {display:inline;}
#footer address {display:inline }
The alt to images was added to help with disability and standards.
I find a lot of the time I need to adjust the position of the image to align with the text. You can do this by wrapping the text and image in a div with position relative and then assigning position absolute on the image. Then you ca add top and margin left to adjust the position relative to the text. https://jsfiddle.net/edhescqn/3/
HTML:
<div class="amazonLink">
<a href="#">
<div class="amazonLink__text">Buy Now on Amazon</div>
<img class="amazonLink__image"
src="http://cdn2.iconmonstr.com/wp-content/assets/preview/2016/240/iconmonstr-amazon-1.png" width="24px" height="24px">
</a>
</div>
CSS:
.amazonLink {
position: relative;
margin-top: 10px;
}
.amazonLink__text {
display: inline-block;
line-height: 40px;
}
.amazonLink__image {
display: inline-block;
position: absolute;
top: 8px;
margin-left: 5px;
}
Use display:inline-block css property for image ad text to display image and text in same line