I have been trying to create a specific layout for some images. Layout I would like to create.
I have tried floating the smaller images so that they stand alongside the large image, this works if I add a clearfix but then for some reason the width I apply to the images is no longer effective. So it's either large images in the right positioning or small images all over the place.
I tried putting all images into separate div tags and then a parent div, then floating but that has it's own issues.
Can this be done in HTML & CSS or do I need to be going down the jQuery route?
I will be tidying the code up, I'm just trying to get it right in my head atm.
HTML:
<section id="galleryposition">
<ul id="gallery">
<div id="mainimage">
<li>
<a href="img/8.jpg">
<img src="img/8.jpg" alt=""></a>
</li>
</div>
<div id="smallphotos">
<div id="smalllefttop">
<li>
<a href="img/2.jpg">
<img src="img/2.jpg" alt="">
</a>
</li>
</div>
<div id="smallrighttop">
<li>
<a href="img/3.jpg">
<img src="img/3.jpg" alt="">
</a>
</li>
</div>
<div id="smallleftbottom">
<li>
<a href="img/4.jpg">
<img src="img/4.jpg" alt="">
</a>
</li>
</div>
<div id="smallrightbottom">
<li>
<a href="img/5.jpg">
<img src="img/5.jpg" alt="">
</a>
</li>
</div>
</div>
</ul>
</section>
CSS:
#gallery {
margin: 50px 0 0 0;
padding: 0;
list-style: none;
}
#galleryposition {
text-align: center;
}
#gallery img {
border-radius: 2.5%;
}
#gallery li {
float: left;
margin: .5%;
color: #bdc3c7;
}
#gallery li a p {
margin: 0;
padding: 5%;
font-size: 0.75em;
color: #bdc3c7;
}
#smalllefttop group {
max-width:50%;
float:left;
}
#smallrighttop group{
max-width: 50%;
float:right;
}
#smallleftbottom group{
min-width:50%;
float:left;
}
#smallrightbottom group{
min-width:50%;
float:right;
}
https://jsfiddle.net/apdeng/wyvzmm9q/1/
Thanks in advance.
Ok, so I started to play around with your code, but I was basically just re-starting it for you, which isn't what SO is for, so here are some things you need to consider:
<ul> tags are intended for lists. This definition is often stretched by developers who use them to create a "list" of links used for navigation, but in this case your image layout is complicated by the use of the <ul> and <li> structure. You'd be better served by simple <div> tags, which a) don't require both the <ul> and <li> tags and b) make more sense semantically since this is not, in fact, a list.
It's bad practice to put a <div> inside a <ul> like your #mainimage div.
The selector group in your css isn't actually doing anything. I googled this because I've never seen it before and couldn't come up with what purpose that keyword would serve. The elements followed by "group" aren't getting the styles you're trying to apply to them. I would remove that from your css.
You'll have more success with just plain old width in your css (not max-width)
Never use <br> tags to create space in a layout. Use margins and padding instead.
Make sure all your tags are closed and opened. When JSfiddle highlights the text red, that means you're missing part of a tag. (In your case, you have one too many </a> tags in each group.)
What you basically need to do is clean up your markup as much as you can and make that big image roughly 50% width and each of the other images roughly 25%. I say roughly because when you go to add margin between all of them, your total width will still need to add up to 100% (any more than that and some of your elements will bump down to the next line). That's probably what went wrong when you tried adding width to your images. Look at selectors for nth-child or last-child to help you remove the margin on the blocks on the side.
Let me know if you have more questions!
Related
Browser testing my development site i'm having an issue, mainly on Firefox version 24. I have set the li elements inside a full width section of 100%, Inside I have 5 floated li with anchor elements set at 20% width. These all sit in place across majority of all browsers, except Firefox 24 which makes the last element drop down onto the next line. I can fix this by reducing the width, but then it obviously does not fill the wrapper width as intended. I have an additional class of .tablet-half, which moves the last two elements to take up 50% each of the wrapper at smaller sizes. I don't know if this is somehow affecting it? The section HTML is;
<section class="header-cta wrapper">
<ul>
<li>
<a href="/security-systems/" class="cta-box btn--info">
<img src="http://dev5.bmpreview.co.uk/wp-content/themes/matrix/images/parking.svg" alt="parking icon">
<p class="cta-box__headline">Parking Barriers</p>
</a>
</li>
<li>
<a href="/access-control/" class="cta-box btn--trader">
<img src="http://dev5.bmpreview.co.uk/wp-content/themes/matrix/images/anpr.svg" alt="anpr icon">
<p class="cta-box__headline">ANPR</p>
</a>
</li>
<li>
<a href="/security-fencing/" class="cta-box btn--info tablet-half">
<img src="http://dev5.bmpreview.co.uk/wp-content/themes/matrix/images/security-fencing.svg" alt="security fencing icon">
<p class="cta-box__headline">Security Fencing</p>
</a>
</li>
<li>
<a href="/cctv-systems/" class="cta-box btn--trader-dark tablet-half">
<img src="http://dev5.bmpreview.co.uk/wp-content/themes/matrix/images/cctv.svg" alt="cctv icon">
<p class="cta-box__headline">CCTV Solutions</p>
</a>
</li>
</ul></section>
Basic styles; (i'm using box-sizing, and there is no margin/padding on the ul,li)
.wrapper {
width: 100%;
float: left;
}
.header-cta .cta-box {
width: 20%;
padding-right: 0.5rem;
padding-left: 0.5rem;
}
.tablet-half {
width: 50%;
}
I have taken an image on my phone of how it looks in Firefox 24
This is the test site url where I am working, if that helps.
So I have the following structure:
<div id="bannerLogin" class="topBannerAnon">
<a href="http://www.redacted.fr/" class="logo" target="_blank">
<img src="redacted" style="border:none;">
</a>
</div>
With no CSS, the containing div extends to the image height, which is on the left side of the div.
Now I want to put that image on the right of the div instead of the natural left. If I use float: right; on the .logo class, the <a> element is taken out of the flow so my containing div won't extend to the picture height anymore (it will have a height=0).
I tried to wrap the <a> element into another div and give the logo class to it (in case it needs to be a block element), but same behaviour.
So I'm realizing I have no idea how to attach an element on the right of its container, with the container still taking into account the dimensions of said element. Is it possible?
You're doing fine, you just need a clearing element before you close your container in order to make the floated elements "occupy" the parent's space. Something like this should work:
<div id="bannerLogin" class="topBannerAnon">
<a href="http://www.redacted.fr/" class="logo" target="_blank">
<img src="redacted" style="border:none;">
</a>
<div class="clear"></div>
</div>
CSS
.clear {clear: both;}
In case of images, you can use the traditional html align="right" tag to put the image on right side of the content and keep the other aspects of styling the same.
The align="right" tag goes in the IMG html element.
Given this CSS:
.logo {
float: right;
}
… you can get the div to grow by adding this CSS:
#bannerLogin {
overflow: hidden;
}
That's due to the fact that an overflow with a value different from visible creates a new block formatting context.
Snippet
#bannerLogin {
background: #fed;
border: 1px solid black;
overflow: hidden;
}
.logo {
float: right;
}
<div id="bannerLogin" class="topBannerAnon">
<a href="http://www.redacted.fr/" class="logo" target="_blank">
<img src="http://placehold.it/100x100" style="border:none;">
</a>
</div>
Hey I have a problem with social buttons. I am trying to move them but only one show up on my page and I can't move that. I have three buttons and them images can someone help I am trying to put them straight line center of header or above my video.And I want to put them links.
HTML
<body>
<div id="header">
<div id="icons>
<img src="facebook-64.png">
<img src="twitter-64.png">
<img src="instagram-64.png">
</div>
<img src="logo2.png">
<div id="nav">
<div id="nav_wrapper">
CSS
img {
position: absolute;
right: 640px;
top: -50px;
}
video {
margin-top: 250px;
}
#icons {
top: -220px;
}
If using absolute positioning. Each button needs a different class. It is best practice to use classes for css styling and keep id for targeting elements with JavaScript. The images need to be wrapped in links ( tags) and the # in the href below should be set to the URL of your facebook, twitter and instagram home pages.
Personally I would set out html as:
<body>
<div class="header">
<div class="icons>
<a class="fb-link" href"#">
<img src="facebook-64.png">
</a>
<a class="twr-link" href"#">
<img src="twitter-64.png">
</a>
<a class="inst-link" href"#">
<img src="instagram-64.png">
</a>
</div>
<img src="logo2.png">
<div id="nav">
<div id="nav_wrapper">
Rather than use absolute positioning I would simply display the links as blocks and float them left. Use a margin on the containing div to position your icons. See below.
css
.icons{
margin:20px auto; //gives margin of 20px top and bottom and centers buttons horizontally.
width:220px;
}
.fb-link, .twr-link, .inst-link {
display:block;
float:left;
width:60px; //set width to the with of image used eg 64px
margin-left:20px;
}
.fb-link{
margin-left:0; //if margin left was left at 20px the icons would be 20px off center.
}
Using these principles laying out the rest of you pages should be straight forward.
You're giving the same style to all img tags, causing them to overlap! try changing positions for each
The current website has 3 column block layout and I am trying to make it responsive. As the window gets small enough, the 3 columns turn into 2 columns, which is what I wanted. However, it leaves white space where the third column was used to be and I don't want the extra white space. So the white space should be hidden as the window gets smaller (this is what happens when the window is large enough for 3 columns. The white space on the right side gets hidden, until the 3 columns turns into 2).
Thank you. :)
JSFiddle
html:
<body>
<div id="content">
<div class="grid3">
<article class="bucket" >
<a href="#">
<img src="images/baskerville1.jpg" alt=""/>
<div class = "img-overlay">
<h3>Monogram</h3></div>
</a>
</article>
<article class="bucket">
<a href="#">
<img src="images/Gastalt.png" alt=""/>
<div class="img-overlay">
<h3>Gastalt Composition</h3>
</div>
</a>
</article>
<article class="bucket">
<a href="#">
<img src="images/redThread.png" alt=""/>
<div class="img-overlay">
<h3>The Red Thread - A Visual Book</h3>
</div>
</a>
</article>
<article class="bucket">
<a href="#">
<img src="images/poster copy.png" alt=""/>
<div class="img-overlay">
<h3>Typographic Hierarchy</h3>
</div>
</a>
</article>
<article class="bucket">
<a href="#">
<img src="images/Spaces.png" alt=""/>
<div class="img-overlay">
<h3>Living in Two Spaces</h3>
</div>
</a>
</article>
css:
#charset "UTF-8";
*{
margin:0;
}
.bucket {
position:relative;
float: left;
margin-left: 3.2%;
margin-bottom:30px;
}
.grid3 .bucket:nth-of-type(3n+1){
margin-left: 0;
clear: left;
}
.grid3 .bucket{
width: 31.2%;
}
.img-overlay h3 {
opacity: 1;
display: inline-block;
margin: auto;
height: 20px;
position: absolute;
top: 0;
bottom: 0;
right: 0;
left:0;
color: rgba(255,254,254,1.00);
text-align: center;
vertical-align: middle;
}
Controlling exact numbers in responsive layout (3col, 2col, etc.) should be done via percentages because it's heaps easier to control when and where breakpoints happen.
Here's a JSFiddle showcasing this: http://jsfiddle.net/sickdesigner/GLnfU/
Essentially, the key to the whole thing is having your .buckets set to percentages according to how many columns you want. This makes your article fill up their container in three columns (27.3+3+3 = 33.3*3 = 99.9%).
.bucket{
margin: 2% 3%;
width: 27.3%; }
Also, for sanity's sake, I added a universal box-sizing. More on why box-sizing makes life easier here: http://www.paulirish.com/2012/box-sizing-border-box-ftw/
However,
If you really want to let your content do what it want, when it feels like it, you could skip the whole matter of floating elements altogether. This is the more hippie-lovey-dovey version of this layout and while it looks sleek and sexy and makes coders, myself included, drool with code-lust, it also means leaving a lot to chance and the hope that your content won't break itself (think what would happen if the images were all different proportions to each other).
Here's another JSFiddle, this time with the hippie-drooly approach: http://jsfiddle.net/sickdesigner/zq8YC/1/
P.S.: the hippie-drooly approach also doesn't require media queries, which is kind of cool, actually.
Cheers!
This question already has answers here:
How can I wrap text around a non rectangular image?
(5 answers)
Closed 3 years ago.
I am trying to get an image of mine to float in the center of a div. Code currently:
<style type="text/css">
#navig {
height: 333px;
}
#navig img {
display: block;
margin: 0px auto;
}
</style>
<div id="navig"><img src="images/logo.png" height="333" id="logo" /></div>
The trouble is the image is a diamond and I would like the text to wrap around the diamond with the indents. I believe this is a possibility with <img align='center' /> but this was deprecated in HTML 4.01 and not even supported in HTML 5.
I have tried several possibilities and I still cannot get the text to wrap correctly around the diamond.
Refer to this for some options. I have two options, CSS-Shapes and SVG.
The best option current is to use an SVG image but make sure to use the SVG code and not linking it as an image.
Here is a JSFIDDLE, as you can see the text is able to highlight and can be edited. (More of a pain to edit so do your best with the text in AI before saving but it can still be edited)
This is also very flexible as you can see in this FIDDLE.
This is a very new feature and does not have good browser support yet.
SO CSS-Shapes
Once this,
shape-outside: polygon(50px 0px, 100px 100px, 0px 100px);
is supported you will be able to do this with ease.
I recommend learning the basics so once it is supported by most current browsers you will already know what to do.
I managed to figure out a manual way around this. The image remains in the div and is surrounded by two other closed divs tags.
<div id="navig">
<div id="nav1"></div>
<div id="nav2"><img src="images/logo.png" height="333" id="logo" /></div>
<div id="nav3"></div>
</div>
I then make sure all three of these float left: #navig div {float:left;} and the two empty divs are using text-align. The first one will align right and the last one align left.
The two empty divs are then filled with <ul>s and the menu I wanted around it is filled into the <li> tags. For the examples I'll use some basic menu items.
<div id="navig">
<div id="nav1">
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
<div id="nav2">
<img src="images/logo.png" height="333" />
</div>
<div id="nav3">
<ul>
<li>Products</li>
<li>Shipping</li>
<li>Legal</li>
</ul>
</div>
</div>
I then added #nav1 ul li:nth-child(1) and positioned the first element, which would be "Home" against the diamond. I can change "Home" to whatever I fancy and the position remains as it is forced to text-align: right. Adding these with however many <li> items you are using and editing them to suit your needs. For example:
#nav1 ul li:nth-child(1) {
position: relative;
left: 48px;
}
#nav1 ul li:nth-child(2) {
position: relative;
left: 24px;
}
#nav1 ul li:nth-child(3) {
position: relative;
left: 8px;
}
This pushed my first, second and third items over to the diamond but with a little padding so as to not intrude.
A bit of a lengthy process, but plenty of freedom and has given me the desired effect!
You can't do it with just an image.
But you can use shapes, check this page:
https://www.makeuseof.com/tag/csstextwrap/
Using CSSTextWrapper you can easily generate HTML text wraps for any
imaginable shape. It can be circles, zig-zags, triangles or whatever
you want. Quick and simple-to-use, just load the logo (optional) on
the provided dashboard and drag sidelines to define your text wrap.
Quite impressive.