I try to copy (sort of) single post presentation design from certain website. Here is how it looks like:
(antyweb.pl)
Apparently they use "A" element and the image is its background. I don't like this idea as it requires to put some dummy text that we won't see anyway.
At this point - let me show how I would like to do it:
What I have is an article element employed as container. Inside there are two other elements with max-width for img and width for div set to 61.8033988749854683%.
How to make it so that the div and the image will be displayed right below the header at the same height?
So far I failed as the div was overlapping over the content below while resizing or when it had enough text in it to make it higher than the image.
Thanks in advance, much love
-edit 1-
first fiddle.
-edit 2-
another container added in order to get text where it belongs to: http://jsfiddle.net/MM5hs/5/
What happens now is that the text from first article overlaps another article: http://jsfiddle.net/MM5hs/6/
You can use floats.
FIDDLE
HTML :
<article>
<header>
<h2>Header</h2>
</header>
<div name="topline">
<div class="img_wrap">
<img src="http://cdn.desktopwallpapers4.me/wallpapers/animals/1920x1200/1/3634-kitten-1920x1200-animal-wallpaper.jpg" />
</div>
<div name="content">
<p>... content ...</p>
</div>
</div>
<div class="auth">
<span>Author:
me,
<time datetime="2014-04-04T01:48:23+00:00">2014-04-04T01:48:23+00:00</time>
</span>
</div>
</article>
CSS :
article {
width: 50%;
margin: auto;
}
div[name*="topline"] {
position:relative;
}
div[name*="content"] {
max-width: 61.8033988749854683%;
margin-left: 38.1966011250145317%;
}
.img_wrap {
width:38.1966011250145317%;
float:left;
overflow:visible;
}
article img {
width: 150%;
}
.auth {
clear:both;
}
Related
Adding < a href> to images makes the box around the image larger and forces the text on the right hand side of the image further right. I would like to make the image link to another page while keeping the current format.
I tried adding to the image (alt is connector) (shown below), but it didn't work. (https://www.w3schools.com/html/html_images.asp - Image as a Link
uses around ).
I would expect adding the to the image would simply make the image link to another page, but it changed the size of the box for the image and pushed the text to the right of the image further right.
Page: https://www.flexsweep.com/pages/aboutourproducts (shows layout as it should be - provides access to inspect if needed.)
/*Image and Advantages*/
.content {
display: flex;
align-items: flex-start;
justify-content: flex-start;
}
.content img {
width: 50%;
margin-right: 70px;
}
.details {
width: 50%;
}
<div id="PushBrooms" class="tabcontent">
<p>Intro text.</p>
<div class="content">
<img src="https://cdn.shopify.com/s/files/1/2355/6001/files/BlackConnector.PushBroom.White.Smooth.jpg?765" alt="Connector" />
<div class="details">
<p>
More text.
<div>Shop Push Brooms →</div>
</p>
</div>
</div>
<!-- Attempt to add link to image -->
<img src="https://cdn.shopify.com/s/files/1/2355/6001/files/BlackConnector.PushBroom.White.Smooth.jpg?765" alt="Connector" />
IMG tags behave special as they are a mixture of "block" (have height and width) and "inline" (float around text) elements. Here's some good information about this topic if you want to learn more about it.
Images in <a> tags have an extra bit of padding at the footer which you can get rid of by applying display:block; to the element. Also make sure that there is no extra margin or padding applied by some other rules:
a img {
padding: 0;
margin: 0;
display: block;
}
Here's a demo with some colored backgrounds to show you which element applies padding or margin.
The original image is sized at 50% width from the CSS rule on .content img. This only affects img tags that are descendants of elements with the content class. If you apply content to the link, it will work as you expect.
Edit: Noticed this will not work if you place it inside all inside another content container because the relative width is calculated from the parent, which in the second case will be the a element and not the content div. I updated the snippet to size descendant links of content to be sized at 50% width and the contained images to be 100%.
To address the small amount of padding at the bottom of the link, you can use the solution provided in Sascha's answer
/*Image and Advantages*/
.content {
display: flex;
align-items: flex-start;
justify-content: flex-start;
}
.content img {
width: 50%;
}
.link-wrap {
width: 50%;
}
.link-wrap img {
width: 100%;
}
.details {
width: 50%;
}
<div id="PushBrooms" class="tabcontent">
<p>Intro text.</p>
<div class="content">
<img src="https://cdn.shopify.com/s/files/1/2355/6001/files/BlackConnector.PushBroom.White.Smooth.jpg?765" alt="Connector" />
<div class="details">
<p>
More text. </p>
<div>Shop Push Brooms →</div>
</div>
</div>
<!-- Attempt to add link to image -->
<div class="content">
<a class="link-wrap" href="www.flexsweep.com"><img src="https://cdn.shopify.com/s/files/1/2355/6001/files/BlackConnector.PushBroom.White.Smooth.jpg?765" alt="Connector" /></a>
<div class="details">
<p>
More text.</p>
<div>Shop Push Brooms →</div>
</div>
</div>
Let's say that I have an image that can be a variable width (min:100px, max:100% [760px]). I also have a <p> element that is to be shown right below the image. I'd like the <p> to end up with the same width as the <img>, but I can't seem to find an answer.
Here is the code involved in such a scenario jsfiddle:
html:
<div id='page'>
<figure>
<img src='http://www.myimage.com/img.jpg'/>
<p>Hi there. I am some text. I would like to start where the image starts :(</p>
</figure>
</div>
css:
#page {
width:760px; /* arbitrary */
}
figure img {
display: block;
border: 1px solid #333;
max-width: 100%;
min-width: 100px;
margin: 0 auto;
}
figure p {
/* ??? */
}
Any ideas?
You can use display: table on the figure and set a small width on it. Because it's a table layout it'll then become as wide as the content, in this case the image.
figure {
display: table;
width: 1%;
}
Demo
It is inheriting from #page div. not from the image. Please see the same fiddle updated.
But, You can control individual elements. You have to specify how you wish it to look like.
Here is the FIDDLE that I made using
HTML:
<div id='page'>
<figure>
<img src='http://www.iiacanadanationalconference.com/wp-content/uploads/2013/01/test.jpg'/>
<figcaption>Hi there. I am some text. I would like to start where the image starts :(</figcaption>
</figure>
</div>
CSS:
#page {
width:760px; /* arbitrary */
}
figure{
padding-left: 10%;
}
Actually there are several ways to make an image caption, such as using <table>. I'm not saying that this is the best way to do that. But this is the easiest way since I see you're using <figure> there. I hope this helps you.
Please see this snippet. UPDATE: answer looks like this.
Here I want the #container element to be big enough to contain the #sometimes_shown layer, but it gets its size from the #always_shown child only.
position:absolute removes #sometimes_shown from the flow, and this aspect of the standard gets mentioned when other people have similar problems.
My question is: can I create the same layer effect without using position:absolute, thereby including the size of all child layers in the parent's flow logic?
Precomputed widths/heights/offsets are not an option: this has to flow dynamically. I won't accept any solution which contains a dimensioned number other than zero. CSS-only solutions are strongly preferred, compatibility with old browsers is not a priority, jQuery/javascript solutions are a last resort. Thanks.
You can use floats.
Fiddle (I deleted all your margins for the test)
This solution needs some html markup changes and you will have to use margin-left: -100%; on #sometimes_shown .
How it works :
put both divs in a wrapper with width:50%; and float:left; so both elements are on the same line.
get the elements with back to normal width adding width:200%; to #always_shown and #sometimes_shown
Add margin-left: -100%; to #sometimes_shown so it stacks to the left of container
add a dummy div with clear:both; at the bottom of the container so it wraps around the floated elements
Here is the code:
HTML :
<div id="container">
<div class="wrap">
<div id="always_shown">
<p>I am always here 1. I am always here 2. I am always here 3. I am always here 4. I am always here 5. I am always here 6. I am always here 7.</p>
</div>
</div>
<div class="wrap">
<div id="sometimes_shown">
<p>I am sometimes here</p>
<p>Extra 1</p>
<p>Extra 2</p>
<p>Extra 3</p>
<p>Extra 4</p>
</div>
</div>
<div class="clr"></div>
</div>
CSS :
#container
{
border: thin solid black;
}
#always_shown
{
width: 200%;
color: red;
}
#sometimes_shown
{
width: 200%;
margin-left: -100%;
color: green;
}
.wrap{
float:left;
width:50%;
}
.clr{
clear:both;
}
I am working with someone else's styling, and can't get things as they managed to. I am trying to make things look like this page:
http://www.comehike.com/outdoors/parks/add_trailhead.php
See how the image is nicely on the right, and the form elements are on the left.
I have this page that I am messing with and trying to make similar:
http://www.comehike.com/account/member_home.php
Is there an easy way for me to make the image go to the far left, and the stuff asking the person to log in, to be on the right?
Thanks!
Start with changing the width on the first div within .basic. Change the width to 100% instead of 450px
You should be able to continue from there.
I would also move the image into it's own container and float that right, and put the form actions in another container. Also, make use of classes and ids for styling to clean things up.
Here is how you can make food use of floating elements:
HTML:
<div class="container">
<div class="form">
<form>....</form>
</div>
<div class="leftImage">
<img src="img.jpg" />
</div>
<div class="clear"></div>
</div>
CSS:
.container {
width: 800px;
}
.container .form {
width: 500px;
float:left;
}
.container .leftImage {
width: 250px;
float:left;
}
.clear {
clear:both;
}
Replace the div with width: 450px to width: 100% then the child H3 float: left
increase the width to 845px for the div.
Float image to the left.
for the h3 tag do the styling
h3 {
float: right;
display: inline;
}
This will do the task for you.
Remove the empty tags from the HTML.
I styled an image with float:left, and predictably, the text of the header after it appears to the right of the image (if it helps, the context for this situation is a logo and title next to each other in the header of a website).
When I look at the header element (h1), it takes up space behind the image (overlapping). The text is still next to the image, but the background of the h1 element overlaps with the image.
<div id="header">
<img src="logo2.png" />
<h1>AlanHoRizon</h1>
<p>
...
#header img {
float: left;
}
Is this how floating is supposed to work? Is background synonymous to the padding in the css box model? What if I wanted the header element to begin completely after the image, including the background (which is what I expected float to do actually).
Doesn't actually affect the appearance of the header, as everything appears as it should, but I'm curious, as it would add to my understanding of html and css web design.
thanks.
HTML:
<div id="header">
<img id="logo" src="http://lorempixum.com/100/100/abstract" alt="" />
<div>
<h1>AlanHoRizon</h1>
<h3>Site description</h3>
</div>
</div>
<div id="content">
<p>Lorem ipsum dolor ...</p>
</div>
CSS:
#header:after {
display: block;
clear: both;
content: ".";
visibility: hidden;
height: 0;
line-height: 0;
}
#logo {
float: left;
}
#header div {
float: left;
padding: .25em;
}
And here's the complete jsfiddle example
modify the css code to:
h1
{
float:left;
}
img
{
float:left;
}
This should work. The following will produce the heading on the left of the image.
Actually, I think I found an answer to my question. Simply put, it seems like this is just how floating behavior works. The content is pushed over, but the background and borders still go behind the float:
http://phrogz.net/CSS/understandingfloats.html#ascolumns
I'm not sure if padding is synonymous to background, but I did test the header elements "padding" simply by making the background color red, and the background indeed is behind the float. In terms of the css box model, I'm still not quite sure what's going on.