How to change my css to achieve the desired layout ? - html

Hi I am designing a blog site using pure html and css and I have some design in mind. Currently it looks like before graph and I would like to achieve after graph. Right now all these classes are in inline-block and I do not want to change the dom structure. Please refer to this code snippet for implementation:
https://jsfiddle.net/yueeee/vb1we2tk/4/
.container {
padding: 10px 40px;
padding-left: 0px;
width: 100%;
height: 100%;
}
.meta {
position: relative;
display:inline-block;
height: 100%;
width: 10%;
max-width: 200px; /*in large resolution dont always want width to be 12%*/
margin-right: 40px;
/* background-color: transparent; */
padding: 0px 10px;
text-align: right;
vertical-align:top; /*always align to the top of container*/
}
.content {
width: 30%;
display:inline-block;
padding: 20px 30px;
background-color: white;
position: relative;
border-radius: 10px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
vertical-align:top; /*always align to the top of container*/
}
<div class="container">
<div class="meta">
<div class="time">
<p>2020/12/09<br>22:18:35</p>
</div>
<div class="tag">
<p>tag1</p>
<p>tag2</p>
</div>
</div>
<div class="content post">
<div class="text">
<h2> title </h2>
<p>content<br>content<br>content<br>content<br>content<br>
</p>
</div>
</div>
</div>
The difficulty I met is how do I set metadata's height equals to content. I checked solution on setting container as table and metadata/ content as table-cell. However, it would cause some other styling issue so I still want to keep everything as inline-block. The other way I am thinking is to set the height of metadata equal to container. It failed because container does not height attribute. I tried something like setting height = 100% cause I do not want a stable height but also did not work.
Need your advice.
Before:
After:

The best choice in these cases is to use the flex property. I added some Properties to both the .container and .meta selectors and deleted some, act like code to get the desired result.
.container {
display: flex;
padding: 10px 40px;
padding-left: 0px;
width: 100%;
height: 100%;
}
.meta {
display: flex;
flex-direction: column;
justify-content: space-between;
width: 10%;
margin-right: 40px;
padding: 0px 10px;
text-align: right;
}
.content {
width: 30%;
display:inline-block;
padding: 20px 30px;
background-color: white;
position: relative;
border-radius: 10px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
<div class="container">
<div class="meta">
<div class="time">
<p>2020/12/09<br>22:18:35</p>
</div>
<div class="tag">
<p>tag1</p>
<p>tag2</p>
</div>
</div>
<div class="content post">
<div class="text">
<h2> title </h2>
<p>content<br>content<br>content<br>content<br>content<br>
</p>
</div>
</div>
</div>

Related

CSS position relative div not responsive

Hello i have a background which i want to add div over it like this picture
im using bulma css framework
i was able to achive this look by writing this code
index.html
<div class="section newsletter">
<figure class="image">
<img src="src/img/newsletter.png">
</figure>
<div class="form">
<h5>Keep updated with out latest news.<br>Subscribe to our newsletter</h5>
<div class="field has-addons">
<div class="control">
<input class="input" type="text" placeholder="Enter Your Email">
</div>
<div class="control">
<a type="button" class="button btn-grad is-dark">
Subscribe
</a>
</div>
</div>
</div>
</div>
css
.newsletter{
padding:0px;
.form{
display: flex;
flex-direction: column;
width:588px;
height:297px;
background: $bg-transperant;
box-shadow: 0px 5px 14px rgba(0, 0, 0, 0.15);
border-radius: 16px;
// Layout
position: relative;
left: 140px;
top: -386px;
h5{
padding: 50px 60px 40px 60px;
font-weight: 600;
font-size: 25px;
line-height: 46px;
color: #2F4B6E;
}
div{
justify-content: center;
}
.input{
height: 50px;
width: 352px;
box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.15);
border-bottom-left-radius: 100px;
border-top-left-radius: 100px;
}
}
}
the problem is that itsn't responsive in mobile or tablet
it looks like this
im using position relative to able to put the div on the top of the image
how can i do it better for example to make it responsive ?
also there is a large white space below the picture i don't know why
Live Project Repo https://github.com/Ov3rControl/ReachGate
Live Overview: https://ov3rcontrol.github.io/ReachGate/
This may be 3 problems combined.
1) Ensure that you have your viewport set to responsive in the head
2) Don't use hard-coded dimensions for containers that expand beyond the smallest possible viewport. Notice your form is set to a 588px width. Try doing width: auto; and then max-width: 588px; instead.
3) Consider not hard-coding your positioning. Try something like this instead to center relatively positioned containers.
Looking really pretty though, good job! One aside: It's considered good practice to always tie a label to an input for accessibility purposes. If you don't want it visible that's fine! See this
I did the following to responsively center the form:
<!------------------------------------[NewsLetter Section - START]------------------------------------------->
<div class="section newsletter">
<div class="form">
<h5>Keep updated with our latest news.<br>Subscribe to our newsletter</h5>
<div class="field has-addons">
<div class="control">
<input class="input" type="text" placeholder="Enter Your Email">
</div>
<div class="control">
<a type="button" class="button btn-grad is-dark">
Subscribe
</a>
</div>
</div>
</div>
</div>
<!------------------------------------[NewsLetter Section - END]------------------------------------------->
.newsletter {
padding: 0px;
background-image: url('src/img/newsletter.png');
height: 400px;
display: flex;
align-items: center;
justify-content: center;
.form {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
max-height: 270px;
max-width: 320px;
background: $bg-transperant;
box-shadow: 0px 5px 14px rgba(0, 0, 0, 0.15);
border-radius: 16px;
// Layout
h5 {
padding: 50px 60px 40px 60px;
font-weight: 600;
font-size: 25px;
line-height: 46px;
color: #2f4b6e;
}
div {
justify-content: center;
}
.input {
height: auto;
height: 50px;
width: 352px;
box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.15);
border-bottom-left-radius: 100px;
border-top-left-radius: 100px;
}
}
}

How to make a div stay UNDER the bottom of the page, so visitor can't scroll to it?

I'm trying to create a div that stays under the bottom of the page and is invisible there. I mean, you can't scroll to it. I tried to google it, but I just can't make it, neither negative bottom-margin, nor negative bottom, nor relative/absolute positioning couldn't make it...
Could anyone of you help me, please?
Here's a snippet of my site - I wanna "Menu" image to be invisible on the bottom (outside the display area), so it can then slide up when needed.
body {
overflow-x: hidden;
margin: 0;
padding: 0;
}
.main-container {
width: 100vw;
height: 100vh;
background-color: #780d0d;
position: absolute;
}
.mainmenu {
width: 70vw;
height: 82vh;
position: relative;
top: 8vh;
left: 15vw;
-webkit-box-shadow: 0px 0px 66px 10px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 0px 0px 66px 10px rgba(0, 0, 0, 0.75);
box-shadow: 0px 0px 66px 10px rgba(0, 0, 0, 0.75);
}
.menu-bottom {
height: 20%;
width: 33.2%;
background-color: red;
border: 1px solid;
display: inline-block;
margin: 0 -5px 0 0;
}
.menu-side-holder {
height: 80%;
width: 30%;
display: inline-block;
}
.menu-side {
height: 50%;
background-color: red;
border: 1px solid;
display: block;
margin: 0;
vertical-align: top;
}
#menu-img {
height: 80%;
width: 40%;
display: inline-block;
margin: 0 -4px;
vertical-align: top;
clear: none;
}
.menu-bottom-slider {
display: inline-block;
width: 100%;
background-color: green;
}
#slider {
position: absolute;
padding-left: 43.5%;
bottom: 0;
margin-bottom: -30vh;
}
<div class="main-container">
<div class="mainmenu">
<div class="menu-side-holder">
<div class="menu-side" id="ogloszenia">
1
</div>
<div class="menu-side">
3
</div>
</div>
<img id="menu-img" src="img/main4.jpg">
<div class="menu-side-holder">
<div class="menu-side">
3
</div>
<div class="menu-side">
4
</div>
</div>
<div class="menu-bottom">
5
</div>
<div class="menu-bottom">
6
</div>
<div class="menu-bottom">
7
</div>
<div class="menu-bottom-slider">
<img id="slider" src="http://s32.postimg.org/xrrmzmohx/slider.png">
</div>
</div>
</div>
place your target div as direct child of body (not nested inside other divs) and use this style:
position:absolute;
bottom:-100% // or fixed size if height is known
One way you might be able to do this is by making it absolute and give it a negative bottom equal to the height of the element like so
.menu-bottom-slider{
position: absolute;
bottom: -(height of element goes here)px
}
Why don't you put
opacity: 0
on the element and position it where you need it ON the page. Then when you want to use it, use jQuery to change the opacity and animate it.
This would be the css of your div section.
#divname {
position:fixed;
height:50px;
background-color:red;
bottom:0px;
left:0px;
right:0px;
margin-bottom:0px;
}
Your body would look like this.
**body{
margin-bottom:50px;
}**
Your code is nearly working, but you are using overflow-x, and you need overflow-y.
EDIT:
Another way is to set the position of the slider to fixed. This means that the position does not depend on the scroll position, so you can't scroll to it:
body {
overflow-x: hidden; /* you could also change this to overflow-y */
margin: 0;
padding: 0;
}
.main-container {
width: 100vw;
height: 100vh;
background-color: #780d0d;
position: absolute;
}
.mainmenu {
width: 70vw;
height: 82vh;
position: relative;
top: 8vh;
left: 15vw;
-webkit-box-shadow: 0px 0px 66px 10px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 0px 0px 66px 10px rgba(0, 0, 0, 0.75);
box-shadow: 0px 0px 66px 10px rgba(0, 0, 0, 0.75);
}
.menu-bottom {
height: 20%;
width: 33.2%;
background-color: red;
border: 1px solid;
display: inline-block;
margin: 0 -5px 0 0;
}
.menu-side-holder {
height: 80%;
width: 30%;
display: inline-block;
}
.menu-side {
height: 50%;
background-color: red;
border: 1px solid;
display: block;
margin: 0;
vertical-align: top;
}
#menu-img {
height: 80%;
width: 40%;
display: inline-block;
margin: 0 -4px;
vertical-align: top;
clear: none;
}
.menu-bottom-slider {
display: inline-block;
width: 100%;
background-color: green;
}
#slider {
position: fixed; /* This fixes the slider, you can't scroll to it! */
padding-left: 43.5%;
bottom: 0;
margin-bottom: -30vh;
}
<div class="main-container">
<div class="mainmenu">
<div class="menu-side-holder">
<div class="menu-side" id="ogloszenia">
1
</div>
<div class="menu-side">
3
</div>
</div>
<img id="menu-img" src="img/main4.jpg">
<div class="menu-side-holder">
<div class="menu-side">
3
</div>
<div class="menu-side">
4
</div>
</div>
<div class="menu-bottom">
5
</div>
<div class="menu-bottom">
6
</div>
<div class="menu-bottom">
7
</div>
<div class="menu-bottom-slider">
<img id="slider" src="http://s32.postimg.org/xrrmzmohx/slider.png">
</div>
</div>
</div>

Align divs on top while they're aligned also on left

1)
I've got 2 divs, placed in 1 big div (container for them). They're supposed to be like small cards with informations. Here, I have a problem. When I have 2 cards next to each other and one card is simply higher, second one moves like it's aligned to bottom of 1st card, but I want to have it aligned allways on top (here is a code and fiddle).
<div class="main-cards">
<div class="card" style="width: 65%;">
<h1>CARD 1</h1>
<p>small</p>
<p>small</p>
<p>small</p>
</div>
<div class="card" style="width: 25%;">
<h1>CARD 2</h1>
<p>small</p>
</div>
</div>
.main-cards{
position: relative;
height: auto;
width: 80%;
margin-left: auto;
margin-right: auto;
top: 150px;
text-align:center;
background-color: #6ab5dd;
}
.card{
display: inline-block;
background-color: white;
height: auto;
margin: 10px;
margin-top: 40px;
padding: 8px;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
}
FIDDLE: https://jsfiddle.net/4px7kc4v/2/
How I want it:
2)
How could I do 3 cards vertically centered in one big container to center, but in this layout? (look at img)
Because I have this problem: https://jsfiddle.net/sx7ryv70/
Thanks for everyone's time! Have a nice day!
1)
Add this to the css of the cards:
vertical-align: top;
2) Having div's as inline-blocks force them to be on the same 'row' as if they are huge text characters. Try fitting the smaller cards together in their own container.
Add vertical-align: top; to .card
Your solutions:
[link](https://jsfiddle.net/Atula/4px7kc4v/3/)
[link](https://jsfiddle.net/Atula/sx7ryv70/1/)
Here look at this JSfiddle
HTML
<div class="main-cards">
<div class="card" style="width: 55%; height: 300px; float:left;"></div>
<div class="card" style="width: 55%; height: 300px; margin-top: 50px; float: left;"></div>
<div class="card" style="width: 25%; height: 650px;"></div>
CSS
.main-cards {
position: relative;
height: auto;
width: 80%;
margin-left: auto;
margin-right: auto;
top: 50px;
text-align: center;
background-color: #6ab5dd;
padding: 30px;
}
.card {
display: inline-block;
background-color: white;
height: auto;
margin: 10px;
margin-top: 40px;
padding: 8px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
All you need to remember is the floating principle.

Is it possible to render (inline) children of a div Right-To-Left instead of the default Left-To-Right?

Normally the elements of an HTML markup appear in the order they are written in the markup file, and the inline elements appear from left to right.
But I want the children of a certain div (only, NOT all the elements of the entire page) to appear from right to left.
In case you wonder why it is needed, I want to do this to solve the following problem:
PROBLEM:
JSFiddle here.
.wrapper {
height: 100%;
width: 826px;
margin: 50px auto;
display: table;
background-color: #003b80;
}
.cell {
display: table-cell;
vertical-align: top;
}
.left-cell {
width: 50%;
background-color: chocolate;
}
.right-cell {
background-color: darkslategrey
}
.step-container {
max-height: 200px;
font-size: 0;
}
.right-cell .step-container {
margin-top: 125px;
}
.content-box {
display: inline-block;
width: 350px;
height: 200px;
/*border: 5px solid blue;*/
font-size: 0;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.69);
-moz-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.69);
-webkit-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.69);
background-color: dodgerblue
}
.right-cell .content-box {
background-color: darkturquoise
}
.middle-cell {
height: 100%;
background-color: white;
width: 1.5px;
font-size: 0;
box-shadow: 0px 0px 10px black;
-moz-box-shadow: 0px 0px 10px black;
-webkit-box-shadow: 0px 0px 10px black;
}
.number-outer-container {
display: inline-block;
position: absolute;
}
.left-cell .number-outer-container {
/*margin-left:39px;*/
}
.number-inner-container {
height: 200px;
display: flex;
flex-direction: column;
justify-content: center;
}
.number-banner {
width: 50px;
height: 50px;
background-color: crimson;
-moz-border-radius: 25px;
-webkit-border-radius: 25px;
border-radius: 25px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
-moz-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
-webkit-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
}
.notch-outer-container {
display: inline-block;
}
.left-cell .notch-outer-container {
margin-right: 24px;
}
.right-cell .notch-outer-container {
margin-left: 10px;
}
.notch-inner-container {
height: 200px;
display: flex;
flex-direction: column;
justify-content: center;
}
.notch {
width: 0;
height: 0;
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
}
.left-face-notch {
border-right: 15px solid #520f23;
}
.right-face-notch {
border-left: 15px solid #571780;
}
<div class="wrapper">
<div class="cell left-cell" align="left">
<div class="step-container">
<div class="content-box"></div>
<div class="notch-outer-container">
<div class="notch-inner-container">
<div class="right-face-notch notch"></div>
</div>
</div>
<div class="number-outer-container">
<div class="number-inner-container">
<div class="number-banner"></div>
</div>
</div>
</div>
</div>
<div class="cell middle-cell"></div>
<div class="cell right-cell" align="right">
<div class="step-container">
<div class="number-outer-container">
<div class="number-inner-container">
<div class="number-banner"></div>
</div>
</div>
<div class="notch-outer-container">
<div class="notch-inner-container">
<div class="left-face-notch notch"></div>
</div>
</div>
<div class="content-box"></div>
</div>
</div>
</div>
In this SSCCE, inside .left-cell .step-container, I have three elements appearing on the same line: .content-box, .notch-outer-container, and .number-outer-container; and to make the .notch appear to be overlapping the right-cell by 50% of its width, I gave .number-outer-container a position:absolute; and .notch-outer-container a margin-right which pushes the number-outer-container to right side to an extent that it appears to be overlapping the (.middle-cell and) right-cell by 50% of it's width.
The problem is that in the .right-cell, this strategy is NOT working. First the .number-right-container appears and still it is absolute, I can not give it a left property with value relative to its parent (otherwise I would try a left:-25px to make it appear 25px behind the left edge of its parent, because it has width:50px;). Then the .notch is hidden below it...
So I am thinking about finding a way through which I can get the elements render from RTL (Right To Left) rather than LTR only inside .right-cell on the page. So that I can follow the same strategy I have used for the .left-cell, in the .right-cell.
There's numerous ways to achieve what you want using either flexing, floats or other options, but I'd say one of the easiest ways, if the rest of the layout works as you want it to, is to use the direction attribute.
div {
direction: rtl;
}
div div {
display: inline-block;
direction: ltr;
}
<div>
<div>first</div>
<div>second</div>
<div>last</div>
</div>

How can I get my image to float to the right of my div?

I am trying to get an image to float to the right of my div with a little space around the edges. I want the image to fill the majority of the div but with space for the link 'view project' beneath it. I've tried different floats, widths and even adjusted padding but still cannot get it to work. Can anyone tell me how to rectify this? Many thanks in advance. This is the page link if needed: http://me14ch.leedsnewmedia.net/portfolio/design.html
HTML:
<div id="middle">
<div class="section group">
<div class="block-1">
<h2>Logo Redesign & Style Guide</h2>
<p><h3>This brief involved...</h3></p>
<div class="snapshot">
<img src="portfolioresources/scenelogo.png">
View Project
</div></div>
<div class="block-2">
<h2>TV Idents</h2>
<p>This brief involved...</p>
View Project
</div>
</div>
<div class="section group">
<div class="block-3">
<h2>Web Banners</h2>
<p>This brief involved...</p>
View Project
</div>
<div class="block-4">
<h2>Multiformat Campaign</h2>
<p>This brief involved...</p>
View TV Idents
</div>
</div>
</div>
And the CSS for this particular bit (although inspect element might show other things that are affecting my divs):
/* design page grids */
.section {
clear: both;
padding: 0px;
margin: 0px;
}
/* COLUMN SETUP */
.colu {
display: block;
float:left;
margin: 1% 0 1% 1.6%;
}
.colu:first-child { margin-left: 0; }
/* GROUPING */
.group:before,
.group:after { content:""; display:table; }
.group:after { clear:both;}
.group { zoom:1; /* For IE 6/7 */ }
/* GRID OF TWO */
.span_2_of_2 {
width: 100%;
}
.span_1_of_2 {
width: 49.2%;
}
/* GO FULL WIDTH AT LESS THAN 480 PIXELS */
#media only screen and (max-width: 480px) {
.colu {
margin: 1% 0 1% 0%;
}
}
#media only screen and (max-width: 480px) {
.span_2_of_2, .span_1_of_2 { width: 100%; }
}
/* style grids */
#middle {
width: 90%;
margin: 0px auto;
padding: 10px;
}
.block-1 {
background-color:#ECECEC;
width: 80%;
margin: 0px auto;
-webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
height: 200px;
padding: 10px;
}
.block-2 {
background-color: white;
width: 80%;
margin: 0px auto;
margin-top: 20px;
-webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
border-top: 2px solid #FADBC8;
border-bottom: 2px solid #FADBC8;
height: 200px;
padding: 10px;
}
.block-3 {
background-color:#ECECEC;
width: 80%;
margin: 0px auto;
margin-top: 20px;
-webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
height: 200px;
padding: 10px
}
.block-4 {
background-color: white;
width: 80%;
margin: 0px auto;
margin-top: 20px;
-webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
border-top: 2px solid #FADBC8;
border-bottom: 2px solid #FADBC8;
height: 200px;
padding: 10px;
}
.block-1 img {
height: 140px;
float: right;
clear: both;
-webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.15);
}
.snapshot a {
float: right;
text-decoration:underline;
font-family: "Raleway";
}
DO this in snapshot class
<div class="snapshot">
<div class="wrap" ><img src="portfolioresources/scenelogo.png"></div>
View Project
</div></div>
and add this to ur css file to sortify your error
.wrap{
padding:2px;
}
While doing these kinda things on your own is definitely useful, so you can learn the ropes and inner workings first, be sure to use a css framework in the future (like bootstrap) so you can knock these out quickly.
<div class="view-project">
<img ... />
<span>View Project</span>
</div>
In your css:
.view-project{ float: right; width:300px; padding:40px; }
.view-project img,.view-project span{ display:block; }
A suggestion: if you want your image at the right of the div with view project beneath, I think you should contain them in another div. Like this:
<div class="snapshot">
<div>
<img src="portfolioresources/scenelogo.png">
View Project
</div>
</div>
Then float that div right and remove all other floats.
If you want the image on top of view project, set display: block; to your 'a' elements.
You need to at least define a width for snapshot. by making the width of snapshot equal the width of the image, this will leave no room for the link and will force it to drop below the image. Remove any floating on the image and link, and rather float snapshot to the right