I am trying to achieve the following:
The DIVS are divided in three section and once reaching a certain screen size, I want them to stack on top of another using Media Queries.
Here is the HTML (disregard inline CSS, i will be moving it to a file once I have it working):
<div class="col span_1_of_3" style="height: 150px;">
<div class="test2n" style="height: 100%;">
<div style="float: left; displat: inline-block; width: 28% padding-right: 2%; height: 100%;"><img id="NewsArticle_2790_image" class="imgArtThumb" title="The Com" alt="The Com" src="tOne.png?n=5350" /></div>
<div style="float: left; display: inline-block; width: 58%; height: 100%;">
<div style="width: 100%; height: 48%; padding-bottom: 2%; text-align: left;">How we can better develop</div>
<div style="width: 100%; height: 48%; overflow: hidden; text-overflow: ellipses; white-space: nowrap; text-align: left">TThis DIV will have a long text but anything that doesn't fit the set dimension will end with a "..."</div>
</div>
</div>
</div>
<div class="col span_1_of_3" style="height: 150px;">
<div class="test2n" style="height: 100%;">
<div style="float: left; displat: inline-block; width: 28% padding-right: 2%; height: 100%;"><img id="NewsArticle_2790_image" class="imgArtThumb" title="The Com" alt="The Com" src="tOne.png?n=5350" /></div>
<div style="float: left; display: inline-block; width: 58%; height: 100%;">
<div style="width: 100%; height: 48%; padding-bottom: 2%; text-align: left;">How we can better develop</div>
<div style="width: 100%; height: 48%; overflow: hidden; text-overflow: ellipses; white-space: nowrap; text-align: left">TThis DIV will have a long text but anything that doesn't fit the set dimension will end with a "..."</div>
</div>
</div>
</div>
<div class="col span_1_of_3" style="height: 150px;">
<div class="test2n" style="height: 100%;">
<div style="float: left; displat: inline-block; width: 28% padding-right: 2%; height: 100%;"><img id="NewsArticle_2790_image" class="imgArtThumb" title="The Com" alt="The Com" src="tOne.png?n=5350" /></div>
<div style="float: left; display: inline-block; width: 58%; height: 100%;">
<div style="width: 100%; height: 48%; padding-bottom: 2%; text-align: left;">How we can better develop</div>
<div style="width: 100%; height: 48%; overflow: hidden; text-overflow: ellipses; white-space: nowrap; text-align: left">TThis DIV will have a long text but anything that doesn't fit the set dimension will end with a "..."</div>
</div>
</div>
</div>
CSS:
.imgArtThumb
{
width: 155px;
height: 100px;
}
.test2n
{
text-align: left;
box-shadow: inset 0 -1px 1px rgba(0,0,0,0.5), inset 0 1px 1px rgba(238,146,85,1);
}
.test2 p, .test2n p
{
text-align: left;
}
/* COLUMN SETUP */
.col {
display: block;
/*float:left;*/
display: inline-block;
margin: 1% 0 1% 0;
}
.col:first-child {
margin-left: 0;
}
.span_1_of_3 {
width: 32.2%;
}
#media only screen and (max-width: 825px) {
.col {
margin: 1% 0 1% 0%;
}
}
#media only screen and (max-width: 825px) {
.span_3_of_3 {
width: 100%;
}
.span_2_of_3 {
width: 100%;
}
.span_1_of_3 {
width: 98%;
}
}
Here is the JSFiddle: http://jsfiddle.net/ofrj55j4/1/
Updated JSFiddle with max-width set to 90%: http://jsfiddle.net/ofrj55j4/6/
How to I make it so that the image is centered on the left vertically and the top right title link should take up 50% and the description on bottom right take up 50%. For the description I would like to have the ellipses if it exceeds the dimension.
UPDATE: I got everything working except the ellipses. Why doesn't fill out the entire DIV before using the ellipses? JSFiddle: http://jsfiddle.net/ofrj55j4/19/
Maybe it is just a typo you entered here on the site...your divs that contain the image are set to displat: inline-block instead of display
To get an image to stack on top of each other you have to specify it by removing the floats.
Using "clear:both;" will remove the floats will stack them, and then you can adjust the size using margins, padding, width, and height to get a perfect box.
Related
This question already has answers here:
Why is this inline-block element pushed downward?
(8 answers)
Align inline-block DIVs to top of container element
(5 answers)
Closed 2 years ago.
I have a bunch of divs that I laid out next to each other (depending upon window size there are 2-4 per "row"). Inside these divs, I added some wrappers and such, but at the center of each div there is an image that only has its width (not height) property set via CSS. The odd thing that was happening was that images with a greater width than height in the original png caused the outermost div containing it to shift down. I searched for a solution for a while and found that setting overflow: auto; in the divs with class "item-card-wrapper" (see below) somehow magically fixed the layout. I thought I understood how overflow works, but I am so confused as to how it seemed to magically fix the issue (and this isn't the only instance in which this has happened for me).
The only "correct" div here is the one that sticks out from the rest. When I added overflow: auto; it was fixed:
Here is the HTML (I clipped it early because it just starts repeating itself for each "square"):
<div id="shop">
<div id="shop-center-wrapper">
<div class="item-card-wrapper" style="width: 25%; min-width: 200px;">
<div class="item-card" style="height: 245px;">
<div class="image-wrapper">
<img class="image" src="static/products/Three Kings Glow.png">
</div>
</div>
</div>
<div class="item-card-wrapper" style="width: 25%; min-width: 200px;">
<div class="item-card" style="height: 245px;">
<div class="image-wrapper">
<img class="image" src="static/products/Amor Azul.png">
</div>
</div>
</div>
...
And here are the relevant CSS classes:
#shop {
margin-top: 40px;
margin-left: 50px;
margin-right: 50px;
overflow: auto;
}
#shop-center-wrapper {
text-align: center;
margin: 0px auto;
}
.item-card-wrapper {
margin-top: 20px;
margin-bottom: 20px;
display: inline-block;
overflow: auto;
}
.item-card {
width: 92%;
margin-left: 4%;
margin-right: 4%;;
background-color: white;
}
.image-wrapper {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.image {
width: 90%;
margin-left: 5%;
margin-right: 5%;
}
I really just want to understand how overflow: auto; was able to solve all of my problems.
The key property here should be inline-block in .item-card-wrapper. Using the inline-block display, the component will be aligned to the baseline, which same like vertical-align: baseline;.
Through my small experiment, you can see 3 images are attached on the baseline. You can remove the overflow: auto; in my snippet to create the same effect.
By adding overflow:auto, the item-card-wrapper's content should be clipped (if it is larger than its parent) to maintain the same height with the parent, therefore all item-card-wrapper component should be same height at last.
You might have question about, your picture have the same size, which shouldn't have this effect. I am guessing background-color: white; in .item-card is covered your actual picture size. Try change the color and see if my assumption is correct or not.
Ps. If you want to search for alternative from inline-block, flexbox with flex-direction might be an another good option.
#shop {
margin-top: 40px;
margin-left: 50px;
margin-right: 50px;
overflow: auto;
background: green; /* Edited */
padding: 10px; /* Edited */
}
#shop-center-wrapper {
text-align: center;
margin: 0px auto;
}
.item-card {
width: 92%;
margin-left: 4%;
margin-right: 4%;;
background-color: white;
}
.item-card-wrapper {
margin-top: 20px;
margin-bottom: 20px;
display: inline-block;
overflow: auto; /* Edited */
}
.image-wrapper {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background: yellow; /* Edited */
}
.image {
width: 90%;
margin-left: 5%;
margin-right: 5%;
}
<div id="shop">
<div id="shop-center-wrapper">
<div class="item-card-wrapper" style="width: 25%; min-width: 200px;">
<div class="item-card" style="height: 245px;">
<div class="image-wrapper">
<img class="image" src="https://www.designhill.com/design-blog/wp-content/uploads/2015/02/McDonald-Logo-1.jpg">
</div>
</div>
</div>
<div class="item-card-wrapper" style="width: 25%; min-width: 200px;">
<div class="item-card" style="height: 245px;">
<div class="image-wrapper">
<img class="image" src="https://d1.awsstatic.com/case-studies/600x400_mcdonalds_logo.58256463615a3353933179883a8c58f593a00880.png">
</div>
</div>
</div>
<div class="item-card-wrapper" style="width: 25%; min-width: 200px;">
<div class="item-card" style="height: 245px;">
<div class="image-wrapper">
<img class="image" src="https://media-exp1.licdn.com/dms/image/C4E0BAQHWxquJ9PJxvw/company-logo_200_200/0?e=2159024400&v=beta&t=95WVdd_Q6vNKUybW3mX2odTGxRJ30bwKjF9SkeSH96w">
</div>
</div>
</div>
</div>
</div>
I tried to build a website with a Special landingpage. Design specific i`d like to build it like that.
To do this I wrote the following code:
<body>
<div id="wrapper">
<div id="header_section">
</div>
<div id="main_section">
<div id="menu_section">
<div class="first_row">
<div class="row_element_4 first_element_row"></div>
<div class="row_element_4"></div>
<div class="row_element_4"></div>
<div class="row_element_4"></div>
</div>
<div class="second_row">
<div class="row_element_4 first_element_row"></div>
<div class="row_element_4"></div>
<div class="row_element_4"></div>
<div class="row_element_4"></div>
</div>
</div>
</div>
<div id="footer_section">
</div>
</div>
And CSS:
/* Main Section */
#main_section
{
background: url("../images/background/bg_person.jpg");
width: 100%;
height: 70%;
background-repeat: no-repeat;
background-size: cover;
overflow: hidden;
}
#menu_section
{
margin: 0 auto;
width: 95%;
margin-top: 1%;
height: 95%;
background: blue;
}
.first_row
{
background: red;
width: 100%;
height: 49%;
}
.second_row
{
background: orange;
width: 100%;
height: 49%;
margin-top: 1%;
}
.row_element_4
{
height: 100%;
width: 24%;
background: aqua;
float: left;
margin-left: 1%;
}
.first_element_row
{
margin-left: 0.5%;
}
My Problem is the responsive Design when I resize the window as shown in the Image below:
My row elements don't look like a square anymore.
How can I fix this Problem with my design staying responsive?
Use position: relative;
Check it here http://www.w3schools.com/cssref/pr_class_position.asp
I think you'll find useful vw and vh units. Define width and height are equal 95vw and you'll get ideal square
#menu_section
{
margin: 0 auto;
width: 95vw;
margin-top: 1%;
height: 95vw;
background: blue;
}
BTW, here's a doubled margin-top definition
I have an Img inside a Div on my webpage, the image appears inside the div, but the alignment is off depending on the browser width.
this is my code:
<div class="w3-row" style="100%; background-color: #fff; margin-top: 5px; height: 100px; padding: 5px;">
<div class="w3-col w3-container w3-green" style="width: 15%; height: 100%;">
<div>
<img class="" src="../images/Joanne.jpg" alt="Chania" style="height: 80px; display: block; margin-left: auto; margin-right: auto;">
</div>
</div>
<div class="w3-col w3-container w3-red" style="width: 85%; height: 100%;">
</div>
</div>
I was wondering if there was a way I could vertically and horizontally align the Image inside that Div, and maybe also have the image with rounded corners.
I have searched around but nothing I try works, I thought by setting the margin left and right to 'auto' would solve my problem, but the image is still off when I resize the browser.
Any help or advice is appreciated.
Demo:https://jsfiddle.net/jjxbm7j7/
For a rounded image - use the border-radius property
For a vertically centered image - Use display:flex and align-items:center on the parent element of the image that has a specified height.
For a horizontally centered image - display:flex and justify-content:center on the parent element of the image that has a specified width.
However, for your example, I used margin:auto, because it is actually simpler.
For more information for flex stuff, click here: http://www.w3schools.com/css/css3_flexbox.asp
It should look like this:
.image {
border-radius: 50px;
}
.w3-col.w3-container.w3-green {
display: flex;
align-items: center;
margin: auto;
}
.w3-row {
border: 1px solid #aaa;
}
<div class="w3-row" style="100%; background-color: #fff; margin-top: 5px; height: 100px; padding: 5px;">
<div class="w3-col w3-container w3-green" style="width: 15%; height: 100%;">
<div>
<img class="image" src="http://s33.postimg.org/vnc0xbztb/Joanne.jpg
" alt="Chania" style="height: 80px; display: block; margin-left: auto; margin-right: auto;">
</div>
</div>
<!--<div class="w3-col w3-container w3-red" style="width: 85%; height: 100%;">
</div>-->
</div>
I added the 1px border property for clarity.
Perfectly Center your Image inside a DIV using transform: scale()
I have created a box inside that i have placed your image to show how to center the image inside the div(class="box") .
body{
width: 100%;
height: 100vh;
margin: 0;
}
.w3-row {
display: flex; //flexBox
align-items: center;
justify-content: center;
flex-direction: column; //Works as a Stack i.e Image at the Top and Description at the bottom
}
For Scaling Image using CSS Transformations
.image{
width: 100%;
height: auto;
transform: scale(.5); //change the scale value to change size of the Image 0<scale<1
}
For Rounded Image
.img-rounded{
border-radius: 50%
}
Working Fiddle: https://jsfiddle.net/rittamdebnath/jjxbm7j7/3/
before anything it's not good approach to write inline CSS but anyway you can use vertical align way on an sudo element (after) like so
.image {
border-radius: 50px; //adjust yourself
display: inline-block;
vertical-align: middle;
}
.w3-col.w3-container.w3-green{
text-align:center;
height:100px;
border:1px solid;
width:100%;
}
.w3-col.w3-container.w3-green:after {
content: "";
display: inline-block;
vertical-align: middle;
height: 100%;
}
<div class="w3-row" style="100%; background-color: #fff; margin-top: 5px; height: 100px; padding: 5px;">
<div class="w3-col w3-container w3-green" style="width: 15%; margin:auto;">
<img class="image" src=" http://s33.postimg.org/vnc0xbztb/Joanne.jpg" alt="Chania" style="height: 80px; ">
</div>
<div class="w3-col w3-container w3-red" style="width: 85%; height: 100%;">
</div>
</div>
I use inside of div tag, 4 div tags to divide to 4 equal areas using following tag.
Is there any other way to divide or improve this division
<div style="width: 689px; margin-left: 215px; margin-top: 0px; float: none; height: 502px;">
<div style="width: 336px; height: 251px; display: inline-block; float: left;">
</div>
<div style="width: 336px; height: 251px">
</div>
<div style="width: 336px; height: 251px; display: inline-block; float: left;">
</div>
<div style="width: 336px; height: 251px">
</div>
</div>
Use <div style="width: 50%; height: 50%"> for inner divs.
There are no other improvements i can suggest you about styles.
In the other hand, if you want to see divs while designing, i can suggest you to assign them temporary background colors like:
<div style="width: 689px; margin-left: 215px; margin-top: 0px; float: none; height: 502px;background-color:gray">
<div style="width: 50%; height: 50%; display: inline-block; float: left;background-color:yellow">
</div>
<div style="width: 50%; height: 50%;background-color:red;float: left">
</div>
<div style="width: 50%; height: 50%; display: inline-block; float: left;background-color:green">
</div>
<div style="width: 50%; height: 50%;background-color:blue;float:left">
</div>
</div>
EDIT: Thanks to background colors, i realised that your floating divs hide other ones. You should add float:left for all inner divs.
Is this your desired effect?
.container {
display: flex;
height: 300px;
}
.container div {
flex: 1;
}
<div class="container">
<div style="background:red">A</div>
<div style="background:blue">B</div>
<div style="background:lime">C</div>
<div style="background:cyan">D</div>
</div>
Or is this?
.container {
height: 300px;
width: 300px;
}
.container div {
width: 50%;
height: 50%;
float: left;
}
<div class="container">
<div style="background:red">A</div>
<div style="background:blue">B</div>
<div style="background:lime">C</div>
<div style="background:cyan">D</div>
</div>
I have this simple website
<div style=" position: relative; margin-right: 40px;">
<div style="float: left; width: 100px; position: relative;">Middle Stuff</div>
<div style="float: right; width: 200px; position: relative; margin-right: 40px;">Right Stuff</div>
<br style="clear: left;" />
</div>
and I want that the middle stuff-box-width grow up when I resize the window so that between the middle stuff-box and the right stuff-box is no empty content.
How can I get this "effect"?
As mentioned in the comments, you can achieve this with percentage widths. Be carful though, if you leave your margins at fixed widths then the layout can break.
<div style=" position: relative; margin-right: 40px;">
<div style="float: left; width: 58%; position: relative; margin-right:2%;" class="middle-div">Middle Stuff</div>
<div style="float: right; width: 38%; position: relative; margin-right: 2%;" class="right-div">Right Stuff</div>
<br style="clear: left;" />
</div>
Here's a Fiddle
Also, you should really try to avoid using inline styles like this. Instead, I'd recommend something along the lines of:
/* CSS in style.css */
.parent-div {
position: relative;
margin-right: 40%;
}
.middle-div, .right-div {
position: relative;
float: left;
}
.middle-div {
width: 58%;
margin-right: 2%;
}
.right-div {
width: 38%;
margin-right: 2%;
}
Then your markup can be reduced to:
<div class="parent-div">
<div class="middle-div">Middle DIV</div>
<div class="right-div">Right DIV</div>
<br style="clear: left;" />
</div>
<div style="position: relative; margin-right: 40px; width: 100%;">
<div style="float: left; width: 60%; position: relative; border: 1px solid #000;">Middle Stuff</div>
<div style="float: left; width: 200px; position: relative; margin-right: 40px;margin-left: 10px; border: 1px solid #000;">Right Stuff</div>
<br style="clear: left;" />
</div>
Try this you will get a fix size for second box as 200px while 60% for first box.
As per your image you need left column fluid and right one fixed: Demo
<div id="outerdiv">
<div id="right">Right Stuff</div>
<div id="left">Middle Stuff</div>
</div>
#outerdiv {
position: relative;
margin-right: 40px;
width: 100%;
}
#left {
float: left;
width: 55%;
position: relative;
border: 1px solid #000;
}
#right {
float: right;
width: 30%;
position: relative;
margin-right: 40px;
border: 1px solid #000;
}
Or you can use responsive grid system like this
demo