I realize this is probably another newbie question but I have tried different things and can't make this work. I am basically building a team page where I want to have a picture on the left side and some text on the right side for each team member. Under the name of the person comes the title, and below that (between title and a paragraph) is a bunch of badge links for email, LinkedIn, and Twitter. For the purpose of having the badges align perfectly below the title, I have used a table. I want to repeat that set up for each team member and have them stack on top of each other.
What I have right now for one person (which displays correctly) in html:
<div class="left">
<img src="url"/>
</div>
<div class="right">
<H3>Name</H3>
<H4>Title</H4>
<table>
<tr>
<td><a href="mailto:email"><img src="url"/></td>
<td><img src="url"/></td>
<td><img src="url"/></td>
</tr>
</table>
<p>Experience</p>
<p>Experience</p>
<p>Experience</p>
</div>
And here is the CSS:
.left img{
position:relative;
float:left;
height:15%;
width:15%;
top:50px;
}
.right{
position: relative;
float:left;
margin-top:10px;
}
.right h3{
color:#39c388;
font-weight:bold;
font-family:Arial,sans-serif;
font-size:28px;
position:relative;
top:30px;
left:20px;
}
.right h4{
color:#818286;
font-family:Arial,sans-serif;
font-size:24px;
position:relative;
top:20px;
left:20px;
}
.right td img{
width:20px;
height:20px;
position:relative;
top:20px;
left:20px;
}
.right td{
width:30px;
}
.right p{
color:#818286;
font-family:Arial,sans-serif;
font-size:20px;
position:relative;
top:40px;
left:20px;
}
So far so good. Now, I want to replicate this code and have these section stack up on top of each other. How would you do that? I have tried having a div around this whole html code and then give that div a class, and used position, z-index, etc but without any success.
If you mean 'stack on top of each other' as in layered over each other, then you need to use:
{position: absolute; top: 0; left: 0} (having top and left position to the position you require)
on the container <div>s for each section.
However, if you mean 'stack on top of each other' as in listed down the page, then it should work with a container <div> as is. You may need to give the container <div> and the left div an {overflow: hidden} (and {height: 1%} for IE 6 - 8) to count for the floating child elements within them.
Related
In my HTML and CSS image gallery I want to have text displayed over the images. However I only manage to get the text below the images.
Here is the html code:
<div class="fleft imgdiv">
<div>Image Name</div>
<img class="galleryimg op80" src='http://qnimate.com/wp-content/uploads/2014/03/images2.jpg'>
</div>
<!-- repeats many many times -->
Here I use only very little CSS and the only thing I try to do is make the text Image Name show up over the images rather than below them.
Here is the CSS I'm using:
.fleft{
float:left;
}
.imgdiv {
width:24%;
height:150px;
position:relative;
overflow:hidden;
margin:0.5%;
}
.imgdiv .galleryimg {
min-width:100%;
min-height:100%;
height:auto;
position:relative;
top:50%;
left:50%;
transform:translateY(-50%) translateX(-50%);
}
.op80{
opacity:0.5;
}
Here is a jsFiddle for better understanding what the problem is. The op80 makes the Image slightly transparent and enables us to see the text below
JS Fiddle Example
What am I doing wrong here and how I can get the text appear in front of the images rather than below them?
Add a Z-Index property to both your image and text elements.
You need to create a class for your text div. I called this one flying-text, as an example.
.fleft{
float:left;
}
.imgdiv {
width:100%;
height:auto;
position:relative;
overflow:hidden;
margin:0.5%;
}
.imgdiv .galleryimg {
min-width:100%;
min-height:100%;
height:auto;
position:relative;
top:50%;
left:50%;
transform:translateY(-50%) translateX(-50%);
z-index:0;
}
.op80{
opacity:1;
}
.flying-text {
color: red;
z-index:1;
position: relative;
text-align: center;
font-size: 2rem;
}
<div class="fleft imgdiv"> <div class="flying-text">Sleepy Cat</div> <img class="galleryimg op80" src='https://www.humanesociety.org/sites/default/files/styles/1240x698/public/2018/06/cat-217679.jpg'></div>
Source
To get the text over the image you really just need to make the child items (img and div) have absolute positioning and then you just have to rearrange your HTML so that the text comes after the img. I see too you're trying to center the image within the div even if it's bigger - the top, left, and transform css you have will work fine for that but again the items need to have absolute positioning so I think that is your main problem.
Side note on the position CSS property - it should be that an ancestor is marked as relative and descendants items absolute, as to absultely position children, relative to the parent.
.fleft{
float:left;
}
.imgdiv {
width:24%;
height:150px;
position:relative;
overflow:hidden;
margin:0.5%;
}
.imgdiv .galleryimg {
min-width:100%;
min-height:100%;
height:auto;
top:50%;
left:50%;
transform:translateY(-50%) translateX(-50%);
opacity: .5;
}
.imgdiv .galleryimg, .imgdiv div {
position: absolute;
}
<div class="fleft imgdiv">
<img class="galleryimg op80" src='https://image.shutterstock.com/image-vector/example-signlabel-features-speech-bubble-260nw-1223219848.jpg'>
<div>Image Name</div>
</div>
<div class="fleft imgdiv">
<img class="galleryimg op80" src='https://image.shutterstock.com/image-vector/example-signlabel-features-speech-bubble-260nw-1223219848.jpg'>
<div>Image Name</div>
</div>
By in front of the images do you mean to center the text in the image? If so you could just center the div for the HTML
I have a fixed div on the left of my screen and I want to put there the categories, and near it I want to put 2 more other divs, the first one to wider that the second, and both of them to be floated left, but the problem is that the 2 divs intersect with the fixed one, and I don't want that, how can I solve this ?
I've made a fiddle here:
https://jsfiddle.net/rn11jxh2/
HTML:
<div id="meniu">
<div id="cat" >
<div class="catico">
<img src="img/Categories.png"/>
</div>
<div class="cattext">
Categories:
</div>
</div>
<ul>
<li>sdncsldncsd </li>
<li>sdncsldncsd </li><li>sdncsldncsd </li><li>sdncsldncsd </li><li>sdncsldncsd </li><li>sdncsldncsd </li><li>sdncsldncsd </li>
</ul>
</div>
<div id="invitapemail">
</div>
#invitapemail {
float:left;
position:relative;
height:200px;
width:620px;
right:30px;
background-color:white;
border:2px solid #797979;
border-radius:1em;
padding:10px;
margin-top:10px;
font-family:Verdana, Geneva, sans-serif;
font-size:1.2em;
color:#797979;
z-index:2;
}
#meniu{
position:fixed;
height:420px;
width:140px;
line-height:30px;
font-size:1.15em;
margin-left:0px;
padding-right:75px;
padding-left:30px;
text-decoration:none;}
This is expected behavior. position:fixed removes the element from the document flow. That means it will ignore other elements as if they aren't even there, this it can cause overlaps. The float:left is shifting your content over to the left as if the fixed menu isn't there.
You can set a margin-left to offset the elements by the width+padding of the menu, in this case it looks like 200px: https://jsfiddle.net/rn11jxh2/1/
You can read more about positioning and floats here: https://css-tricks.com/all-about-floats/
I am trying to position the second image inline next to the one before, the second image is smaller and i want it to sit on the same bottom line next to the larger one next to it. this will create a gap above the second image where i can put a small bit of text.
My problem is when i play around with background-size:, height: and width: to change the size of the image it just goes to the top left hand corner of its surrounding div.
I plan on having 4 more small image next to the small one so I'm asking please could anyone sort out the positioning of the divs and css so that i can easily add more next to the prior one,
Here is an image to give you an understanding of what i am trying to achieve, The red box shows where i want it to be positioned, and the other red box is where i will have the next skin.
LINK
Things i have tried:
Bottom:0
margin-top ( to push it down ) though this does not leave room for me to add text above the smaller images
padding-top:
Here is my current CSS:
#secondinner {
width:980px;
margin:0 auto;
overflow: hidden;
}
#dailyskin {
width:120px;
height:20px;
background-color:#336699;
color:white;
font-size:14px;
text-align:center;
padding-top:1px;
}
#topskin {
background-image:url(images/topskins/1f.png);
background-size:110px;
height:220px;
background-repeat:no-repeat;
width:110px;
dislpay:inline-block;
float:left;
margin-top:5px;
}
#topskin2 {
background-image:url(images/topskins/1f.png);
background-size:80px;
height:150px;
background-repeat:no-repeat;
width:80px;
dislpay:inline-block;
float:left;
margin-top:5px;
}
#downloadbutton1 {
width:100%;
}
#firstskin {
width:110px;
overflow:hidden;
float:left;
}
#secondskin {
width:100px;
overflow:hidden;
float:left;
padding-left:10px;
}
Here is the HTML:
<div id="secondinner">
<div id="dailyskin">Todays Daily Skin!</div>
<div id="firstskin">
<div id="topskin"></div>
<button id="downloadbutton1" type = "button" name = "Download"> Download </button>
</div>
<div id="secondskin">
<div id="topskin2"></div>
<button id="downloadbutton1" type = "button" name = "Download"> Download </button>
</div>
</div>
This is the third section to the index page.
</div>
Here is a JS fiddle to show you what i mean,
http://jsfiddle.net/bjbear123/qdwgpaqc/
display: table-cell; with a vertical-align: bottom could be a good solution.
Have a jsBin!
HTML
<div class="skin-wrap">
<div>
<img src="http://www.placehold.it/100X300" />
<button>Download</button>
</div>
<div>
<p>text above </p>
<img src="http://www.placehold.it/100X200" />
<button>Download</button>
</div>
</div>
This is the third section to the index page.
CSS
.skin-wrap {
display: table;
}
.skin-wrap > div {
display: table-cell;
width: 100px;
vertical-align: bottom;
padding: 10px;
}
And if you don't want / are not able to use table-cell as misterManSam answered you can use nested divs with position absolute.
.wrapper{
position: relative;
height: 200px;
width: 100px;
}
.content{
position: absolute;
bottom: 0;
}
<div class="wrapper">
<div class="content">
<img src="whatever.jpg" />
</div>
</div>
And there you have a little jsbin http://jsbin.com/jiqakefu/1/
One easy solution is to increase the top margin of topskin2.
#topskin2 {
background-image:url(images/topskins/1f.png);
background-size:80px;
height:150px;
background-repeat:no-repeat;
width:80px;
dislpay:inline-block;
float:left;
margin-top:75px;
i tried this on jsfiddle both download button were inline.
You can set margin as per your need, if you want space between both then you can use margin-left to create gap.
you were right doing it through bottom:0;
The thing you missed was to set position:absolute; and for outer div position:relative;
Here's a fiddle: http://jsfiddle.net/Nive00/qdwgpaqc/2/
I need to show one big div with 3 divs inside it. The layout has to be fluid, i.e. the height of the big div must adapt to the contents of the 3 divs inside it. Moreover, I want the 3 divs have the same height, and I managed to do that with display:table property for the container div and display:table-cell property for the 3 inner divs. Nevertheless, there is a big problem: as soon as I put a div with a margin-top: inside the first of the three divs, it shifts downwards the content of the other two divs.
I really cannot understand why, any help would be much appreciated.
Here is the html and the css code:
<div id="body">
<div id="left-box">
<div id="left-container">
LEFT LEFT LEFT LEFT LEFT LEFT
</div>
</div>
<div id="central-box">
<div id="central-container">
CENTRAL CENTRAL CENTRAL CENTRAL CENTRAL
</div>
</div>
<div id="right-box">
<div id="right-container">
RIGHT RIGHT RIGHT RIGHT RIGHT RIGHT
</div>
</div>
</div>
CSS:
#body {
width:80.9%;
margin:0 auto 0 auto;
height:auto;
/*background-color:#0F3;*/
display:table;
}
#left-box {
height:100%;
width:60%;
background-color:red;
display:table-cell;
border-right:1px solid #000;
}
#left-container {
background-color:#0CF;
width:72%;
margin-top:82px;
margin-left:2%;
}
#central-box {
background-color:#00F;
display:table-cell;
border-right:1px solid #000;
width:20%
}
#central-container {
margin-top:0px;
float:left;
background-color:#FF0;
}
#right-box {
background-color:#0C0;
display:table-cell;
border-right:1px solid #000;
width:19%;
}
#right-container {
margin-top:0px;
background-color:#FF0;
}
Try using vertical-align on the divs, for example something like this:
div {vertical-align:top;}
it is a similar phenomenon as with inline-block elements we discussed here
here I put your code + vertical-align on jsfiddle
What's the simplest way to achieve the following with HTML/CSS:
+---------+---------------------------------------------------+
| my | Home About Categories Donate |
| best +---------------------------------------------------+
| website | Search __________ |
+---------+---------------------------------------------------+
Constraints:
"my best website" is text, not an image, so cannot specify height of "masthead" in px
The height of each of the two long rectangles should take up 50% of the height of the square box
The two long rectangles should stretch "all the way" to the right
Here is my best attempt:
#masthead {
background-color:red;
}
#masthead-sitename {
font-size:3em;
float:left;
color:white;
padding:20px;
background-color:black;
width:188px;
}
#masthead-twobars {
float:left;
background-color:green;
}
#masthead-menu {
float:left;
width:100%;
font-size:x-large;
color:white;
padding:20px;
background-color:gray;
}
#masthead-search {
float:left;
width:100%;
font-size:x-large;
color:white;
padding:20px;
background-color:yellow;
}
<div id="masthead">
<div id="masthead-sitename" >
my<br/>best<br/>website
</div>
<div id="masthead-twobars" >
<div id="masthead-menu">
Home About Categories Donate
</div>
<div id="masthead-search">
Search
</div>
</div>
</div>
It fails because the two long rectangles do not stretch all the way to the right, and the heights of the two long rectangles do not add up to the height of "masthead-sitename"
Give the masthead left padding as wide as the site name, then position the sitename absolutely over the padding. Don't float the bars, don't give them width. They'll just naturally fill the container without overlapping the left padding. Set the sitename's height to 100% and make the bars tall enough to fully display the site name.
Demo: http://jsfiddle.net/d6xsQ/1/
.masthead {
padding-left: 218px;
background-color:red;
position: relative;
}
.masthead .sitename {
position:absolute;
left: 0;
top: 0;
font-size:3em;
color:white;
background-color:black;
width:218px;
height: 100%;
overflow: hidden;
}
.masthead .sitename > div {
padding:20px;
}
.masthead .bar {
font-size:x-large;
padding:40px 20px;
}
.masthead .menu {
background-color:gray;
color:white;
}
.masthead .search {
background-color:yellow;
}
<div class="masthead">
<div class="sitename" >
<div>
my<br/>best<br/>website
</div>
</div>
<div class="bar menu">
Home About Categories Donate
</div>
<div class="bar search">
Search
</div>
</div>
http://jsfiddle.net/4cn7q/3/
Basically, let the site name dictate the box height, and absolutely position the two "rows" within the wrapper.
(You can then choose to vertically center content in the rows if you like, using a variety of techniques.)
The "easiest" (although probably not the best way) is to use a table:
<table>
<tr>
<td rowspan="2">my best website</td>
<td>Home About Categories Donate</td>
</tr>
<tr>
<td>Content goes here</td>
</tr>
</table>
However I know a lot of people who would lynch me for suggesting this. Hey, I just want to not have to spend five hours getting the CSS to work, okay? :p