I have these three sections that have three sections underneath them and I would like for the ones below to follow the ones directly above them. For example in this codepen the second section below does not go directly underneath the second section above, because the first section above is a little longer.
codepen.io/anon/pen/apEQRE
Is there a way to fix that?
Not easily without changing your HTML structure. You could float the elements to the left rather than displaying them as inline-block, however, the element on the bottom left would have the same problem. You could display them as flex, but that would cause problems with the way the text is formatted.
What I would recommend is diving the sections into three defined columns:
<div class="column">
<section>
<h2>Title</h2>
<p>Text</p>
<p>Text</p>
</section>
<section>
<h2>Title</h2>
<p>Text</p>
</section>
</div>
Then you would need to slightly change your CSS to cover this:
.column {
float: left;
width: 33.33%;
}
section {
text-align: center;
background-color: white;
width: 90%;
padding: 15px;
border: 1px solid #007d87;
margin-bottom: 5px;
opacity: 0.8;
display: inline-block;
text-align: left;
vertical-align: top;
}
I've created a new pen showcasing this.
Note that your example has identical sections, but in practical application, you'll need to re-order the sections so that they read left to right, rather than top to bottom.
Hope this helps!
Related
I am trying to create a horizontal line inserted between the image and text using html and css.
The image is on the very left side of the screen, and the text is on the very right side of the screen. Then the horizontal line inserted "IN THE MIDDDLE" and "VERTICALLY ALIGN CENTER"
I am now facing a very strange problem.
1. If i increase the width of hr over than 80% the text next to it will be break to new line
If I scale down the screen the text next to it will also break into a new line, how can I make it responsive without breaking into a new line.
I am very new to html and css please kinldy suggest, I have tried reading and finding solution in the forum it seems very difficult to understand and difficult to be applied
I am very new to html and css please kinldy suggest, I have tried reading and finding solution in the forum it seems very difficult to understand and difficult to be applied
hr{
display: inline-block;
margin:auto;
width:80%;
}
img {
vertical-align: middle;
display: inline-block;
height: 70px;
width: 70px;
border: 1px solid red;
}
p {
display: inline-block;
vertical-align: middle;
}
<img src ="example" alt="Product Image"><p>Healthy Cake</p><hr><p style="padding: 10px; background-color: green;">Promotional Price</p>
</html>
hr should be used to divide elements vertically not horizontally but you can manage this using flexbox on a wrapper
.wrap {
display: flex;
align-items: center ;
}
hr {
flex:1
}
<div class="wrap">
<img src="http://www.fillmurray.com/g/140/100" alt="">
<hr>
<p>Product Description</p>
</div>
Try this and it may be solve your problem,
Add margin-top: 25px; to your <hr> style and add margin-top: 0px; to your <h2> style
I have tried the above mentioned styles and i got like the below screenshot.
h1, p {
font-family: futura; sans-serif;
margin: 20px 20px 0px 20px;
}
.section {
background-color: tomato;
padding: 50px;
margin: 0 auto;
}
.container {
background-color: white;
padding: 5px;
margin: 10px 20px;
text-align: center;
display: inline-block;
height: 250px;
}
<div class="section">
<div class="container">
<h1>This is a title</h1>
<p>This is the body copy for the section in which we read more about the aforementioned subject matter within the title.</p>
</div>
<div class="container">
<h1>This is another title</h1>
<p>This is the body copy for the section in which we read more about the aforementioned subject matter within the title.</p>
</div>
<div class="container">
<h1>This is a third title</h1>
<p>This is the body copy for the section in which we read more about the aforementioned subject matter within the title.</p>
</div>
</div>
I am trying to improve my ability to organize content with CSS. It's something I'm really struggling with and I've read a lot of different articles and watched all the videos but it's not clicking just yet. I would like to understand how to do so in a way that incorporates responsive design ideals in addition to not relying on flex box. Flexbox is the next step but I want to master this stage first.
I practiced adding styles to a simple three-card section of content. I was able to get to the point where I have the boxes lined up horizontally. Now there are a couple of issues.
The cards won't align on the same row unless I give a max width, which I'm not sure is best practice for responsive design.
The .container content won't center within the .section class. I've done 'margin: 0 auto;' but it won't affect it.
I've tried adding a relative position property to the .container class as well but that didn't seem to matter.
When I size the viewport to mobile view, the text spills over the bottom of the white container. How do I get the height of the container to adjust to the content within?
Try to use css flex features. Example:
h1, p {
font-family: futura; sans-serif;
margin: 20px 20px 0px 20px;
}
.section {
background-color: tomato;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.container {
width:80%;
background-color: white;
text-align: center;
padding: 5px;
margin: 10px 20px;
}
<div class="section">
<div class="container">
<h1>This is a title</h1>
<p>This is the body copy for the section in which we read more about the aforementioned subject matter within the title.</p>
</div>
<div class="container">
<h1>This is another title</h1>
<p>This is the body copy for the section in which we read more about the aforementioned subject matter within the title.</p>
</div>
<div class="container">
<h1>This is a third title</h1>
<p>This is the body copy for the section in which we read more about the aforementioned subject matter within the title.</p>
</div>
</div>
Your query states that you want to learn style techniques prior to Flexbox, so I dug up an antique prototype that I built in 2011 following this tutorial by Christopher Schmitt http://christopher.org/css-floats-to-display-columns-in-any-order/, and I posted it as a Pen for you to see.
https://codepen.io/cwebba1/pen/agxMzQ
<div><p>Check it out Here</p></div>
I also put it here.
Christopher Schmitt's original tutorial is still up and he has a link to a book that he wrote. You can see from his tutorial that he uses floats, inline-blocks, and percentage widths for layout, and negative margins to control the order of content display on the page. I am in the midst of redesigning my webpage and I still use this pattern.
Also, when I first started learning CSS I found a small inexpensive book, CSS in Easy Steps. It will lead you through the Cascade and styling elements quickly.
As to your projet, I recomend using persentages to set widths, and then changing percentages and adding inline-block to wider media-query layouts.
So I've been looking for days and can't find a way to do that.
I made a WordPress site, and my homepage is displaying the most recent posts I've made.
Thing is, the content of a post is written with some specific layout, and it is meant to stay that way. The layout cannot change! I need the text to stay in the exact same place, even if it becomes way smaller and less readable when looking at the site on a smartphone.
Of course, the site is responsive. Only thing I don't want to be responsive is the content of a post.
I've tried a lot of things, but I can't find a way to make it... This page shows exactly what I'm looking for, except that I don't want the post to be re-sizable by the user. I just need it to fit the parent div.
.responsive-wrapper {
border: 3px solid black;
}
.post-content {
position: relative;
width: 100%;
height: 100%;
padding: 10px;
}
.txt-top-right {
display: block;
float: right;
margin-left: auto;
padding-right: 20px;
}
.txt-under-top-right {
clear: both;
}
.txt-center {
text-align: center;
}
.post-content img {
display: block;
max-width: 200px;
float: right;
padding-right: 20px;
}
<div class="responsive-wrapper">
<div class="post-content">
<p class="txt-top-right"><em>Div right-top corner</em></p>
<p class="txt-under-top-right">
Div following the one on right-top corner
</p>
<div class="txt-center">
<h2>h2 in the middle of the page</h2>
<h1>h1 in the middle of the page</h1>
<h3>h3 in the middle of the page</h3>
</div>
<img src="http://cs.pes.edu/wp-content/uploads/2016/06/default.jpg" />
<p>
paragraph<br> on the left side<br> of the page<br> describing<br> a lot of things<br> on a lot of lines
</p>
<p>
Adress<br> City<br> Country
</p>
</div>
</div>
I understand HTML/CSS/JS, but I am struggling with JavaScript... I can insert some <script> tags in my html header with functions in it, but I have hard times understanding what these functions do.
I'd like the layout to stay the exact same way, doesn't matter which device the user is on. For instance, I want the .txt-top-right paragraph to take this amount of space. On a smartphone, the font size shouldn't re-size and fill up more than this amount of space of the container...
This is an example of what is happening right now when re-sizing the window. The layout changes completely !
Thank you for reading, hope it was clear enough :)
I want to align an text to an exactly position, like 2cm from right not the pre-stabled positions like right, left and center. There's an example: Example
How can I center the Regular, upgraded and exclusive cases like that?
per my comment, here is how the text is centered, but the price tag is included as an inline element with the text.
html
<p class="container">
Text goes here
<span class="block">
$3
</span>
</p>
CSS
.block {
padding: 4px;
background: lightblue;
border-radius: 2px;
margin-left: 4px;
}
.container {
max-width: 400px;
text-align: center;
border: 1px solid;
}
EDIT:
based on the additional information you provided, it's not just aligning text that you were having an issue with, but also layout in general.
I've updated my example to show how you could align elements within a container using text-align: center; and converting the different text/price items to have display: inline-block;.
This is just an entry point to get you started. There are many other ways to layout content with CSS, from floats, flex-box and new CSS Grids. I suggest you review each to determine what is appropriate for your project.
Updated Demo: https://codepen.io/scottohara/pen/oWLxXN
I have four columns in a row, however, when I add content to the columns, each following column is pushed down on the page. I'm unsure how I can go about fixing this.
You can get a better understanding of my problem here, I've increased box size, and reduced it to two boxes, instead of four. http://jsfiddle.net/x5zDj/
<div class="row">
<div class="column">
<h1>Latest News</h1>
<p>Lorem</p>
<p>Lorem</p>
</div>
<div class="column">
<h1>Application</h1>
</div>
</div>
Im sure there's something silly I've overlooked....
When using inline-block, you need to set the vertical-align to your desired property.
In your case, adding it to your .column css as follows corrected the issue:
.column {
width: 460px;
height: 100%;
display: inline-block;
vertical-align: top; /* Adding this causes them to line up evenly across the top */
border: 1px solid #000;
padding: 15px;
}
Fiddle