I'm trying to create a gallery of rounded photos (mostly landscape rectangular images). It works for the first image but I don't know how to apply it to all the images while maintaining the rounded format. Any help would be appreciated since I'm still new to this.
Here's my HTML:
<div class="photos">
<img src="url">
<img src="url">
etc.. more images
</div>
Then my CSS:
.photos {
display: inline-block;
position: relative;
width: 200px;
height: 200px;
overflow: hidden;
border-radius: 50%;
}
img {
width: auto;
height: 100%;
margin-left: -50px;
display: inline-block;
}
Add this to your css, it works for all img tag inside of Photos
.photos img{
border-radius: 50%;
}
<div class="photos"></div>
You should use .photos with one image inside it, like:
.photos {
display: inline-block;
position: relative;
width: 200px;
height: 200px;
overflow: hidden;
border-radius: 50%;
}
img {
width: auto;
height: 100%;
margin-left: -50px;
display: inline-block;
}
<div class="photos">
<img src="http://cdn1-www.dogtime.com/assets/uploads/gallery/cardigan-welsh-corgi/chasing-8_680-453.jpg">
</div>
<div class="photos">
<img src="http://cdn1-www.dogtime.com/assets/uploads/gallery/cardigan-welsh-corgi/chasing-8_680-453.jpg">
</div>
Hope this helps!
Try editing your css with this:
.photos img {
display: inline-block;
position: relative;
width: 200px;
height: 200px;
overflow: hidden;
border-radius: 50%;
}
img {
width: auto;
height: 100%;
margin-left: -50px;
display: inline-block;
}
You would simply put each image in its own <div> with a class round for instance.
.round {
display: inline-block;
position: relative;
width: 200px;
height: 200px;
overflow: hidden;
border-radius: 50%;
background-color:blue;
}
<div class='round'>
<img src='yourImage'>
</div>
<div class='round'>
<img src='yourImage'>
</div>
Related
I have a bit complicated problem,
I want IMAGE to set full size to DIV, but to be hidden to another DIV inside..
I'll give it my best to explain:
#grandParent {
width: 100%;
height: 500px;
border: 2px solid black;
position: relative;
}
#parent {
width: 50%;
height: 100%;
overflow: hidden;
border: 1px solid red;
}
#child {
width: 100%;
height: auto;
position: absolute;
}
<div id="grandParent">
<div id="parent">
<img id="child" src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/52/Liliumbulbiferumflowertop.jpg/220px-Liliumbulbiferumflowertop.jpg">
</div>
</div>
Made changes ^^
Thanks in adv :)
Something like this may work:
.grandParent {
border: 1px solid;
width: 500px;
height: 500px;
display: flex;
justify-content: center;
align-items: center;
}
img {
width: 500px;
height: 500px;
}
.parent {
width: 250px;
height: 250px;
overflow: hidden;
}
EDIT: Maybe I have a better idea.
Code Pen
Try this
#grandParent {
width: 50vw;
height: 50vw;
}
#parent {
width: 25vw;
height: 25vw;
}
#parent::after {
content: '';
display: block;
position: relative;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-color: white;
}
#child {
position: absolute;
width: 50vw;
height: 50vw;
}
<div id="grandParent">
<div id="parent">
<img id="child" src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/52/Liliumbulbiferumflowertop.jpg/220px-Liliumbulbiferumflowertop.jpg"/>
</div>
</div>
Edit
I removed the opacity: 0 on the image and put overflow: hidden on the parent element. I used the vw to get the percent of the screen. Try expanding the snippet to full screen and resizing the window.
Edit
I used a pseudo element and I think is working right now.
I have made an analogue clock like so that shares 1 parent div space with 2 other divs:
.left {
vertical-align: top;
width: 27%;
overflow: hidden;
display: inline-block;
}
#picLeft {
height: 100%;
width: 100%;
}
.container {
vertical-align: top;
position: relative;
display: inline-block;
width: 16.7%;
}
.clock {
vertical-align: top;
width: 100%;
height: 100%;
position: relative;
display: inline-block;
}
.hands {
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.hands-cl {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
vertical-align: top;
}
.right {
vertical-align: top;
width: 52.2%;
height: 100%;
overflow: hidden;
display: inline-block;
}
.picRight {
width: 100%;
height: 100%;
}
<div class="header-logo">
<div class="left">
<img id="picLeft" src="TIDleft.png">
</div>
<div class="container">
<div class="clock">
<img class="hands" src="TidClockFace.png">
<img id="hourHand" class="hands-cl" src="hourHand.png">
<img id="minuteHand" class="hands-cl" src="hourHand.png">
</div>
</div>
<div class="right">
<img class="picRight" src="TIDright.png">
</div>
</div>
This is what happens:
As You can see it looks ridiculous.
I don't know if the problem is in the rotation or the image size since the divs shrink the images to fit the part of the website.
This is the third day I have been persistently searching for the answer. No stackoverflow threads are similar, and I have run out of ideas for search terms.
I hope this question is asked properly, and enough info has been given.
If not though, don't hesitate to ask for something or correct me.
I've had a look for similar questions and tried removing the position attribute but unfortunatley that didn't work.
I have a container with 2 divs inside, and both those divs contain one image each. The images display correctly but the overall container has a height of 0px. Here is an image with the developer console open: https://gyazo.com/277d635619eb80d2d3f63a1c28c80314
This happened after trying to make the images responsive with width: 100%; and height: auto;
#landing-images {
width: 100%;
height: auto;
margin-top: 10%;
margin-bottom: 5%;
border: solid 2px black;
}
.leftLanding {
/*position: relative;*/
width: 80%;
float: left;
}
.rightLanding {
/*position: relative;*/
width: 80%;
float: right;
}
.landingImage {
width: 100%;
height: auto;
}
<div id="landing-images">
<div class="leftLanding">
<img class="landingImage" src="http://www.hlgjyl888.com/data/wallpapers/57/WDF_1035782.png">
</div>
<div class="rightLanding">
<img class="landingImage" src="http://www.hlgjyl888.com/data/wallpapers/57/WDF_1035782.png">
</div>
</div>
You just need to add.
overflow:auto; to #landing-images.
So, Your CSS will be like,
#landing-images {
width: 100%;
height: auto;
overflow:auto;
margin-top: 10%;
margin-bottom: 5%;
border: solid 2px black;
}
Because floating the child element removes it from the document flow and the parent will collapse. By adding the overflow rule, the desired behavior is restored.
The problem are the float attributes, use display: block and margin instead.
#landing-images {
width: 100%;
height: auto;
margin-top: 10%;
margin-bottom: 5%;
border: solid 2px black;
position:relative;
}
.leftLanding {
position: relative;
width: 80%;
display:block;
margin-right:auto;
}
.rightLanding {
position: relative;
width: 80%;
margin-left:auto;
}
.landingImage {
width: 100%;
height: auto;
}
<div id="landing-images">
<div class="leftLanding">
<img class="landingImage" src="http://cdn.playbuzz.com/cdn/d2b06305-f201-4127-8eb7-7410bcc0de02/2d6c2415-2b8c-430c-87a4-c516409d8488.jpg">
</div>
<div class="rightLanding">
<img class="landingImage" src="http://www.nationalgeographic.com/content/dam/animals/pictures/mammals/g/gray-wolf/gray-wolf_01.ngsversion.1484679603276.JPG">
</div>
</div>
You must clear the wrapper whenever there is a floating element inside it.
#landing-images {
width: 100%;
height: auto;
margin-top: 10%;
margin-bottom: 5%;
border: solid 2px black;
}
.leftLanding {
/*position: relative;*/
width: 80%;
float: left;
}
.rightLanding {
/*position: relative;*/
width: 80%;
float: right;
}
.landingImage {
width: 100%;
height: auto;
}
.clearfix::after {
visibility: hidden;
display: block;
content: "";
clear: both;
height: 0;
}
<div id="landing-images" class="clearfix">
<div class="leftLanding">
<img class="landingImage" src="http://www.hlgjyl888.com/data/wallpapers/57/WDF_1035782.png">
</div>
<div class="rightLanding">
<img class="landingImage" src="http://www.hlgjyl888.com/data/wallpapers/57/WDF_1035782.png">
</div>
</div>
I always use the standard clearfix class with the following style:
.clearfix::after {
visibility: hidden;
display: block;
content: "";
clear: both;
height: 0;
}
So, always have such a class on your global CSS. And add this class to all the wrappers which has floating elements inside it.
Read more about clearfix concept at:
https://css-tricks.com/snippets/css/clear-fix/
I've checked multiple threads and have tried multiple options. I've tried setting display to block, setting specific width for both image and container. Any other condition that I might be missing out on?
HTML:
<footer>
<div id="footercontent">
<div id="logobox">
<img src="images/logo.png" /> <--- THIS IS THE IMAGE IN QUESTION
</div>
<div id="social">
</div>
</div>
</footer>
CSS:
footer {
width: 100%;
height: 200px;
background-color: white;
position: relative;
margin-top: 70px;
}
#footercontent {
width: 70%;
height: 100%;
background-color: black;
margin: auto;
}
#logobox {
width: 30%;
height: 100%;
margin-right: 0;
float: left;
}
img {
height: 70%;
position: absolute;
margin: auto;
display: block;
}
#social {
width: 70%;
height: 100%;
background-color: white;
float: left;
}
Remove position: absolute and apply margin: 0 auto to img. When position: absolute is applied on some element, it is taken out from the normal flow of DOM
img {
height: 70%;
margin: 0 auto;
display: block;
}
hello I have a problem with vertical-align: middle;
.wp{
width: 100px;
height: 500px;
background-color: #000000;
}
.sub{
width: 100%;
height: 20%;
background-color: red;
vertical-align: middle;
}
<div class="wp">
<div class="sub"></div>
</div>
I want to div witch has .sub class will be vertical center of .wp div. plz help me.
Sorry for my bad english.
As an alternative, you can use transform's translateY method, like
transform: translateY(-50%);
Works here: http://jsfiddle.net/r5z8gjgu/embedded/result/
vertivcal-align works with table-cell. look how it works in jsfiddle.
this is the html and css
<div class="table">
<div class="tableRow">
<div class="wp">
<div class="sub"></div>
</div>
</div>
</div>
.table {
display: table;
width: 100px;
}
.tableRow{
display: table-row;
height: 400px;
}
.wp {
display: table-cell;
background-color: tomato;
vertical-align: middle;
}
.sub {
height: 200px;
background-color: green;
}
also you can achieve this by "relative" and "absolute" positions
.wp{
position: relative;
width: 100px;
height: 500px;
background-color: #000000;
}
.sub{
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
width: 100%;
height: 20%;
background-color: red;
vertical-align: middle;
}
After looking at your questions I was curious and a quick google search gave me the following already from stackoverflow:
Vertically Aligning Divs
http://phrogz.net/css/vertical-align/index.html
http://jsfiddle.net/ktxpP/3/
In an attempt to not just provide a link answer:
The snippet below belongs to Lalit :
You can vertically align a div in other div. For this you must define css like this example on fiddle. Just see the small demo that vertically align a innerDiv in outerDiv.
HTML
My Vertical Div CSS
.outerDiv {
display: inline-flex; <== This is responsible for vertical alignment
height: 400px;
background-color: red;
color: white; }
.innerDiv {
margin: auto 5px; <== This is responsible for vertical alignment
background-color: green; } .innerDiv class margin must be as margin: auto *px;
[* can be your desired value.]
display: inline-flex property is supported in latest(updated/current
versions) browsers with HTML5 support.
Always try to define height of vertically align div (i.e. innerDiv)
for any further compatibility issue.
.wp{
width: 100px;
height: 500px;
background-color: #000000;
display:inline-flex; <--
}
.sub{
width: 100%;
height: 20%;
background-color: red;
margin:auto; <--
}
<div class="wp">
<div class="sub"></div>
</div>
If I understand you correctly, you want something like this
.wp{
width: 100px;
height: 500px;
background-color: #000000;
}
.sub{
position:absolute;
top: 250px;
width: 100px;
height: 20%;
background-color: red;
vertical-align: middle;
}
<div class="wp">
<div class="sub"></div>
</div>
Hope that helps.
this is my solution try this
<html>
<head>
<style>
.wp{
width: 10%;
height: 10%;
float: left;
background-color: green;
border: 1px solid #00FF 00;
margin: 0.5%;
position: relative;
}
.sub
{
width: 50%;
height: 50%;
background-color: red;
position: absolute;
}
.center{
margin: 0 auto;
left: 25%;
}
.right{
left: 50%;
}
.middle {
top: 25%;
}
.bottom {
top: 50%;
}
</style>
</head>
<body>
<div class="wp">
<div class="sub center middle"></div>
</div>
</body>
</html>