I am trying to put a few images in a row and display text that is directly underneath them and centered this is for my college work. I have tried some code but could not get it to work.
<div class="test">
<p>
<a href="https://www.facebook.com">
<img height="200px" style="display: block; margin-left: 100px; float: left;border: 2px solid white; border-radius: 100%; margin-top: 30px;" src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-9/12512240_1005566046198664_2775546349199755757_n.jpg?oh=a37edadd99a4631e165accf6bd193a9f&oe=58C8AD58">
<h3>Test</h3>
</a>
</p>
<p>
<a href="https://www.facebook.com">
<img height="200px" style="display: block; margin-left: 500px; float: left;border: 2px solid white; border-radius: 100%; margin-top: 30px;" src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-9/12512240_1005566046198664_2775546349199755757_n.jpg?oh=a37edadd99a4631e165accf6bd193a9f&oe=58C8AD58">
<h3>Test</h3>
</a>
</p>
<p>
<a href="https://www.facebook.com">
<img height="200px" style="display: block; margin-left: 500px; float: left;border: 2px solid white; border-radius: 100%; margin-top: 30px;" src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-9/12512240_1005566046198664_2775546349199755757_n.jpg?oh=a37edadd99a4631e165accf6bd193a9f&oe=58C8AD58">
<h3>Test</h3>
</a>
</p>
</div>
Personally I would do so:
.test a {
margin-left: 10px;
float: left;
text-align: center;
overflow: auto;
}
.test a img {
width: 100px;
border:2px solid white;
border-radius: 50%;
}
<div class="test">
<a href="https://www.facebook.com">
<img src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-9/12512240_1005566046198664_2775546349199755757_n.jpg?oh=a37edadd99a4631e165accf6bd193a9f&oe=58C8AD58">
<h3>Test</h3>
</a>
<a href="https://www.facebook.com">
<img src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-9/12512240_1005566046198664_2775546349199755757_n.jpg?oh=a37edadd99a4631e165accf6bd193a9f&oe=58C8AD58">
<h3>Test</h3>
</a>
<a href="https://www.facebook.com">
<img src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-9/12512240_1005566046198664_2775546349199755757_n.jpg?oh=a37edadd99a4631e165accf6bd193a9f&oe=58C8AD58">
<h3>Test</h3>
</a>
</div>
Key points:
Use HTML for markup. Use CSS for style. Separate them.
The p tag is not necessary.
To float the three block on one line you have to set 'float:left' to the <a> element not in the img.
If we use a float based layout we have to Clearing floats (because the floats' container doesn't want to stretch up to accomodate the floats). This is why I added 'overflow: auto' to the container named '.test'
Last but not least, there are tons of method for lay-out things with CSS. I recommend watching Flexbox.
First of all, close your <p> tags.
Then personally I would an inline-block to the p and remove the margin-left on the img.
.test {
text-align: center;
}
img {
display: block;
float: left;
border: 2px solid white;
border-radius: 100%;
margin-top: 30px;
}
p {
display: inline-block;
}
You needed to two things:
HTML wrapping DIVs to be able to control your blocks.
Using CSS
Please, try this fiddle which may meet your requirement:
<style>
div.test {
width:auto;
margin: auto;
}
div.block {
float: left;
}
div.block a{
display:inline-block;
margin-left: 50px;
}
div.block img {
border: 2px solid white;
border-radius: 100%;
width:150px;
}
h3 {
text-align: center;
}
</style>
<div class="test">
<div class='block'>
<a href="https://www.facebook.com">
<img src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-9/12512240_1005566046198664_2775546349199755757_n.jpg?oh=a37edadd99a4631e165accf6bd193a9f&oe=58C8AD58">
<h3>Test</h3>
</a>
</div>
<div class='block'>
<a href="https://www.facebook.com">
<img src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-9/12512240_1005566046198664_2775546349199755757_n.jpg?oh=a37edadd99a4631e165accf6bd193a9f&oe=58C8AD58">
<h3>Test</h3>
</a>
</div>
<div class='block'>
<a href="https://www.facebook.com">
<img src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-9/12512240_1005566046198664_2775546349199755757_n.jpg?oh=a37edadd99a4631e165accf6bd193a9f&oe=58C8AD58">
<h3>Test</h3>
</a>
</div>
</div>
Related
I would like to know if someone could help me with a CSS topic.
I am creating a page model through CSS, but it turns out that there is a part that does not stay the same as the rest.
It appears as follows:
enter image description here
And it should look like this, like the footer in the following image.
Do you suggest any ideas? I leave here the code that I have used for CSS.
enter image description here
I attach the HTML and CSS code used.
I tried to move the height and width but can't find the solution.
<!--Inicio de pie de página-->
<div class="clearfix"></div>
<footer id="footer">
<div class="wrap">
<div id="menu_footer">
<h5>Menú</h5>
<ul>
<li>Inicio</li>
<li>Blog Personal</li>
<li>Currículum</li>
<li>Contacto</li>
</ul>
</div>
<div id="location">
<h5>¿Dónde estamos?</h5>
<iframe
src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3037.4968410733713!2d-3.690925684351!3d40.41999606336424!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0xd42289a4a865227%3A0x98278b3a144a86f1!2sPuerta%20de%20Alcal%C3%A1!5e0!3m2!1ses!2ses!4v1599489227264!5m2!1ses!2ses"
width="600" height="450" frameborder="0" style="border:0;" allowfullscreen="" aria-hidden="false"
tabindex="0">
</iframe>
<div id="info">
<h5> Desarrollado con</h5>
<p>
<img src="img/html5-badge-h-css3-graphics-multimedia-performance-semantics.png"
alt="Creado con HTML y CSS">
</p>
<h5>Optimizado para</h5>
<p id="browsers">
<a href="#">
<img src="img/firefox-icon.png" alt="Firefox" title="Firefox">
</a>
<a href="#">
<img src="img/chrome.png" alt="chrome" title="Chrome">
</a>
<a href="#">
<img src="img/Opera_256x256.png" alt="Opera" title="Opera">
</a>
<a href="#">
<img src="img/safari.png" alt="Safari" title="Safari">
</a>
<a href="#">
<img src="img/android.png" alt="Android" title="Android">
</a>
<a href="#">
<img src="img/ios.png" alt="Apple" title="Apple">
</a>
</p>
<h5>Autor</h5>
<p>©Cristina Martínez - acmartinez96.blogspot.com</p>
</div>
</div>
</div>
</footer>
<!--Fin de pie de página-->
</body>
</html>
/FOOTER/
#footer h5
display: block;
background: url(../img/pxgray.png), white;
height: 55px;
letter-spacing: 2px;
text-align: center;
font-family: "BebasNeue";
font-size: 40px;
line-height: 55px;
color: black;
border-radius: 5px;
margin-bottom: 15px;
#footer ul
text-align: left;
margin: 20px;
font-size: 25px;
#footer ul li
margin-top: 10px;
padding: 5px;
border-bottom: 1px solid #cccccc;
#footer ul li a
display: block;
height: 40px;
#footer iframe
width: 100%;
height: 300px;
margin-top: 10px;
border-radius: 5px;
box-shadow: 0x 0px 5px grey;
border: 5px solid white;
}
#footer img
margin-bottom: 15px;
#footer #browsers img{
width: 45px;
Thanks!
Try to use flexbox it's very helpful.
the rendering you request can be done simply this way
<div class="flex">
<div class="ll">Menu</div>
<div class="ll">Map</div>
<div class="ll">Footer</div>
</div>
div.ll {
background: #fff;
margin: 20 auto;
width: 200px;
padding: 50px;
text-align: center;
}
div.flex {
display: flex;
}
You can test it by using sandbox
Instead of a footer, try creating a <div> or <section> and align that to the right.
I have a section part on the website where I want four products being displayed in the middle, right and left arrows on both sides of the screen and a title in the middle above the displayed products, I think I have all of the HTML and CSS good but the position isn't working properly, can someone have a look and help me feature it out?img of the sections I am talking about
ps: the background color doesn't feel the space that the items and buttons are in, why does it happens too?
edit: this is a pic of how i wish it would look
HTML:
<section class="one">
<div><span class="title">New products</span></div>
<br>
<button class="left">
<span class="Lmain"></span>
<span class="Lside"></span>
</button>
<div class="items">
<div class="item">
<a href="">
<img class="itemImg" src="../Images/Image1.png" alt="Picture of the product">
</a>
<div><span class="desc">Description about that specific item that is being showen to you above this text
right here</span></div>
</div>
<div class="item">
<a href="">
<img class="itemImg" src="../Images/Image2.png" alt="Picture of the product">
</a>
<div><span class="desc">Description about that specific item that is being showen to you above this text
right here</span></div>
</div>
<div class="item">
<a href="">
<img class="itemImg" src="../Images/Image3.png" alt="Picture of the product">
</a>
<div><span class="desc">Description about that specific item that is being showen to you above this text
right here</span></div>
</div>
<div class="item">
<a href="">
<img class="itemImg" src="../Images/Image4.png" alt="Picture of the product">
</a>
<div><span class="desc">Description about that specific item that is being showen to you above this text
right here</span></div>
</div>
</div>
<button class="right">
<span class="Rmain"></span>
<span class="Rside"></span>
</button>
</section>
CSS:
.title {
text-align: center;
position: absolute;
margin: auto;
border: 1px solid goldenrod;
font-size: 40px;
}
.one {
background-color: hotpink;
position: relative;
}
.two {
background-color: rgb(255, 0, 128);
}
/*items appearance*/
.items {
position: relative;
margin: auto;
}
.item {
border: 1px solid rgb(255, 170, 0);
float: left;
position: absolute;
top: 0px;
margin: 0px 8px;
left: 12%;
width: 350px;
height: auto;
}
.itemImg {
width: 100%;
height: auto;
}
/*end of item appearance*/
.right {
right: 0px;
top: 0px;
position: absolute;
}
.left {
left: 0px;
top: 0px;
position: absolute;
}
Utilize flexbox to make this layout easy:
body {
margin: 0;
background: #1a1a1a;
color: #fff;
font-family: sans-serif;
}
h1#title {
padding: 1rem;
text-align: center;
}
main {
padding: 1rem;
display: flex;
justify-content: space-between;
align-items: center;
}
#products {
display: flex;
justify-content: center;
align-items: flex-start;
margin: 0;
}
.product {
padding: 2rem 1rem;
background: #fff;
color: black;
margin: .5rem;
}
<body>
<h1 id="title">Items</h1>
<main>
<div class="arrow" id="arrow-left">←</div>
<div id="products">
<div class="product">
Product
</div>
<div class="product">
Product
</div>
<div class="product">
Product
</div>
<div class="product">
Product
</div>
</div>
<div class="arrow" id="arrow-right">→</div>
</main>
</body>
Here a list of problem I see:
the .title element is position:absolute, so it doesn't fill any space and other elements will position weirdly. Solution: remove position: absolute
the .title is a <span> element witch is an inline-element who doesn't behave like a block element (<div>, <p>, <h1>, etc.), so the text-align: center doesn't take effect. Solution: remove the span and give the .title class to the parent <div>
the left and right buttons should be wrapped in a <div> with position:relative
Here is a jsfiddle with the fixed code.
I didn't fix the image positioning because i think those will be positioned by js, anyhow it dipends by the images dimensions and is a very weak method. So I strongly suggest using flexbox that is widely supported by browsers.
You can follow the #yerme example or this guide on flexbox.
So I have multiple div tags, each one represents a inline-block. Each div has an image and headings as text. I want to be able to display them side by side, as seen from this image:
(For this image, see the "Getting Started" section, as this is what I'm referring to specifically.)
My question is how do I achieve this structure? I've tried positioning the images and text side to side, but it didn't work in the code below.
.Getting-Started {
background-color: lightBlue;
text-align: center;
padding-top: 20px;
padding-bottom: 50px;
}
.Step1,
.Step2,
.Step3 {
display: inline-block;
}
br {
margin: 0px;
padding: 0px;
line-height: 0px;
}
.Step1 {}
.Step2 {}
.Step3 {}
<div class="Getting-Started">
<h1 style="margin: 0 0 20px;">Getting Started</h1>
<div class="Step1">
<img src="#" alt="#">
<h2 style="margin: 0px;">Step 1: Select your year level above</h2>
</div>
<br>
<div class="Step2">
<img src="#" alt="#" width="">
<h2>Step 2: Choose a level of difficulty you feel cofident with</h2>
</div>
<br>
<div class="Step3">
<img src="#" alt="#">
<h2>Step 3: Select a topic and click on "Read More"</h2>
</div>
<br>
</div>
https://jsfiddle.net/ct69hkbg/
Your mistake is in your css making div elements with class "step1, step2, step3" to inline-block.
You have to make display of children of these elements to inline-block
.Getting-Started {
background-color: lightBlue;
text-align: center;
padding-top: 20px;
padding-bottom: 50px;
}
.step h2,
.step img {
display: inline-block;
vertical-align: middle;
}
.step img {
margin-right: 10px;
}
br {
margin: 0px;
padding: 0px;
line-height: 0px;
}
refactored your code a bit and replaced "step1, step2, step3" to step as you can see in the code
check this out: https://jsfiddle.net/gj02r3dn/
Remove your Step1...3 classes from your HTML and your CSS.
Remove the <br> tags.
Use div:nth-of-type(odd) img and div:nth-of-type(odd) img selectors to
float your images left/right alternatingly.
.Getting-Started {
background-color: lightBlue;
text-align: center;
padding-top: 20px;
padding-bottom: 50px;
}
br {
margin: 0px;
padding: 0px;
line-height: 0px;
}
.Getting-Started div:nth-of-type(odd) img {
float: left;
}
.Getting-Started div:nth-of-type(even) img {
float: right;
}
<div class="Getting-Started">
<h1 style="margin: 0 0 20px;">Getting Started</h1>
<div>
<img src="#" alt="#">
<h2>Step 1: Select your year level above</h2>
</div>
<div>
<img src="#" alt="#" width="">
<h2>Step 2: Choose a level of difficulty you feel confident with</h2>
</div>
<div>
<img src="#" alt="#">
<h2>Step 3: Select a topic and click on "Read More"</h2>
</div>
</div>
Here is the Simple Code
HTML
<h3>
<span class="first-label">This is the main label</span>
<span class="secondary-label">secondary label</span>
</h3>
CSS
.first-label:after {
content: '\A';
white-space: pre; }
try this code:
.Getting-Started {
background-color: lightBlue;
padding-top: 20px;
padding-bottom: 50px;
}
.Step {
display: flex;
flex-direction: row-reverse;
justify-content: space-between;
align-items: center;
border: 1px solid #000;
text-align: right;
}
.Step:nth-child(2n) {
flex-direction: row;
text-align: left;
}
.Step h2 {
flex: 0 0 60%;
}
img {
width: 150px;
height: 150px;
background-color: yellow;
border: 2px solid yellow;
}
<div class="Getting-Started">
<h1 style="margin: 0 0 20px;">Getting Started</h1>
<div class="Step">
<img src="#" alt="#">
<h2 style="margin: 0px;">Step 1: Select your year level above</h2>
</div>
<div class="Step">
<img src="#" alt="#" width="">
<h2>Step 2: Choose a level of difficulty you feel cofident with</h2>
</div>
<div class="Step">
<img src="#" alt="#">
<h2>Step 3: Select a topic and click on "Read More"</h2>
</div>
</div>
heading element <h1> through <h6>, hence can't be displayed inline or inline-block. Use inline elements instead for eg. span.
https://jsfiddle.net/snehansh/xdw9cp50/4/
.Getting-Started {
background-color: lightBlue;
text-align: center;
padding-top: 20px;
padding-bottom: 50px;
}
.Step1, .Step2, .Step3 {
display: inline-block;
}
br {
margin: 0px;
padding: 0px;
line-height: 0px;
}
.Step1 {
}
.Step2 {
}
.Step3 {
}
<div class="Getting-Started">
<h1 style="margin: 0 0 20px;">Getting Started</h1>
<div class="Step1">
<img src="#" alt="#">
<span>Step 1: Select your year level above</span>
</div>
<br>
<div class="Step2">
<img src="#" alt="#" width="">
<span>Step 2: Choose a level of difficulty you feel cofident with</span>
</div>
<br>
<div class="Step3">
<img src="#" alt="#">
<span>Step 3: Select a topic and click on "Read More"</span>
</div>
<br>
</div>
I am trying to create a setup mimicking the one in the link with an image, text and a border all horizontally and vertically centered. I've tried a number of different ideas.
The below is the closest I've gotten but even then I'm still experiencing issues with the border displaying and things not being centered the way I want them.
<div style="max-width: 800px; height border: 1px solid #c6c6c6; border-radius: 5px; padding: 35px; margin-left: 60px; float: center; height: 220px; display: inline-block;">
<img src="image.gif" />
</div>
<div style="height: 220px; display: inline-block;">
<div style="position: relative; top: 50%;">
<h4 style="text-align: center;">Text 1/h4>
<p style="text-align: center;">Text 2<br />Text 3</p>
</div>
</div>
I would try using CSS tables, put the image and the text in separate block level elements that use display: table-cell, all of which are contained in a parent container using display: table.
.wrapper {
border: 1px solid gray;
border-radius: 5px;
display: table;
height: 220px;
margin: 0 auto;
}
.wrapper .item {
display: table-cell;
vertical-align: middle;
text-align: center;
min-width: 200px;
padding: 35px;
}
.item img {
display: block;
}
<div class="wrapper">
<div class="item">
<a href="www.google.com" target="_blank">
<img src="http://placehold.it/200x150" />
</a>
</div>
<div class="item">
<h4>Text Line One</h4>
<p>Text 2
<br />Text 3</p>
</div>
</div>
you should put inline-block on image and the parent div of text panel and vertical-align:middle .. would do that
.textpane{
height: 220px;
display: inline-block;
vertical-align:middle;
}
.imagepane{
width:50px;
height:50px;
display:inline-block;
vertical-align:middle;
max-width: 800px;
border: 1px solid #c6c6c6;
border-radius: 5px;
padding: 35px;
margin-left: 60px;
height: 220px;
}
<div class='imagepane'>
<img src="image.gif" />
</div>
<div class='textpane'>
<div style="position: relative; top: 50%;">
<h4 style="text-align: center;">Text 1/h4>
<p style="text-align: center;">Text 2<br />Text 3</p>
</div>
</div>
jsfiddle
Note
there is not such thing as float:center;
I am trying to display caption on images.
This is my HTML
<div class="image-hover">
<div class="image-block">
<a href="" target="_blank" class="image-overlay">
<div class="details">
<h4>Our philosophy and Vision</h4>
</div>
<div class="image-backdrop">
<img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/omr-office.jpg"/>
</div>
</a>
</div>
<div class="image-block">
<a href="" target="_blank" class="image-overlay">
<div class="details">
<h4>Our philosophy and Vision</h4>
</div>
<div class="image-backdrop">
<img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/omr-office.jpg"/>
</div>
</a>
</div>
<div class="image-block">
<a href="" target="_blank" class="image-overlay">
<div class="details">
<h4>Our philosophy and Vision</h4>
</div>
<div class="image-backdrop">
<img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/omr-office.jpg"/>
</div>
</a>
</div>
<div class="image-block">
<a href="" target="_blank" class="image-overlay">
<div class="details">
<h4>Our philosophy and Vision</h4>
</div>
<div class="image-backdrop">
<img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/omr-office.jpg"/>
</div>
</a>
</div>
</div>
This is my CSS :
.image-hover {
overflow: hidden;
}
.image-hover .image-block {
width: 234px;
height: 100px;
display: inline-block;
border: 1px solid #666666;
}
.image-hover .image-block img {
width: 230px;
height: 100px;
border: 2px solid #fff;
}
.details, .image-backdrop {
float: left;
}
.details h4:after {
display: inline-block;
content:" ";
width: 0;
height: 0;
border-top: 6px solid transparent;
border-bottom: 6px solid transparent;
border-left: 8px solid #666666;
margin: 0 10px;
}
This is my JsFiddel
My problem is how can I get image's caption to above of image?
Any comments are greatly welcome.
Thank you.
you should use position:relative; to the container and position:absolute; to the child container whom you want to on image it is styled as you want
http://jsfiddle.net/ADMvd/2/
Add this to your CSS
.details h4 {
color: white; /* just to make it look pretty */
}
.details {
position: absolute;
}
.image-overlay {
position: relative;
}
DEMO
EDIT
Note that you are using div tag inside your a tag so don't forget to add display: block to your a.image-overlay tag because inline elements can't contain any other type of elements. It does work but will cause many weird problems.
For starters height:100% won't work for div inside a